-
How this is updating contact's mailing address related to account's billing address?
trigger ContactMailAddr on Contact (before insert, before update) { set<id> setofaccountIds=new set<id>(); for(Contact contact:trigger.new) { if(contact.AccountId!=null) { setofaccountIds.add(contact.AccountId); } } map<id,account> accountmap=new map<id,account>([select id, billingCity, billingState, billingpostalcode, billingStreet, billingCountry from account where id in :setofaccountIds]); for(contact contact :trigger.new) { contact.MailingCity = accountmap.get(contact.AccountId).billingCity; contact.MailingState = accountmap.get(contact.AccountId).billingState; contact.MailingStreet = accountmap.get(contact.AccountId).billingStreet; contact.MailingCountry = accountmap.get(contact.AccountId).billingCountry; contact.MailingPostalCode = accountmap.get(contact.AccountId).billingpostalcode; } }
Log In to reply.
Popular Salesforce Blogs
RemoteAction Annotation In Apex | Salesforce Apex Developer Guide
Annotations: An Apex annotation, like a Java annotation, modifies how a method or class is used. Annotations begin with a @ symbol and are followed…
The Top 5 Benefits of Web-To-Lead
Web-To-Lead is the process of converting a website visitor into Lead. What is a Lead? A Lead is a potential Customer who is interested in…
From Data Islands to Unified Insights: Transforming Business with Salesforce
In the current digital age companies generate huge amounts of data each and every day. However, the majority of this data remains scattered across various…
Popular Salesforce Videos
Salesforce Security Review | Tutorial Video
If you ever wanted to publish an app, you probably know of the Salesforce security review. While dreaded by many developers, it is far from…
Use Aura Component in Screen Flow | Salesforce Flow Builder Tutorial
Hello Trailblazers, In this video, we will learn how to use Aura Component in Salesforce Screen Flow. How to validate the Lightning Component Input from…
Introduction To Salesforce Apex | DataType | Collection | Conditional Statements
In this video salesforce apex hours creators provides an introduction to Apex. Apex enables developers to access the Salesforce platform, back-end database and client-server interfaces…