Create Roll-Up Summary field to count Contacts on Account with Process Builder and Flows
- 12月
- 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
近期文章
- 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的开发者用户突破10,000名!THANK YOU!
- Lightning Component中使用Promise处理Apex服务端请求
Top Posts
- Salesforce DevTools – Saleforce开发者必备Chrome扩展 - 222.8K views
- Date format 与 DateTime format - 206.9K views
- Salesforce批量编辑 (Chrome扩展) – 在任何标准视图上进行批量插入, 拷贝, 更新, 删除, 支持Classic与Lightning! - 159.6K views
- 用Sublime Text 3架设Salesforce的快速开发环境 - 122.7K views
- 编写一个可被计划执行的Batch Apex - 121.7K views
分类目录
- APEX
- 应用
- Custom Label
- Custom Metadata
- Custom Setting
- Design & UI
- 交流会
- 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
您必须登录才能发表评论。