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

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!
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
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:
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
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.
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
Thanks again for the input, Mike. I appreciate it.
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.
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>
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:
Cool.
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($Action.Lead.Convert, Lead.Id, [retURL=URLFOR
($Action.Lead.Convert, Lead.Id)], true)}");
}
updateConvertMe();
</script>
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:
Does anyone have a Visual Force solution for this? S-Controls are no longer supported.
Much appreciated!
Thanks!
Huzzah! thanks so much, this worked for me, I tried a few other codes out there but this was the only one that worked.
Glad to hear it, StrangeLooper!
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.
there is nothing in that link..
i need of that code...
thanks i advance.