Create Roll-Up Summary field to count Contacts on Account with Process Builder and Flows
- Dec
- 09
- Posted by Lin
- Posted in Other, Salesforce, Visualforce
As we know,roll-up summary field is used to display a value in a master record based on the values of fields in a detail record. The detail record must be related to the master through a master-detail relationship.
Unfortunately Account and Contact objects only have a lookup relationship so we cannot create roll-up summary field on Account such as to count the number of contacts related to that account.
Writing a Trigger for Contact object is a general solution in this case,but there also have a no coding way to solve this problem, with Process Builder and Flows.
Here is the list of setting we have to create:
・ContactSummaryFlow (Flows)
・ContactSummaryProcess (Process Builder)
・ContactDeleteFlow (Flows)
・ContactDeletePage (VF Page)
※wow,doesn’t that look more complicated than a Trigger? well,maybe the other guys don’t think so, especially the clients. ; )
Then we should create a delete flow and a flow page next for fixing this issue.
Add a Record Delete element “DeleteContact” and a variable “varTargetId”. Add flow “ContactSummaryFlow” at the end. Save and active it.
At the next post I will share you the other interesting usages of Process and Visual Flows.
Enjoy it!
Unfortunately Account and Contact objects only have a lookup relationship so we cannot create roll-up summary field on Account such as to count the number of contacts related to that account.
Writing a Trigger for Contact object is a general solution in this case,but there also have a no coding way to solve this problem, with Process Builder and Flows.
Here is the list of setting we have to create:
・ContactSummaryFlow (Flows)
・ContactSummaryProcess (Process Builder)
・ContactDeleteFlow (Flows)
・ContactDeletePage (VF Page)
※wow,doesn’t that look more complicated than a Trigger? well,maybe the other guys don’t think so, especially the clients. ; )
New custom field
Create a custom field(Number(18, 0)) on Account named “NumberofContacts”.ContactSummaryFlow
Create a Visual Workflow from Create > Workflow & Approvals > Flows. Add a Decision element(Drag & Drop) named “ValidateAccountId”. Create a variable named “varAccountId”. Add a Fast Loopup element named “SearchContacts” to flow area. Create a SObject Collection Variable named “contacts” for storing search results. Now the Fast Loopup “SearchContacts” should look like the following image. Then add a Loop element named “LoopContacts”. Add a Assignment element for the Loop element “LoopContacts”. Add a Record Update element at the end. Now,set the Decision element to be a Start Element and link the elements with mouse like the following image. Save flow as “ContactSummaryFlow” and activate it.ContactSummaryProcess
Create a process named “ContactSummaryProcess” from Create > Workflow & Approvals > Process Builder. Add Contact object and save it. Add a criteria and save it. Add a action for the criteria when it is true,and select the flow “ContactSummaryFlow”. Now activate the process. So far we have completed setting for counting number of contacts when contact is created or updated, but the process cannot be started when object is deleted.Then we should create a delete flow and a flow page next for fixing this issue.
ContactDeleteFlow
Create another Visual Workflow named “ContactDeleteFlow”.Add a Record Delete element “DeleteContact” and a variable “varTargetId”. Add flow “ContactSummaryFlow” at the end. Save and active it.
ContactDeletePage
Create a Visualforce Page named “ContactDeletePage” with the following source code.Replace Contact delete action
Replace the standard delete action of Contact with vf page “ContactDeletePage”, from Customize > Contacts > Buttons, Links, and Actions.Operation check
Create a contact
Delete contact
It looks like working well!At the next post I will share you the other interesting usages of Process and Visual Flows.
Enjoy it!
Post Tagged with Account, Contact, no coding, Process, Process Builder, Roll-Up Summary, Salesforce, Visual Flow
Recent Posts
- Salesforce DevTools Release Notes (version 3.10.0) – mass edit custom fields on lightning
- Salesforce DevTools Release Notes (version 3.9.0) – Object Fields, SOQL Query Editor
- Salesforce DevTools Release Notes (version 3.8.0)
- Salesforce DevTools JUST HIT 10,000 USERS! THANK YOU!
- Using Promise for Apex Server-Side request in Lightning Component
Top Posts
- Salesforce DevTools – Powerful Salesforce developer tools, loved by over 50K developers - 222.8K views
- Date format and DateTime format - 206.9K views
- Salesforce Mass Editor (Chrome Extension) – Mass create, mass update, mass clone, mass delete on any list view. Support for both Classic and Lightning! - 159.6K views
- Setup an awesome Salesforce developer environment with Sublime Text 3 - 122.7K views
- Writing a Schedulable Batch Apex in Salesforce - 121.7K views
Categories
- APEX
- Apps
- Custom Label
- Custom Metadata
- Custom Setting
- Design & UI
- Event
- Heroku
- iOS & Object-c
- Lightnint Component
- Linux & Mac OS
- Metadata API
- Node.js
- Open Source
- Other
- PHP Framework
- Release Notes
- REST API
- Salesforce
- Salesforce DevTools
- Salesforce DX
- SOQL
- Tooling API
- Unit Tests
- Validation Rule
- Visualforce
- WordPress
You must be logged in to post a comment.