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
Roger Bannister 53Roger Bannister 53 

If statement in Custom button URL with Error Message for false condition

I have added a custom button to Quote object including an IF conditional statement , when the statement is true it functions correctly however if false instead of showing error message statement I get URL No Longer Exists error - please see code below. What can I do to fix this?
{!IF( ISPICKVAL( Quote.Status , 'Approved') , 

URLFOR('/apex/dsfs__DocuSign_CreateEnvelope', null, [SourceID = Quote.Id, 
LF='1', 
CRL='Email~'+Quote.Email+';LastName~'+Quote.Full_Name__c+';Role~Signer 1,LoadDefaultContacts~0', 
OCO='Send' 
]), "Quote must be submitted for approval") 
}

 
Best Answer chosen by Roger Bannister 53
Roger Bannister 53Roger Bannister 53
Thanks Sekar , I actually found the fix for this I needed to create a VF page (Error Message) and then reference it as URLFOR - see code below.

Regards, Roger

{!IF( ISPICKVAL( Quote.Status , 'Approved') , 
URLFOR('/apex/dsfs__DocuSign_CreateEnvelope', null, [SourceID = Quote.Id, 
LF='1', 
CRL='Email~'+Quote.Email+';LastName~'+Quote.Full_Name__c+';Role~Signer 1,LoadDefaultContacts~0']), URLFOR('/apex/DocuSignQuoteNotApproved'))}

All Answers

SEKAR RAJ.SEKAR RAJ.
Hi Roger,
Try to create varible and store the values there and call the variables based on your if logic.

var res = URLFOR('/apex/dsfs__DocuSign_CreateEnvelope', null, [SourceID = Quote.Id, LF='1', CRL='Email~'+Quote.Email+';LastName~'+Quote.Full_Name__c+';Role~Signer 1,LoadDefaultContacts~0', OCO='Send' ]);
var errMsg = "Quote must be submitted for approval";

{!IF( ISPICKVAL( Quote.Status , 'Approved') ,res , errMsg) }

Thanks,
SEKAR RAJ
Roger Bannister 53Roger Bannister 53
Thanks Sekar , I actually found the fix for this I needed to create a VF page (Error Message) and then reference it as URLFOR - see code below.

Regards, Roger

{!IF( ISPICKVAL( Quote.Status , 'Approved') , 
URLFOR('/apex/dsfs__DocuSign_CreateEnvelope', null, [SourceID = Quote.Id, 
LF='1', 
CRL='Email~'+Quote.Email+';LastName~'+Quote.Full_Name__c+';Role~Signer 1,LoadDefaultContacts~0']), URLFOR('/apex/DocuSignQuoteNotApproved'))}
This was selected as the best answer