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
Kyle Floersch 1Kyle Floersch 1 

Custom Button Validation Rule

I have a custom button that I would like to validate against the Status field. 
If Status does not equal "Approved by Business Manager" return an error message. 

I have tried the following but does not work:

IF({!ISPICKVAL( Invoice__c.Status__c , "Approved by Business Manager")},
/apex/loop__looplus?sessionId={!$Api.Session_ID}&eid={!Invoice__c.Id}
&ddpids=a0Z50000009UjxA&deploy=a0Y500000091MwT
&contactid=0035000002ZrYHU,
Alert('Value can only be Approved by Business Manager'))
Best Answer chosen by Kyle Floersch 1
RainnyCloudyRainnyCloudy
If you have your custom button setup to execute JavaScript you can try this:
 
if(!{!ISPICKVAL(Invoice__c.Status__c, "Approved by Business Manager")}){
    alert('Value can only be Approved by Business Manager');
}else{
   window.open("/apex/VF_Example?sessionId"+{!$Api.Session_ID}+"&eid="+{!Invoice__c.Id}+"&ddpids=a0Z50000009UjxA&deploy=a0Y500000091MwT
&contactid=0035000002ZrYHU", "_blank");
}

 

All Answers

RainnyCloudyRainnyCloudy
If you have your custom button setup to execute JavaScript you can try this:
 
if(!{!ISPICKVAL(Invoice__c.Status__c, "Approved by Business Manager")}){
    alert('Value can only be Approved by Business Manager');
}else{
   window.open("/apex/VF_Example?sessionId"+{!$Api.Session_ID}+"&eid="+{!Invoice__c.Id}+"&ddpids=a0Z50000009UjxA&deploy=a0Y500000091MwT
&contactid=0035000002ZrYHU", "_blank");
}

 
This was selected as the best answer
Kyle Floersch 1Kyle Floersch 1
Thanks for your reply. 

I have it setup to execute JavaScript but seems to have an issue with the below underlined part of the code:

if(!{!ISPICKVAL(Account.CustomerPriority__c, "High")}){
    alert('Value can only be Approved by Business Manager');
}else{
   window.open("/apex/loop__looplus?sessionId"+{!$Api.Session_ID}+"&eid="+{!Invoice__c.Id}+"&ddpids=a0Z50000009UjxA&deploy=a0Y500000091MwT
&contactid=0035000002ZrYHU
", "_blank");
}

Getting the following error: 
A problem witht he OnClick javaScript for this button or link was encountered. 
Unexpected token ILLEGAL



To test I ran this piece and it worked and triggered the alert and if correct status it opened the VF Page. But I need to add the IDs. 

if(!{!ISPICKVAL(Invoice__c.Status__c, "Approved by Business Manager")}){
    alert('Status is not Approved by Business Manager');
}else{
  //alert("in else block");
   window.open("/apex/loop__looplus", "_blank");
}


 
RainnyCloudyRainnyCloudy
It's probably something within the url your trying to open. 


window.open("/apex/loop__looplus?sessionId=" + {!$Api.Session_ID} + "&eid= " +{!Invoice__c.Id} + "&ddpids=a0Z50000009UjxA&deploy=a0Y500000091MwT
&contactid=0035000002ZrYHU", "_blank");

 
Kyle Floersch 1Kyle Floersch 1
Thanks for your help Luke. There was an issue with the url I was opening. Works now. .