Skip to content
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24globalworld |
  • News24classictimes |
  • Incriediableindia |
  • TechW3web |
  • W3Force ..
w3web.net
the vijay kumar Sign Up to Get Free Code Access β†’ |
  • Home
  • Tutorial
    • Lightning Component
    • Salesforce LWC
    • Salesforce Integration
    • Visualforce
    • Trigger
    • JQuery
  • Our Courses
  • Integration
  • Aura Comp
  • Salesforce LWC
  • Visualforce
  • Trigger
  • JQuery
  • React Js
  • More
    • About Us
    • Contact Us
    • Sitemap
    • Course Pricing
    • Blog
    • Gallery
    • Most Popular Articles
    • Download E-Book
    • YouTube Channel


When an Account record is created then Create a related Contact automatically through Apex Trigger in Salesforce

January 14, 2025February 29, 2024 by Vijay Kumar
813 views

Hey guys, today in this post we are going to learn Trigger Scenario: – When an Account record is created then Create a related Contact automatically in Salesforce.

 

 

Final Output β†’

 

Other related post that would you like to learn in Salesforce

πŸ‘‰ Download Free Ebook β†’
πŸ‘‰ Get Free Course β†’

Challenges in your career

🎯 If You Are Facing Any Of These 6 Challenges in your career.

  • Learn Salesforce Development
  • Career Confusion
  • No Interview Call
  • Low Salary
  • No Promotion/Growth
  • No Finding New Job Opportunity
  • Why you stucking from past so many years in same company?

 
  • Apex trigger to create and count the number of child records associated with parent object based on custom field when parent record is created/updated in Salesforce
  • Apex Trigger to Send a Custom Visualforce Component Email Template when Record is Created on Custom Object in Salesforce
  • Trigger to Update the Custom Last Modified Date Field in the Parent Object When the Records in the Child Object is Updated Using Apex Trigger in Salesforce
  • Trigger to update count of child records with custom field of parent object | count of child records on parent for lookup relationship uses of apex trigger in Salesforce
  • Create rollup summary using Apex trigger on custom object | rollup summary trigger for count of child records on custom object in Salesforce example
  • Create Duplicate Rule & Matching Rule to Prevent Insert/Update Duplicate Records on Contact sObject based on Contact Email and Contact Phone in Salesforce
  • Apex trigger on Account to avoid creation of duplicate record if the account with same phone exists in the system in Salesforce
  • Write a trigger on contact to update parent record when child is updated using apex trigger in Salesforce
  • Write a trigger whenever Opportunity is deleted the corresponding Account and Contact should be deleted uses of Apex trigger in Salesforce
  • Write a trigger on Contact to Prevent the user to create duplicate Contact based on Phone if Phone number is already exist on related account in Salesforce
  • Write Validation rule for StageName of opportunity sObject that don’t allow the user to move Previous/Next Stage based on User/Profile (Except specific profile of user) in Salesforce

 

Create Apex Trigger β†’

Step 1:- Create Apex Controller : AccountTrigger.apxt

SFDX:Create Apex Trigger>> New >> AccountTrigger.apxt

AccountTrigger.apxt [Apex Trigger]


  1.    TRIGGER AccountTrigger ON Account (BEFORE INSERT, after INSERT) {
  2.  
  3.     IF(TRIGGER.isBefore){
  4.  
  5.     }ELSE IF(TRIGGER.isAfter && TRIGGER.isInsert){
  6.  
  7.        accountTriggerHandler.contactRelAccount(TRIGGER.new);        
  8.     }
  9.  
  10.  
  11. }

 

Create Trigger Handler Controller β†’

Step 2:- Create Apex Controller : accountTriggerHandler.apxc

SFDX:Create Apex Trigger>> New >> accountTriggerHandler.apxc

accountTriggerHandler.apxc [Trigger Handler]


  1.  public class accountTriggerHandler {
  2.  
  3.     public static void contactRelAccount(List<Account> accList){
  4.         List<Contact> conList = NEW List<Contact>();
  5.         FOR(Account acc:accList){
  6.             Contact con= NEW Contact();
  7.             con.FirstName=acc.Name;
  8.             con.LastName='Con Last Name';
  9.             con.Phone=acc.Phone;
  10.             con.Description=acc.Description;
  11.             con.AccountId=acc.Id;
  12.             conList.add(con);
  13.         }
  14.  
  15.         IF(!conList.isEmpty()){
  16.             INSERT conList;
  17.         }
  18.  
  19.     }
  20. }

 

Further post that would you like to learn in Salesforce

  • Trigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in Salesforce
  • Create a Apex Trigger on Account to Update the Associated Contact Account Name Null Whenever Account Record is Updated in Salesforce
  • Trigger to check duplicate name to custom object in Salesforce | how to prevent duplicate records based on multiple fields through apex trigger in Salesforce
  • Write a Apex trigger to Add the Contact First Name and Last Name to Associated Account Custom Field Whenever the Contact inserted or Updated in Salesforce
  • Trigger to update parent records field when child record is updated | update parent field from child using apex trigger
  • How to call invocable method (@InvocableMethod) from APEX Controller to convert automatic lead to Account, Contact and Opportunity Uses of Flow Builder/Flow Action in Salesforce
  • Write a trigger to update parent account phone number whenever the contact phone number is updated using trigger handler and helper class in Salesforce
  • Trigger on custom object to prevent delete the related list record based on lookup relation whenever trying to delete parent record, throw an error message using apex class handler trigger in Salesforce
  • Write a trigger on lead to prevent duplicate records based on lead email Whenever the records is inserted Or updated using apex class handler trigger in Salesforce
  • Apex Trigger on Contact to Create Account Automatically and map to related account Id to Contact Whenever New Contact is Created in Salesforce
FAQ (Frequently Asked Questions)

What is the difference between Contacts and related Contacts?

The 'Related Contacts' list for an Organization is a list of all Contacts whose 'Organization Name' field matches the Organization in question.

What is the difference between Contacts related and contact roles?

A contact is someone directly associated with an account. For example, Kate Chamberlain is the Director of Event Planning for Portsmouth College, so she is listed in the Contacts related list on that account. A contact role, however, describes the part a person plays on the account.

Can a contact be related to multiple accounts in Salesforce?

When you use Contacts to Multiple Accounts, each contact still requires a primary account (the account in the Account Name field). The contact and its primary account have a direct relationship. But you can add other accounts to the contact. These secondary account-contact relationships are indirect.

Related Topics | You May Also Like

  • Upon Contact record creation if LeadSource Field is having value as β€˜Web’ or β€˜Phone Inquiry’ then Populate Level as β€˜Primary’ through Apex Trigger in SalesforceUpon Contact record creation if LeadSource Field is having value as β€˜Web’ or β€˜Phone Inquiry’ then Populate Level as β€˜Primary’ through Apex Trigger in Salesforce
  • Do not allow delete Account, if any of related Contact associated with Account in Salesforce |  Prevent the deletion of Account which have related contact through apex trigger in SalesforceDo not allow delete Account, if any of related Contact associated with Account in Salesforce | Prevent the deletion of Account which have related contact through apex trigger in Salesforce
  • While creation of Account if Phone is null then throw an error message, Here we are applying a custom validation in apex triggerWhile creation of Account if Phone is null then throw an error message, Here we are applying a custom validation in apex trigger
  • Apex Trigger to update Account phone from Contact Phone based on lookup relationship in Salesforce | Update the related Account Phone if Contact Record is Created in SalesforceApex Trigger to update Account phone from Contact Phone based on lookup relationship in Salesforce | Update the related Account Phone if Contact Record is Created in Salesforce
  • Whenever new Contact is created, we will be updated correspondence Account field of β€œStatus”, if Account Developer field Selected as “Salesforce Developer”, then status should be updating automatically “true”   || we will be checking, If Contact is created then we will check associated Account’s Developer field, if Developer selected as β€œSalesforce Developer”, then then we will be updating Status “true” in SalesforceWhenever new Contact is created, we will be updated correspondence Account field of β€œStatus”, if Account Developer field Selected as “Salesforce Developer”, then status should be updating automatically “true” || we will be checking, If Contact is created then we will check associated Account’s Developer field, if Developer selected as β€œSalesforce Developer”, then then we will be updating Status “true” in Salesforce
  • Upon Contact record creation if LeadSource Field is having value as β€˜Web’ or β€˜Phone Inquiry’ then Populate Level as β€˜Primary’Upon Contact record creation if LeadSource Field is having value as β€˜Web’ or β€˜Phone Inquiry’ then Populate Level as β€˜Primary’
  • If Account Active fields selected β€œYes” and Related Opportunities Stage has β€œClosed Lost” then display error message in Salesforce || If Account Active fields selected β€œYes” and Related Opportunity Stage has β€œClose Lost” then don’t allow to updated record, here we will display error message in SalesforceIf Account Active fields selected β€œYes” and Related Opportunities Stage has β€œClosed Lost” then display error message in Salesforce || If Account Active fields selected β€œYes” and Related Opportunity Stage has β€œClose Lost” then don’t allow to updated record, here we will display error message in Salesforce
  • Write a trigger on Account Whenever New Account Record is created, then needs to create associated Contact Record Automatically with Account name as Contact LastName and Account Phone as Contact Phone in Salesforce | Apex Trigger Create Related Contact whenever new Account is created in SalesforceWrite a trigger on Account Whenever New Account Record is created, then needs to create associated Contact Record Automatically with Account name as Contact LastName and Account Phone as Contact Phone in Salesforce | Apex Trigger Create Related Contact whenever new Account is created in Salesforce
 
  

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



Vijay Kumar

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

Categories Trigger, Tutorial Tags after update trigger on account to create contact, bulkified contact trigger that creates an account, contact being automatically created with an account, create a trigger that creates a related contact, create a trigger to validate that no more than 3 contact get added to an account, create related contact automatically from contact in apex trigger, Create Related Contact whenever new Account is created, how to query related Contact from Account by Id in, trigger to create account when contact is created, upon account creation if industry is not null in apex trigger, what is a 360-degree view in salesforce?, whenever new account record is created then needs to create associated contact record automatically, which of these actions can be done from an account record?, write a trigger to update the contact address when ever the account address is updated
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
When an Account record is created then Create a related Opportunity automatically in Salesforce

Archives β†’

Categories β†’

  • Blog (4)
  • More (7)
  • Tutorial (259)
    • Formula Field (1)
    • JQuery (12)
    • Lightning Component (60)
    • React Js (2)
    • Salesforce Integration (8)
    • Salesforce LWC (108)
    • Trigger (43)
    • Validation Rule (9)
    • Visualforce (16)

Global Visitors β†’

Popular Posts β†’

  • display lightning output fields label/value as a read-only in Salesforce LWC How to use output-field label/value represents as a read-only help-text Using of lightning:outputField element in Salesforce LWC | how do you display lightning output fields label/value as a read-only in Salesforce lightning web component — LWC 4 views per day
  • save Pdf as a attachement in salesforce -- w3web.net Save the Attachment as PDF using Apex Class and Visualforce Page on click button in Salesforce | How to save instantly my pdf visualforcepage as a file/attachment on click button in Salesforce | Rendering a VF page as PDF and saving it as an attachem... 3.67 views per day
  • lwc custom component to upload multiple file -- w3web.net How to creates a custom file uploader component that allows multiple files of JPG, PNG, PDF to be upload in object Uses of ‘lightning-file-upload’ elements in Salesforce Lightning Web Component — LWC | How to upload multiple files i... 3.33 views per day
  • create button menu with custom dropdown in lwc -- w3web.net Create Button Menu with Custom dropdown with a list of actions/functions and display selected value when you click on list option uses of ‘lightning-button-menu’ tag element in Salesforce lightning web component – LWC | Set the valu... 3.33 views per day
  • disabled input field values in lwc -- w3web.net How to disabled all of input field values dynamically based on button click Uses of foreach loop in javascript in Lightning Web component Salesforce – LWC | How to make lightning-input fields values disabled based on click a button Using dynami... 3.33 views per day
  • create lightning datatable row actions in lwc -- w3web.net Creating a Lightning Datatable with Row Actions and Display a Modal Popup on Click View Icon Button in Salesforce Lightning Web Component – LWC | how to create lightning datatable row actions in lwc 3.33 views per day
  • upload delete and preview files attachments lightning component -- w3web.net How to get upload/delete and preview the files attachments through apex class uses of lightning:fileCard and lightning:fileUpload elements in Salesforce Lightning component | file Uploader With Preview & Delete in aura component Salesforce 3.17 views per day
  • trigger to create account Automatically whenever contact is is created -- w3web.net Apex Trigger on Contact to Create Account Automatically and map to related account Id to Contact Whenever New Contact is Created in Salesforce | trigger to create account automatically whenever contact is created in salesforce 3.17 views per day
right side banner -- www.surfmyindia.com
right side banner -- overstockphoto.blogspot.com

Join Our Newsletter β†’

Loading
right side banner -- www.lifedreamguide.com

Recent Posts β†’

  • How JSX Works in ReactJS (With Live Example)
  • Introduction to ReactJS – Create Your First React App
  • How to use custom event & dispatch event in LWC | How to dispatch event from child to parent in LWC – Lightning Web Component?
right side banner -- www.w3webmart.com


header banner -- www.overstockphoto.blogspot.com
  • Follow Me β†’
➑ : Facebook
➑ : Twitter
➑ : Linkedin
➑ : Instagram
➑ : Reddit
➑ : Forcetalks
➑ : Pinterest
➑ : Github
➑ : Medium
➑ : Tumblr
➑ : Telegram
 
header banner -- www.overstockphoto.blogspot.com

Recent Posts β†’

  • How JSX Works in ReactJS (With Live Example)
  • Introduction to ReactJS – Create Your First React App
  • How to use custom event & dispatch event in LWC | How to dispatch event from child to parent in LWC – Lightning Web Component?
header banner -- www.lifedreamguide.com

Popular Posts β†’

  • lwc custom component to upload multiple file -- w3web.net How to creates a custom file uploader component that allows multiple files of JPG, PNG, PDF to be upload in object Uses of ‘lightning-file-upload’ elements in Salesforce Lightning Web Component — LWC | How to upload multiple files in lwc 5 views
  • Create custom path dynamically for a picklist field of Stage in Opportunity Object using lightning:picklistPath in Lightning Component Salesforce | how to create custom lightning path for a picklist field of Stage in Opportunity 4 views
  • create lightning pill with remove in lwc -- w3web.net How to create lightning-pill button with remove dynamically functionality in LWC Salesforce | create lightning-pill/lightning-pill-container with remove button action in lightning web component Salesforce — lwc 4 views
  • convert datetime to date in lwc -- w3web.net How to convert date format Using @track with html tag in lwc | How to format today Date in DD/MM/YYYY in lightning web components | Convert String To Current Date In Salesforce LWC 4 views
  • How display the current user details in lightning component lwc -- w3web.net LWC to Get Logged in User Id, Name, Email, IsActive, Alias details without apex class Uses of ‘uiRecordApi’ property and display the current User detail on lightning component in Salesforce Lightning Web Component (LWC) | How to get current user detail in lwc 4 views
  • w3web.net Trigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in Salesforce 3 views
  • dynamically fetch picklist values in salesforce lwc -- w3web.net Retrieve picklist values dynamically of Opportunity Object without apex class using ‘uiObjectInfoApi’ property and displaying the selected pick-list value in Salesforce Lightning Component — LWC | How to fetch picklist value without apex method and display selected pick-list value in lwc 3 views
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24classictimes |
  • TechW3web |
  • Refund Policy |
  • Delivery Policy |
  • Privacy Policy |
  • Term & Conditions
© 2025 w3web.net • Built with GeneratePress

Chat Now