Show dynamic VisualForce page based on a field value in Salesforce.

  • In order to achieve the requirement, create a custom button and set the Behavior picklist to option ‘Execute JavaScript’ and Content Source picklist to ‘OnClick JavaScript’.
  • Add the below lines of code in Custom button Editor Text page:

  • Here, I am showing the custom VF page based on the values present in RecordType.
if('{!Position__c.RecordType}'=="Developer")
{
  var url='/apex/ApplicationTemplate';
  window.open(url, '_self');
}
else if('{!Position__c.RecordType}'=="Sr.Developer")
{
  var url='/apex/Template2';
  window.open(url, '_self');
}
  • We can pass the parameters as well, then the below code will look like below:
var url='/apex/Template2?id={!Account.Id}';
window.open(url, '_self');
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s