Ask Search:
Alexander OlanderAlexander Olander 

Contact info to Account Details

Hi Guys

I'm trying to make a flow that copy some of the infomation from a Primary Contact on a Oppertunity to some custome fields under Details in the related Account. Is this possible ? 

Hope you guys can help me out. 

Best Regards 
Alexander
Best Answer chosen by Alexander Olander
Nitish SinghalNitish Singhal
Great !!

Then it will be a trigger on Opportunity, after insert, after update, if opportunity.primaryContact != null, then query the primary contact fields by writing a SOQL on contact object. Once done, you need to update the Account record. 

Account acc = new Account(id=opportunity.AccountId, fieldName = primaryContact.fieldValue);
update acc;

A developer can help in writing the bulkified trigger code. But if you are the one to start, I would suggest to go through this trailhead trail to learn triggers. 
https://trailhead.salesforce.com/en/modules/apex_triggers/units/apex_triggers_intro

Happy coding !! :)

Thanks
Nitish

All Answers

Nitish SinghalNitish Singhal
Hi Alexander,

Yes you can do that definitely, but it will only make sense if an Account has only one opportunity with one primary contact. 

If there will be multiple opportunities associated to an account, then it's possible that each opp will have its own primary contact, so there will be a confusion, that which opportunity's primary contact's information will be updated on account fields. I hope you get my point. 

But if you are clear that what needs to be done, then it would be done using apex triggers only. 

Hope it helps !!

Thanks
Nitish
Alexander OlanderAlexander Olander
Hi Nitish 

Yep I had allready considered that. But lucky for us we do only have 1 opp per account. 
Ok do you know any guide to the apex trigger I need ? 
Nitish SinghalNitish Singhal
Great !!

Then it will be a trigger on Opportunity, after insert, after update, if opportunity.primaryContact != null, then query the primary contact fields by writing a SOQL on contact object. Once done, you need to update the Account record. 

Account acc = new Account(id=opportunity.AccountId, fieldName = primaryContact.fieldValue);
update acc;

A developer can help in writing the bulkified trigger code. But if you are the one to start, I would suggest to go through this trailhead trail to learn triggers. 
https://trailhead.salesforce.com/en/modules/apex_triggers/units/apex_triggers_intro

Happy coding !! :)

Thanks
Nitish
This was selected as the best answer