0

I was able to reuse code from the another post to successfully convert a lead and have it open to the Opportunity after the conversion. But that code bypasses the VF page that lets you match up to existing contact or account. So duplicates are being created.

Can someone give me tips on how to got the Oppty AFTER the conversion (not necessarily in edit mode). I considered a checkbox on the Opportunity that is TRUE if the oppty is created by a lead conversion. That would trigger another action but I know enough to be dangerous and would like to just reuse someone elses code that works. Thanks.

1 Answer 1

0

In your controller after you do the DML that converts the Lead you will get a LeadConvertResult back.

Database.LeadConvertResult lcr = Database.convertLead(lc);

You can use the LeadConvertResult to get the opportunity Id.

Id oppId = lcr.getOpportunityId();

You can then use the Id to redirect to the Opportunity detail page.

public PageReference goToOpportunity(Id oppId){
    PageReference ref = new PageReference('/'+oppId);
    return ref;
}

OR

// Use Opp with StandardController to get Detail Page.
public PageReference goToOpportunity(Id oppId){
    Opportunity opp = new Opportunity(Id = oppId);
    ApexPages.StandardController sc= new ApexPages.StandardController(opp);
    return sc.view();
}
1
  • Thank you for this information and for your generous time. I will see if I can get it going.
    – Bettymac
    Commented Sep 26, 2016 at 15:05

You must log in to answer this question.

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