You need to sign in to do that
Don't have an account?
Sales Development
How to copy Email of Primary Contact in a new custom field in Opportunity ?
Hello everyone,
I am trying to create a workflow or a process builder or even an APEX trigger in order to copy automatically the email of primary contact into a new Opportunity custom field when the Primary Contact is created or changed/edited.
I found a solution for this but it was not completely automatic since the custom field was a lookup field and for each opportunity, i had to select it manually, i would like this process totally automatic. I hope it is possible !
Thank you for your future answers, I hope someone can help us !
I am trying to create a workflow or a process builder or even an APEX trigger in order to copy automatically the email of primary contact into a new Opportunity custom field when the Primary Contact is created or changed/edited.
I found a solution for this but it was not completely automatic since the custom field was a lookup field and for each opportunity, i had to select it manually, i would like this process totally automatic. I hope it is possible !
Thank you for your future answers, I hope someone can help us !
May I suggest you to please refer the below link to copy primary contact to opportunity custom field.
- https://developer.salesforce.com/forums/?id=906F00000008yK8IAI
hope It will be helpful.Please mark it as best answer if the information is informative.
Best Regards
Rahul Kumar
Do you have any idea of what is going wrong ?
You are trying to send an email to primary contacts in closed opportunities right?
So What i done for your scenario is:
1) created the custom contact lookup field name:Primary_Contace__c.
2)update the Conatct field from the Opportunity Contact Role using below trigger.
trigger primarycontact on Opportunity (before insert,before update) {
set<Id> OppId=new set<Id>();
for(Opportunity opp:trigger.new)
{
If(opp.Isclosed == True)
{
OppId.add(opp.Id);
}
}
map<Id,Id> OPC=new map<Id,Id>();
for(OpportunityContactRole OCR:[select Id,ContactId,isPrimary,Role,OpportunityId from OpportunityContactRole where OpportunityId = :OppId and IsPrimary=True])
{
OPC.put(OCR.OpportunityId,OCR.ContactId);
}
List<Opportunity> OppUp=new List<Opportunity>();
for(opportunity opp:trigger.new)
{
//OpportunityContactRole OPPCON=OPC.get(opp.Id);
opp.Primary_Contact__c=OPC.get(opp.Id);
OppUp.add(opp);
}
//Update OppUp;
}
3) create the Workflow and in the Email Alert use the Recipient type as Related Contact.
Then select the Related Contact: Primary Contact to Selected Recipients.
Can you please Let me know if it works or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj