You need to sign in to do that
Don't have an account?
Gopikrishna Dasari
I have one question I want to write the trigger when ever I am trying to insert or update the contact I want to update the contact email with account email
any one can help me on this
Please try with the below trigger and let me know further :
Hope this helps !
Thank you.
All Answers
I will suggest you can just create a simple formula field if you want to keep contact email same as account email.
Or else if the requirements is as you mentioned, will suggest to use Salesforce flow and keep email up to date.
Follow below link
https://help.salesforce.com/s/articleView?id=sf.flow_build_data_update.htm&type=5
If this resolved your question please dont forget to mark it as Best answer
Please try with the below trigger and let me know further :
Hope this helps !
Thank you.
Here's a general outline of what the trigger could look like:
apexCopy code
trigger UpdateContactEmail on Contact (before insert, before update) { for (Contact contact : Trigger.new) { // Check if the contact has an associated account if (contact.AccountId != null) { // Get the related account record Account relatedAccount = [SELECT Id, Email FROM Account WHERE Id = :contact.AccountId LIMIT 1]; // Update the contact's email with the account's email if (relatedAccount != null && relatedAccount.Email != null) { contact.Email = relatedAccount.Email; } } } }
Please make sure to test the trigger thoroughly in a sandbox environment before deployingor try the nol monthly pass (https://nolcard.ae/nol-card-monthly-pass/) it to production. If you encounter any issues or need further assistance, feel free to ask!
Thanks for your answer.
Thanks,
Gopikrishna
Can you please give brief explanation how can we create flow on this requirement.
Thanks in advance.
Thanks,
Gopikrishna.