Upon Contact record creation if LeadSource Field is having value as ‘Web’ or ‘Phone Inquiry’ then Populate Level as ‘Primary’

521 views


Hey guys, today in this post we are going to learn about How to write a apex trigger on Contact, whenever Contact record created and if LeadSource Field is having value as ‘Web’ or ‘Phone Inquiry’ then Populate Level as ‘Primary’ automatically.

 

Final Output →

contact-record-creation-populate-level-as-primary -- w3web.net
 

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]

  1.   TRIGGER ContactTrigger ON Contact (BEFORE INSERT) {
  2.  
  3.     ContactTriggerHandler.lavelPopulate(TRIGGER.new);
  4.  
  5. }

 

Create Apex Class Controller

Step 2:- Create TriggerHandler Class : ContactTriggerHandler.apxc

From Developer Console >> File >> New >> Apex Class

ContactTriggerHandler.apxc [Apex Class Controller]

  1.   public class ContactTriggerHandler {
  2.  
  3.     public static void lavelPopulate(List<Contact> contactList){
  4.         FOR(Contact con:contactList){
  5.             IF(con.LeadSource == 'Web' || con.LeadSource == 'Phone Inquiry'){
  6.                 con.Level__c='Primary';
  7.             }
  8.         }
  9.  
  10.     }
  11.  
  12. }

 

Lead Source Field

contact-record-creation-populate-level-as-primary -- w3web.net

 

Lavel Field

contact-record-creation-populate-level-as-primary -- w3web.net
 

Further post that would you like to learn in Salesforce

 

FAQ (Frequently Asked Questions)

What are the two options for when apex triggers can run?

There are two types of Apex triggers in Salesforce: Before Triggers and After Triggers. Before Triggers execute before the record is saved to the database, while After Triggers execute after the record has been saved.

Can apex trigger make a callout?

Even though there's the restriction of not allowing API callouts from triggers, there's a workaround to make it happen. You can use Asynchronous Apex to make callouts.

What is the limit of apex triggers in Salesforce?

Your Apex triggers (combined) must not exceed 200 SOQL queries per batch. If they do, your Clean job for that object fails. In addition, if your triggers call future methods, they're subject to a limit of 10 future calls per batch.

Related Topics | You May Also Like

Our Free Courses →

👉 Download App to Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Download App to Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration

 
 
🌩️ Download App to Get Free Course Access: -

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net