function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GabeGabe 

Override Convert Lead button with default behavior plus 1 simple action - sample code, please?

I haven't done much with custom S-Controls, so if someone is willing to provide some example code for how to do this, I'd really appreciate it.

 

Basically, I'm running into the issue outlined in the thread Time-Based Workflow Rules on Leads Preventing Lead Conversion --  so I want to create a button override that sets a variable (ConvertMe = true), then converts the lead as usual.

 

How would I do this?

 

I can get a custom button to convert a lead when I use this simple HTML code:

 

/lead/leadconvert.jsp?retURL=/{!Lead.Id}&id={!Lead.Id}

 

But how do I first set the variable? I've tried a number of different functions and OnClick JavaScripts I've found in these discussion boards, but haven't had any luck yet.

 

Any suggestions? It doesn't seem like this should be that complicated, but I'm obviously missing something. :)

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
GabeGabe

Hi Cyberfire-

 

It looks like I made a minor change to a line near the end (in bold below) at some point.

 

Try this version - this is what I have in place now:

 

 

<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<script>
function updateConvertMe()
{
// Store current lead information

var currentLeadId = "{!Lead.Id}";
var leadToUpdate = new sforce.SObject("Lead");
leadToUpdate.Id = "{!Lead.Id}";
LeadId = "{!Lead.Id}";

leadToUpdate.ConvertMe__c="true";
sforce.connection.update([leadToUpdate]);

this.parent.frames.location.replace("{!URLFOR($Action.Lead.Convert, Lead.Id, [retURL=URLFOR($Action.Lead.Convert, Lead.Id)], true)}");

}
updateConvertMe();
</script>

 


 

All Answers

GabeGabe

After lots of research and some help from one of our developers, I got this working.

 

Here's the code for the custom S-Control, in case anyone else needs to do this:







<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<script>
function updateConvertMe()
{
// Store current lead information
var currentLeadId = "{!Lead.Id}";
var leadToUpdate = new sforce.SObject("Lead");
leadToUpdate.Id = "{!Lead.Id}";
LeadId = "{!Lead.Id}";

leadToUpdate.ConvertMe__c="true";
sforce.connection.update([leadToUpdate]);
this.parent.frames.location.replace("/lead/leadconvert.jsp?retURL=/{!Lead.Id}&id={!Lead.Id}");
}
updateConvertMe();
</script>





Force2b_MikeForce2b_Mike

What happens if the user clicks [Cancel] during the convert process? Wouldn't that leave the ConvertMe__c field set to TRUE, but the lead not actually converted?

 

I believe another way to accomplish this without that possibility is to use a Trigger on the Lead that looks for the scenario where the Lead is being converted and then updates your custom field.

 

Mike

GabeGabe

Thanks, Mike. You are right: It seems my Cancel button doesn't work if you're in the middle of a lead conversion, so the ConvertMe field does get set to true once you land on that conversion page.

 

Thanks for the other suggestion re: triggers... I haven't done anything with triggers, though, so I'm not really sure where I'd begin with your suggestion.

 

Alternatively, I may just use DemandTools to run a monthly query to update any leads that may have ended up with a ConvertMe = true.

Force2b_MikeForce2b_Mike

Gabe,

 

I looked at Workflow rules to see if that would, but at least in my quick test it doesn't seem to work on the converted lead. 

 

Another option is to create a report of converted leads and schedule it to run (and eMail you) weekly or monthly. The criteria could be set to "Converted Date = Last 7 Days" so the report only picks up new conversions each time.

 

Triggers are useful for these kinds of updates, though you need Enterprise or Unlimited edition to implement. I'd be happy to help if you want to go this route.

 

Best Regards,

 

Mike

GabeGabe

Thanks again for the input, Mike. I appreciate it.

 

So with the reporting option you mention, are you thinking I would include the ConvertMe value? If the lead eventually ends up getting converted, then it shouldn't be an issue anyway, since I have another workflow rule that will send the same email - on manual lead conversion - that this thing's all about anyway (and that rule doesn't look at the ConvertMe value).

 

The main point here is basically allowing the lead to get converted without having the time-delayed workflow rule block it, so I think as long as I do a regular report or data update via DemandTools, I'm probably all set, as I'm now realizing that it doesn't really matter what the ConvertMe value ends up being (I'm pretty sure :) ).

 

That said, if you think I can accomplish the same thing, but in a more foolproof way, with triggers, then I'm all ears. 

CyberfireCyberfire
Gabe - for some reason, when using the code that you provided, Salesforce just hangs, or seems to be looping when a user clicks "Convert", now that I've overridden the button. Do you know why it would be doing that?
GabeGabe

Hi Cyberfire-

 

It looks like I made a minor change to a line near the end (in bold below) at some point.

 

Try this version - this is what I have in place now:

 

 

<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<script>
function updateConvertMe()
{
// Store current lead information

var currentLeadId = "{!Lead.Id}";
var leadToUpdate = new sforce.SObject("Lead");
leadToUpdate.Id = "{!Lead.Id}";
LeadId = "{!Lead.Id}";

leadToUpdate.ConvertMe__c="true";
sforce.connection.update([leadToUpdate]);

this.parent.frames.location.replace("{!URLFOR($Action.Lead.Convert, Lead.Id, [retURL=URLFOR($Action.Lead.Convert, Lead.Id)], true)}");

}
updateConvertMe();
</script>

 


 

This was selected as the best answer
CyberfireCyberfire

Gabe - this is perfect, thanks!

 

This is exactly what I was needing for our org, and now that you've provided the workaround, we're able to get past this, thanks again! :smileyhappy:

GabeGabe
Great! Glad to hear this did the trick for you!
goabhigogoabhigo

Cool.

ultratechultratech

Hi Gabe,

Thanks for developing this.  It's much needed.  When I enter your code into my S-controls Content box, it wont let me save because it says there is a Syntax error.  It specifically highlights one part (bolded/underlined below) do you know why it would be doing this?

 

<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<script>
function updateConvertMe()
{
// Store current lead information

var currentLeadId = "{!Lead.Id}";
var leadToUpdate = new sforce.SObject("Lead");
leadToUpdate.Id = "{!Lead.Id}";
LeadId = "{!Lead.Id}";

leadToUpdate.ConvertMe__c="true";
sforce.connection.update([leadToUpdate]);

this.parent.frames.location.replace("{!URLFOR($Act​ion.Lead.Convert, Lead.Id, [retURL=URLFOR
($Action.Lead.Convert, Lead.Id)], true)}");

}
updateConvertMe();
</script>

GabeGabe

Glad it will help you out, ultratech.

 

When I copy your code into my SFDC account as a new s-control, I get the same syntax error. But when I copy my existing code into a new s-control and check syntax, it's fine.

 

Here it is:

 

 

<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<script>
function updateConvertMe()
{
// Store current lead information

var currentLeadId = "{!Lead.Id}";
var leadToUpdate = new sforce.SObject("Lead");
leadToUpdate.Id = "{!Lead.Id}";
LeadId = "{!Lead.Id}";

leadToUpdate.ConvertMe__c="true";
sforce.connection.update([leadToUpdate]);

this.parent.frames.location.replace("{!URLFOR($Action.Lead.Convert, Lead.Id, [retURL=URLFOR($Action.Lead.Convert, Lead.Id)], true)}");

}
updateConvertMe();
</script>

 

 

Salesforce SamuraiSalesforce Samurai

Does anyone have a Visual Force solution for this?  S-Controls are no longer supported.

 

Much appreciated!

 

Thanks!

StrangeLooperStrangeLooper

Huzzah! thanks so much, this worked for me, I tried a few other codes out there but this was the only one that worked.

GabeGabe

Glad to hear it, StrangeLooper! 

Jay AllenJay Allen

I was able to accomplish the same thing using this tip:  http://www.opfocus.com/2011/08/how-to-convert-a-lead-in-use-by-a-time-based-workflow-in-salesforce/

 

Note:  The visualforce page did not function correctly at first.  I had to clean up the line breaks and commenting in the code in order for it to function. 


Salesforce Samurai wrote:

Does anyone have a Visual Force solution for this?  S-Controls are no longer supported.

 

Much appreciated!

 

Thanks!


 

Salesforce Learning 5Salesforce Learning 5
Hello can you please share the visualforce code..
there is nothing in that link..

i need of that code... 
thanks i advance.