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 Apisero – Salesforce Developer Interview Questions September 25, 2024 Get all Active and Deleted records salesforce November 28, 2022 Trigger: On Insert Contact check if linked Account is already associated to other Contact. Throw Error. January 8, 2025 Trigger : Find all Account related Contacts when an Account is Updated. January 5, 2025 How to fetch all record types of any object in lwc salesforce. January 21, 2022 How to use intl-tel-input JavaScript plugin in lwc component salesforce. February 5, 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.
Trigger: On Insert Contact check if linked Account is already associated to other Contact. Throw Error. January 8, 2025