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".


global class convertLead{
    WebService static Id  convertLeadtoAcc(string id){
        Database.LeadConvert lc = new database.LeadConvert();
        LeadStatus convertStatus = [SELECT Id, MasterLabel 
                                    FROM LeadStatus 
                                    WHERE IsConverted=true LIMIT 1];                
        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:

var opportunityId=sforce.apex.execute("ConvertLeadCustom","convertLeadtoAcc", {id:"{!Lead.Id}"});
var newURL = "/"+opportunityId[0].id+"/e";

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

You just need redirect to

var newURL = "/"+opportunityId+"/e";
  • 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.