+ Start a Discussion
anjaanja 

create opportunity from contact automatically

is it possible to use a trigger/apex to create an opportunity automatically from a contact once a contact is created?

Best Answer chosen by Admin (Salesforce Developers) 
cashworthcashworth

Sounds to me like you need to have the trigger fire after insert on CampaignMember. Make sure you include an IF statement that checks to see that the Contact ID != null on the CampaignMember record.

 

Also, make sure you query the Campaign and populate the Campaign field on the opportunity to ensure it gets associated to the campaign as well.

All Answers

bob_buzzardbob_buzzard

You could create an opportunity from a contact and an after insert trigger.  You'd need to provide some fields that may not be obvious - close date, for example.

anjaanja

Thanks Bob,

another question - what I am being asked to do is when a contact is added to a campaign (becomes campaign member) of a certain record type - create a new opportunity related to that contact - I am being told that the contact will already exist. Tyring to wrap my head around this one - campain memeber ship is a related list on contact, but that is all. Not sure if I need to add a field on contact to reflect campaign membership specifically for that record type in order to give something to trigger off of.

 

Starz26Starz26

Trigger on the Campaign using the contact's id in the record to create the opportunity

cashworthcashworth

Sounds to me like you need to have the trigger fire after insert on CampaignMember. Make sure you include an IF statement that checks to see that the Contact ID != null on the CampaignMember record.

 

Also, make sure you query the Campaign and populate the Campaign field on the opportunity to ensure it gets associated to the campaign as well.

This was selected as the best answer
anjaanja

That worked - thanks!

cashworthcashworth

Glad it worked for you!