Ensuring data consistency across industry-specific records is crucial in Salesforce—especially when different industries require different field values, lead sources, or qualification criteria. In this blog, we focus on automating field updates for Leads in the Healthcare industry using a simple yet powerful before update Apex trigger.
This trigger detects when a Lead is being updated and automatically sets default values for fields like Lead Source, SIC Code, and Primary if the Lead falls under the Healthcare industry. Additionally, it sets the Status field to “Working-Contacted” for all updates, ensuring a consistent lead management flow.
The logic executes in the before update context, modifying the records in-memory before they are committed to the database—an efficient way to enforce uniformity across incoming data.
🧠 Why This Trigger Is Important
When working with leads across different industries, field values can vary greatly. But without controls in place:
-
Users may enter inconsistent values manually
-
Field defaults might not reflect the industry context
-
Leads could be routed incorrectly due to missing or incorrect metadata
-
Downstream automations may fail or behave unpredictably
By enforcing specific field values for Healthcare Leads during updates:
-
You reduce the chances of human error
-
You ensure leads are enriched and qualified properly
-
You streamline the workflow for teams responsible for follow-up
-
You create a clean dataset for reporting, segmentation, and marketing
It’s a lightweight automation with a significant impact on data hygiene and process efficiency.
🔍 What This Blog Covers
-
How to write a before update trigger on the Lead object
-
How to detect specific industry values and apply conditional updates
-
How to set values like
LeadSource
,SICCode__c
, andPrimary__c
-
Why in-memory updates in
before
triggers are efficient and scalable -
How this type of automation contributes to better data standardization
This trigger offers a straightforward way to implement industry-specific business logic directly within your CRM workflow.
🎯 Real-World Use Cases for This Trigger
-
Healthcare sales teams that work with strict qualification criteria
-
B2B marketers segmenting leads based on SIC code or lead source
-
Customer onboarding teams needing specific field values for routing
-
Lead scoring engines that depend on consistent primary values
-
Data quality assurance processes to standardize industry-specific entries
This pattern can be extended to other industries as well—just modify the logic for each industry type and its required field values.
👨💻 Developer & Admin Tips
Let’s break down how the trigger works:
-
The trigger runs in the before update phase, which allows it to modify the record in memory.
-
It loops through each incoming Lead in
Trigger.new
. -
It sets the Status to “Working-Contacted” by default.
-
If the Industry is “Healthcare”, it:
-
Sets the Lead Source to “Purchased List”
-
Assigns SIC Code as “1100”
-
Marks the Primary field as “Yes”
-
Key reasons this works well:
-
No DML operations are required—since it’s a
before
trigger -
It’s bulk-safe and handles multiple records in a single transaction
-
No need for queries or recursive flags—making it simple and clean
Ways to expand this:
-
Add logic for other industries (e.g., “Finance”, “Education”)
-
Check if values already match to avoid unnecessary overwrites
-
Introduce a custom setting or metadata-driven mapping for different industries
-
Trigger notifications if fields are force-updated due to logic enforcement
Make sure to test:
-
Updating a Healthcare Lead and verifying all values are set correctly
-
Updating Leads in other industries to ensure their values remain unchanged
-
Batch updates with mixed industry values
-
Records that are already in the correct state to avoid redundant updates
This type of automation ensures consistent CRM behavior even when users update records manually, through imports, or via integrations.
🎥 Watch the Implementation – YouTube Playlist
If you prefer a hands-on approach, check out the Salesforce Makes Sense YouTube playlist where this trigger is explained line by line. You’ll learn:
-
How to set up and deploy the trigger
-
Tips for using
before update
context effectively -
Debugging common issues
-
Best practices to keep triggers clean and modular
Solution:
trigger LeadTrigger on Lead (before update) {
if(Trigger.isBefore && Trigger.isUpdate) {
for (Lead leadRec : Trigger.NEW) {
leadRec.Status=’Working-Contacted’;
if (leadRec.Industry == ‘Healthcare’) {
leadRec.LeadSource = ‘Purchased List’;
leadRec.SICCode__c = ‘1100’;
leadRec. Primary__c = ‘Yes’;
}
}
}
}