Hey guys, today in this post we are going to learn about Apex Trigger Scenarios is Upon Contact record creation if LeadSource Field is having value as ‘Web’ or ‘Phone Inquiry’ then Populate Level as ‘Primary’ through Apex Trigger in Salesforce.
Final Output →
Other related post that would you like to learn in Salesforce
Create Apex Trigger →
Step 1:- Create Apex Controller : ContactTrigger.apxt
SFDX:Create Apex Trigger>> New >> ContactTrigger.apxt
ContactTrigger.apxt [Apex Trigger]
|
TRIGGER ContactTrigger ON Contact (BEFORE INSERT) {
ContactTriggerHandler.lavelPopulate(TRIGGER.new);
}
Create Trigger Handler Controller →
Step 2:- Create Apex Controller : ContactTriggerHandler.apxc
SFDX:Create Apex Trigger>> New >> ContactTriggerHandler.apxc
ContactTriggerHandler.apxc [Trigger Handler]
|
public class ContactTriggerHandler {
public static void lavelPopulate(List<Contact> contactList){
FOR(Contact con:contactList){
IF(con.LeadSource == 'Web' || con.LeadSource == 'Phone Inquiry'){
con.Level__c='Primary';
}
}
}
}
Further post that would you like to learn in Salesforce
How would you write a trigger to count the number of tasks associated with an account?
You can write an 'after insert', 'after update', and 'after delete' Trigger on the Task object. Within this Trigger, count the number of Tasks related to each Account.
What is the difference between before and after trigger in Salesforce?
Before Triggers are ideal for making changes to the triggering record, while After Triggers are suitable for working with related records and system-generated field values. Understanding this distinction is key to designing effective and efficient trigger logic in Salesforce.
How many triggers we can write on the same object with same trigger event?
Use only one trigger per object principle. Minimize the use of SOQL query and DML operations. Avoid trigger recursion via a static variable when performing an update on the same object from the trigger.
Related Topics | You May Also Like
Our Free Courses →
👉 Get Free Course →
📌 Salesforce Administrators 📌 Salesforce Lightning Flow Builder 📌 Salesforce Record Trigger Flow Builder |
👉 Get Free Course →
📌 Aura Lightning Framework 📌 Lightning Web Component (LWC) 📌 Rest APIs Integration |