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
the1castdownthe1castdown 

Trying to Create a Custom Button That Changes Functions Based On Case Data

I started creating a custom button to appear in the details section of cases.  I want the button to go to the "Send an Email" page if it is the first time responding to a support case, but I would like it to go to "Email Messages for Case" page if a reply Email for the support case has been sent.  I got this to work using 2 different buttons with the following code:
 
"Send an Email" button
http://na3.salesforce.com/email/author/emailauthor.jsp?p2_lkid={!Case.ContactId}&p3_lkid={!Case.Id}&p24={!Case.SuppliedEmail}
"Email Messages for Case" button
https://na3.salesforce.com/ui/email/EmailMessageListPage?id={!Case.Id}
 
To put these functions in the same button I figured I'd have to use an IF statement that could check to see if emails have been sent or not.  The best solution I came up with thus far:
 
http://na3.salesforce.com/
{!IF( Case.CreatedDate >= Case.LastModifiedDate ,
"email/author/emailauthor.jsp?p2_lkid=" & Case.ContactId & "&p3_lkid=" & Case.Id & "&p24=" & Case.SuppliedEmail ,
"ui/email/EmailMessageListPage?id=" & Case.Id )}
 
Believe it or not, that code actually works, except for the fact that every "/" inside the IF statement is changed to %2F as well as the"?" which is changed to its HTML equivalent. I've seen that browsers can interpret escaped characters correctly, but for some reason it doesn't work for my function.  If I use URLs without characters that change to their HTML equivalent, such as www.yahoo.com or www.amazon.com the function works great. Any help on this problem as well as a better idea on how to check if Emails activity has occurred would be great.  If this seems like a bad solution for making my salesforce case work more user friendly, I'm open to any ideas.
 
Unless I decide this is the wrong approach for providing better case workflow, I plan to add functionality that applies a support email template to the first Reply email for a support case.