2

I have a global class that creates an Opp from a custom lead conversion button. The problem is that the button works to convert the lead to an Opp but it does not open the Opp. I get an error message that "that URL does not exist".

Ideas?

global class convertLead{
    WebService static Id  convertLeadtoAcc(string id){
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(id);
        LeadStatus convertStatus = [SELECT Id, MasterLabel 
                                    FROM LeadStatus 
                                    WHERE IsConverted=true LIMIT 1];                
        lc.setConvertedStatus(convertStatus.MasterLabel);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        Id OpportunityId=[select ConvertedOpportunityId from Lead where id=:id].ConvertedOpportunityId;
        return OpportunityId;
    }
}

My button is an OnClick Javascript button with this code:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var opportunityId=sforce.apex.execute("ConvertLeadCustom","convertLeadtoAcc", {id:"{!Lead.Id}"});
var newURL = "/"+opportunityId[0].id+"/e";
window.location.href=newURL;
3

Since your method returning opportunity Id means var opportunityId contains the actual opportunity Id

You just need redirect to

var newURL = "/"+opportunityId+"/e";
window.location.href=newURL;
1
  • 1
    @MelissaLenai Seeing as Ratan's answer solved your problem please mark it as the correct solution.
    – dBeltowski
    May 27 '16 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.