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

If statement in custom button
I'm trying to create a custom button that will auto-select the From address when sending an email from a case, depending on a custom field on the case record. I've tried several ways of doing this, but none of them seem to be working correctly. One of the posts I found on the board uses Javascript to hack the URL, and I've tried doing this, but I get the error "unexpected token ILLEGAL" when I try it. Here's the code I'm using:
IF({!Case.CustomField__c} = 'Option 1', location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&p26=address1@gmail.com;,
(IF({!Case.CustomField__c}='Option 2', location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&p26=address2@gmail.com;,
location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId};)))
I imagine I'm doing this wrong, since this seems to be mixing Salesforce formulas with Javascript. Is this the correct way to approach my issue, or is there a way to make the button link to the desired URL without using Javascript?
No, you have to use Javascript.
You could use JavaScript, You need to make a HiddenField "theField" with the value of your Case.CustomField__c
<script>
function newTask()
{
var Tmp = document.getElementById("{!$Component.ThePage.TheForm.TheBlock.theField}").value;
if(Tmp == 'Option 1') var newURL = "ALL YOUR URL";
...etc...
window.parent.location.replace(newURL);
}
</script>
<apex:pageBlockButtons >
<apex:commandButton value="Button 1" onclick="newTask()"/>
</apex:pageBlockButtons>
Okay, so if I want to customize the "Send an Email" button in Setup/Customize/Activities/Activity Buttons (or another custom button defined in Tasks/Activities), I would change that button to us a custom S-Control, right? How do I define the S-Control to execute this script? From what I can tell, I would set the type to HTML and include the script as defined in your example, but what is the command to execute that script?
Ok sorry I didn't understand that you were overriding a button. I thought that you have a custom button in a VF.
When you click in your actual button you've got an URL, this url may have in the "retURL" or in the "Id", the value of your id Lead. Something like that: cs2.salesforce.com/......?retURL=/XXXX&id=XXXXX
Check which variable has the id of the lead
Now You could override your button to a VF instead an S-Control, and in your class make a sql of the value of your custom field.
In your VF something like:
In your Class