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
Andrey BolkonskyAndrey Bolkonsky 

Javascript Button to Launch Flow

I have a custom detail page button that launches a flow, however validation rules do not work with custom buttons so I am going to have to use Javascript to Validate the record before it is passed into my flow.

I just learned Apex but know nothing about javascript. How would I turn the below button into a javascript button that won't allow users to access the flow unless certain fields are filled in?
 
/flow/Submission?AnRevID={!Annual_Review__c.Id}&OppID={!Annual_Review__c.OpportunityId__c}&AeID={!Annual_Review__c.Account_ExecutiveId__c}&PmID={!Annual_Review__c.Portfolio_ManagerId__c}&OppOwnerName={!Annual_Review__c.OppOwnerName__c}&OppOwnerID={!Annual_Review__c.OppOwnerID__c}&Status={!Annual_Review__c.Status__c}&AnRevName={!Annual_Review__c.Name}&AccountID={!Annual_Review__c.AccountId__c}&OPM={!Annual_Review__c.OPM__c}&OppName={!Annual_Review__c.Opportunity__c}&Product={!Annual_Review__c.Product__c}&OppOwnerState={!$User.State}

 
PriyaPriya (Salesforce Developers) 
Hi Andrey,

Try the below code :- 
 
{!REQUIRESCRIPT(“/soap/ajax/30.0/connection.js”)}
{!REQUIRESCRIPT(“/soap/ajax/24.0/apex.js”)}

var ReferraAccepted = sforce.connection.query(“SELECT OpportunityId__c,Account_ExecutiveId__c,Portfolio_ManagerId__c,OppOwnerName__c,OppOwnerID__c,Status__c,
 Name,AccountId__c,OPM__c,Opportunity__c,Product__c from Annual_Review__c where id ='{!Annual_Review__c.Id}’ limit 1”);

records = ReferraAccepted.getArray(“records”);

var recStatus = records[0].Status__c; // assign the quiered records to a variable

if(recStatus==null){ // add your condition here
alert(“Please submit the completed referral form to the Clearing House as this form cannot be submitted on it’s own.”) // Add your validation message here
}
else {
alert(“Success”)
/flow/Submission?AnRevID={!Annual_Review__c.Id}&OppID={!Annual_Review__c.OpportunityId__c}&AeID={!Annual_Review__c.Account_ExecutiveId__c}&PmID={!Annual_Review__c.Portfolio_ManagerId__c}&OppOwnerName={!Annual_Review__c.OppOwnerName__c}&OppOwnerID={!Annual_Review__c.OppOwnerID__c}&Status={!Annual_Review__c.Status__c}&AnRevName={!Annual_Review__c.Name}&AccountID={!Annual_Review__c.AccountId__c}&OPM={!Annual_Review__c.OPM__c}&OppName={!Annual_Review__c.Opportunity__c}&Product={!Annual_Review__c.Product__c}&OppOwnerState={!$User.State}
//window.location.reload();
}
 

Please mark it as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan