You need to sign in to do that
Don't have an account?

Open new opportunity when lead is converted
I can't believe no one out there has wanted to do this but I've searched and searched and haven't found anything similar. Specifically when converting a lead with an opportunity we'd like it to immedietly go to the add product page for the opportunity or at least just the page for the opportunity that was just created. It seems like there should be some way to do this. Something must tell it that it was just at the lead page and is now at the account page even if it's an existing account. I just can't find how. If anyone has any ideas on this I would love to hear them.
Thanks,
Amanda
Thanks,
Amanda
Please find the below snippet.
1) Create a global apex class
2) Define a static webservice method with logic to convert the lead
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;
}
}
3) Create a custom convert Lead button
Now use the button to call the below javascript
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var opportunityId=sforce.apex.execute("convertLead","convertLeadtoAcc", {id:"{!Lead.Id}"});
Load the window with the Opportunity Id.
Thanks,
Gokul
System will do the mapping automatically,Please have a look at this link.
https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_dml_examples_convertlead.htm
Thanks,
Gokul
P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
Thanks,
Gokul
{!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;
It creates the Opportunity but it won't open it. I get a URL doesn't exist error message page at the following address. https://cs51.salesforce.com/undefined/e
Any ideas?