You need to sign in to do that
Don't have an account?

Automatically assign contact roles to opportunities - possible?
I'd like to have a program that would automatically connect all contacts associated with an account to an opportunity as contact roles. I already know that if you create an opportunity from a contact, that the contact is assigned as the contact role. However, I have multiple contacts associated with some of my accounts and I need them to be connected to the opportunity as well. I've created a flow to make opportunity entry easier for the office staff, however getting them to remember to go back and add the contact roles after they have created the opportunities is a pain. It would be so much nicer if this could be done behind the scenes with programing. Is it possible to do this with a flow? I'm using the desktop flow developer, and I see you can make a data source/target with an opportunitycontactrole table. But I'm not sure how to go about adding this to my flow. I'm assuming I'd have to add another lookup element, have the person find the contact to attach, selected it and assign the role. The problem with this, is that the operator, has to know who to add to the opportunity, which opens up a possbility of adding the wrong people. If there was a way to make it automatic, it would remove the potential for operator error.
This can be achieved with the help of trigger and class.You can query the account associated with the opportunity and add all contacts associated with that account to contact role.
I'm a beginner salesforce developer. Would it be possible for you to give me a bit more information about how to do this?
Thanks so much,
Stephanie
Not entirely sure if I got your question right, but this trigger will add all account contacts to the contact roles when you create a new opportunity. Though, one should still manually enter the specific roles for the contacts, and you should probably also write a test class for it.
If this is what you wanted, feel free to mark this as answer. But more importantly, if you'd implement this code, do make sure you understand it , or try to recode it yourself.
Using the above trigger, How would I create the standard functionality where a user adds an opportunity from a contact and this adds the contact to that opportunity as a contact role?
I have a custom button which replaces the standard Opportunity New button because it defaults the stage field and others and therefore loose the standard contact role assignment
I'm pretty new trying to learn apex triggers and classes but using the above trigger from Joseph Dindinger what would the apex test class be? I've watched a few videos and searche on how to create one based on that trigger but I'm completely lost. Thanks for any help.
Thanks,