Skip to content
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24globalworld |
  • News24classictimes |
  • Incriediableindia |
  • TechW3web |
  • W3Force ..
w3web.net
Sign Up to Get Free Code Access → |
  • Home
  • Tutorial
    • Lightning Component
    • Salesforce LWC
    • Salesforce Integration
    • Visualforce
    • Trigger
    • JQuery
  • Get Free 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
1,308 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

  • 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


🎁 Up to 99% Off Courses (Coupon)
💥 Use Promo Code: STANDARDOFFER💥
🚀 Get Free Salesforce Course Access: www.thevijaykumar.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
  • 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
  • Write apex trigger on custom Parent Object (Parent__c) to update the related Child Object (Child__c)  Phone whenever Parent__c Phone is Updated | Apex Trigger to update the related Object Phone whenever Parent Phone is updatedWrite apex trigger on custom Parent Object (Parent__c) to update the related Child Object (Child__c) Phone whenever Parent__c Phone is Updated | Apex Trigger to update the related Object Phone whenever Parent Phone is updated
  • 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

👉 Get Complementary →

right side banner -- www.w3webmart.com
 
  
👉 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 →

  • Agentforce (4)
  • Blog (4)
  • More (7)
  • Tutorial (326)
    • Formula Field (1)
    • JQuery (13)
    • Lightning Component (60)
    • React Js (15)
    • Salesforce Integration (41)
    • Salesforce LWC (115)
    • Trigger (57)
    • Validation Rule (9)
    • Visualforce (16)
  • Uncategorized (4)

Global Visitors →

Popular Posts →

  • Create Quote and QuoteLineItem From Opportunity in LWC -- w3web.net How to Create Quote and QuoteLineItem From Opportunity in Lightning Web Component – LWC Salesforce | How to add and delete rows dynamically in lightning web component | How to create multiple records dynamically with custom functionaliy in LWC 4.17 views per day
  • Write Apex Trigger Whenever a Contact is Inserted / Updated / Deleted, We need to Count child Contacts related to each Account Based on MailingCountry Only for these 4 countries (India, USA, England, Japan) Then store the count on Account object. 3.17 views per day
  • 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 Salesforce 3 views per day
  • Salesforce sends Contact data to an External CRM System using POST REST API, External system returns a Customer Reference ID, salesforce stores that ID in a custom field, Whenever Contact Phone or Email is updated, Salesforce notifies the external sy... 3 views per day
  • update contact account name Null whenever account record is updated -- w3web.net Create a Apex Trigger on Account to Update the Associated Contact Account Name Null Whenever Account Record is Updated in Salesforce | trigger to update account name of contact whenever account record is updated 2.50 views per day
  • Apex Trigger Whenever Contact is Inserted/Updated/Deleted/Undeleted We need to count Contacts based on LeadSource and update Account, LeadSource values: Web, Phone Inquiry, Partner Referral, Advertisement 2.33 views per day
  • use the lightning formatted fields in lwc - w3web.net How to use the lightning-formatted-email, lightning-formatted-number, lightning-formatted-phone, lightning-formatted-date-time, lightning-formatted-text, lightning-formatted-address, lightning-formatted-url in Salesforce lightning web component (LWC)... 2.33 views per day
  • lightning datatable inline edit lwc -- w3web.net Example of lightning-datatable inline to edit/save rows of records and refresh lwc component on click button in Salesforce Lightning Web Component — LWC | Inline Edit/Save Field and refresh the component after successful save of standard record... 2.33 views per day

Get Free Courses →

right side banner -- www.surfmyindia.com
right side banner -- overstockphoto.blogspot.com

Join Our Newsletter →

Loading
right side banner -- www.lifedreamguide.com

Recent Posts →

  • Create a hand-on example as pass input value from parent to child component through PubSub Model LWC in Salesforce
  • How to pass input value from parent to child component through LMS method in Salesforce | Hand-on example as pass input value from parent to child component through Lightning Message Service (LMS) in Salesforce
  • Apex Trigger Whenever Case is: Inserted/Updated/Deleted/Undeleted We need to count Cases based on Priority: High, Medium, Low And update counts on Account
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
 

🧩 Get Free Courses

👉 Get Complementary →

right side banner -- www.w3webmart.com
header banner -- www.overstockphoto.blogspot.com

Recent Posts →

  • Create a hand-on example as pass input value from parent to child component through PubSub Model LWC in Salesforce
  • How to pass input value from parent to child component through LMS method in Salesforce | Hand-on example as pass input value from parent to child component through Lightning Message Service (LMS) in Salesforce
  • Apex Trigger Whenever Case is: Inserted/Updated/Deleted/Undeleted We need to count Cases based on Priority: High, Medium, Low And update counts on Account
  • Apex Trigger Whenever Opportunity is: Inserted/Updated/Deleted/Undeleted We need to: Calculate total Amount of all Opportunities Where StageName = ‘Closed Won’ And update it on Account
  • Apex Trigger Whenever Opportunity is Inserted/Updated/Deleted/Undeleted We need to count how many Opportunities have: StageName = ‘Closed Won’ And update that count on Account.
  • Apex Trigger Whenever Contact is Inserted/Updated/Deleted/Undeleted We need to count Contacts based on LeadSource and update Account, LeadSource values: Web, Phone Inquiry, Partner Referral, Advertisement
header banner -- www.lifedreamguide.com

Popular Posts →

  • 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 attachement in Salesforce 7 views
  • Apex Trigger Whenever Contact is Inserted/Updated/Deleted/Undeleted We need to count Contacts based on LeadSource and update Account, LeadSource values: Web, Phone Inquiry, Partner Referral, Advertisement 6 views
  • Create a hand-on example as pass input value from parent to child component through PubSub Model LWC in Salesforce 4 views
  • Create Quote and QuoteLineItem From Opportunity in LWC -- w3web.net How to Create Quote and QuoteLineItem From Opportunity in Lightning Web Component – LWC Salesforce | How to add and delete rows dynamically in lightning web component | How to create multiple records dynamically with custom functionaliy in LWC 4 views
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24classictimes |
  • TechW3web |
  • Refund Policy |
  • Delivery Policy |
  • Privacy Policy |
  • Term & Conditions
© 2026 w3web.net • Built with GeneratePress

Chat Now