You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Salesforce中创建工作流统计Contact记录保存点击次数?

Got it, let's walk through how to set up a workflow that increments the "Number Of Updates" field on a Salesforce Contact every time the record is saved. I'll cover both a code-based approach and a no-code option so you can pick what works best for your team.

Method 1: Apex Trigger (Code-Based)

First, make sure you've created a Number field on the Contact object (let's assume its API name is NumberOfUpdates__c—replace this with your actual field name if it's different). Then create a before update trigger that runs right before the record is saved, which lets us update the counter field without triggering an extra save cycle.

Here's the trigger code:

trigger ContactUpdateCounter on Contact (before update) {
    for(Contact contactRecord : Trigger.New) {
        // Handle null values for the first update
        if(contactRecord.NumberOfUpdates__c == null) {
            contactRecord.NumberOfUpdates__c = 1;
        } else {
            contactRecord.NumberOfUpdates__c += 1;
        }
    }
}

Key Notes:

  • The before update context ensures the counter is updated in the same database transaction as the original save, so no extra API calls or record locks are needed.
  • Always handle null values—if the field was never set before, we start at 1 instead of hitting a null pointer error.
  • This works seamlessly for both single-record edits and bulk updates (like list view edits or Data Loader operations).

Method 2: Record-Triggered Flow (No-Code)

If you prefer not to write Apex, Salesforce Flow Builder can handle this just as effectively. Here's a step-by-step setup:

  1. Go to Setup > Flows and click New Flow. Select Record-Triggered Flow and click Create.
  2. Configure the trigger settings:
    • Object: Contact
    • Trigger Event: A record is updated
    • Entry Conditions: (Optional) If you only want to count updates that modify specific fields, set conditions here. Otherwise, leave it as "All records" to count every save.
    • Optimize the flow for: Fast Field Updates (since we're only updating a single field)
  3. Add an Update Records element to your flow:
    • Choose "Select the records that meet specific conditions"
    • Object: Contact
    • Condition: Record ID equals {!$Record.Id} (this targets the exact record being updated)
    • Under "Set Field Values for the Records", find your "Number Of Updates" field. Set its value to this formula:
      IF(ISBLANK($Record.NumberOfUpdates__c), 1, $Record.NumberOfUpdates__c + 1)
      
  4. Save your flow with a clear name (like "Contact Update Counter Flow") and click Activate.

Key Notes:

  • The formula handles null values, so the first save will set the counter to 1 instead of leaving it blank.
  • To avoid accidental loopbacks (the flow triggering itself when it updates the counter field), adjust the entry conditions to exclude updates where only the "Number Of Updates" field changed. Just add a condition like {!$Record.NumberOfUpdates__c} != {!$Record_Old.NumberOfUpdates__c} and uncheck that condition in the entry criteria.

Testing Your Implementation

Whichever method you choose, test it thoroughly to ensure it works as expected:

  1. Create a new Contact record (the counter field should be blank initially).
  2. Edit the record and click Save—the counter should jump to 1.
  3. Edit it again and save—now it should be 2, and so on.
  4. Try a bulk update (e.g., edit multiple Contacts from a list view) to confirm all counters increment correctly.

内容的提问来源于stack exchange,提问作者liraz yakobovich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:30:59