Trigger – Create Contact when Account is created Create contact with account is created - CodersBugs Post author:Swapnil Jaiswal Post published:June 21, 2024 Post category:Blog / Salesforce Post comments:0 Comments Here is apex trigger for creating contact when new account record is get added. trigger AccountTrigger2 on Account(after insert) { if (trigger.isInsert && trigger.isAfter) { List < Contact > lstContact = new List < Contact > (); for (Account acc: trigger.new) { Contact con = new Contact(); con.FirstName = 'Test Contact' + acc.Name; con.LastName = 'Test'; con.AccountId = acc.Id; lstContact.add(con); } if (!lstContact.isEmpty()) { database.insert(lstContact); } } } Watch the video for clarity You Might Also Like LWC Intermediate Quiz – 15 Questions on Lightning Data Service, Events, LMS & More September 16, 2026 LWC Real Interview Questions Quiz – 39 Questions Asked in Actual Salesforce Interviews September 22, 2026 Get all objects available on polymorphic field December 13, 2022 Identify if a Salesforce Object is Custom or Standard March 8, 2023 InfoBeans Salesforce Interview questions November 2, 2024 Character patterns set 1 November 7, 2022 Leave a Reply Cancel replyCommentEnter your name or username to comment Enter your email address to comment Enter your website URL (optional) Save my name, email, and website in this browser for the next time I comment.
LWC Intermediate Quiz – 15 Questions on Lightning Data Service, Events, LMS & More September 16, 2026
LWC Real Interview Questions Quiz – 39 Questions Asked in Actual Salesforce Interviews September 22, 2026