2

On a lead conversion, I would like to convert the information on the lead to an additional object. This object will be associated with both the account, as well as the opportunity.

trigger createApp on Opportunity (after insert) {
    List<ID> opportunityIds = new List<ID>();
    for (Opportunity opps : Trigger.new) {          
       opportunityIds.add(opps.Id);     
    }

   Lead lead = [SELECT ID, Custom__c FROM Lead where ConvertedOpportunityID = :opportunityIds[0]];

is the current top part of my code.

It throws the error that lead is not being assigned to any value, meaning that ConvertedOpportunityID is not equal to the opportunity ID that is being stored from Trigger.new

Any thoughts would be appreciated.

1 Answer 1

1

after insert on Opportunity is bit too soon, check Lead Conversion Trigger Order of Execution

(think about it like that: OK, Opp was freshly created but you're jumping in in the middle of that process, "insert" didn't finish yet. It does have to finish before the Id can be put on the respective Leads)

Also - your query could be simplified to WHERE ConvertedOpportunityId IN :trigger.new for example (no need to fetch Ids into set + it's generally a mistake to bind only the 1st element of collection).

1
  • Thanks for the quick response! This was extremely useful.
    – James
    Commented Dec 22, 2013 at 20:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .