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
skiptomylou11skiptomylou11 

Trigger a VF page to popup based on picklist selection

Hi there,

 

On opportunities I want to use a picklist field ('Stage') to trigger opening a VF page if a certain value in selected (i.e. Project Lost).

 

I have already created the VF page (which includes some addtional input fields like who is the winning competitor) but my issue is how can I trigger the VF page to appear / pop-up once 'Project Lost' is selected in the 'stage' field.

 

I assume I'd have to use Java for this but I have no / not much experience with it.

 

Does anyone has some sample code or can point me in the right direction?

Help is highly appreciated...

Many thanks!!! 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,


We cannot perform any JavaScript event like onlick, onchange on the standard object page .You can insert a page in VF page section and by using the JavaScript AJAX check the value of pick list if the pick list value will be according to your condition then open the new page .


For Example


I have tried the Example on the Account object
Create a Vf page with following code


<apex:page standardController="account" >
<script src="/soap/ajax/22.0/connection.js"></script>
<script src="/soap/ajax/22.0/apex.js"></script>
<script>
var arrId = '{!$CurrentPage.parameters.id}';
var queryresult = sforce.connection.query("Select Rating from account where id='"+arrId+"'");
var records = queryresult.getArray("records");

if(records[0].Active__c=='Warm')
{
window.open('/apex/searchcontact');
}


</script>

</apex:page>

 

Add above Page on Account page layout


Replace searchcontact with your page name which you want to open in window.open('/apex/searchcontact');

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

All Answers

Andy BoettcherAndy Boettcher

You can't modify any of those controls on a Standard SF page layout - but you could make this happen if your page was VF.  I'd use jQueryUI's modal popup and some Javascript to make it happen.

 

-Andy

mmrrmmrr

Hi,

 

Did you get any solution on that, as I have the same kind of requirement.

Please let me know if you had solved it.

raseshtcsraseshtcs

You can use onchange in the apex:actionsupport tag to call a javascript function written in the VF page which would allow you to redirect the user to another page or open a new page.

 

Can I know the exact requirement for which you need to do this...

mmrrmmrr

When the user changes the opportunity stage to a particular value, he should not be allowed to save the record without entering some mandatory fields which are in a visualforce page - the reason to be in visualforce page is that it also contains the related object fields. So how will the user be redirected to this page while changing the value? any ideas...

Navatar_DbSupNavatar_DbSup

Hi,


We cannot perform any JavaScript event like onlick, onchange on the standard object page .You can insert a page in VF page section and by using the JavaScript AJAX check the value of pick list if the pick list value will be according to your condition then open the new page .


For Example


I have tried the Example on the Account object
Create a Vf page with following code


<apex:page standardController="account" >
<script src="/soap/ajax/22.0/connection.js"></script>
<script src="/soap/ajax/22.0/apex.js"></script>
<script>
var arrId = '{!$CurrentPage.parameters.id}';
var queryresult = sforce.connection.query("Select Rating from account where id='"+arrId+"'");
var records = queryresult.getArray("records");

if(records[0].Active__c=='Warm')
{
window.open('/apex/searchcontact');
}


</script>

</apex:page>

 

Add above Page on Account page layout


Replace searchcontact with your page name which you want to open in window.open('/apex/searchcontact');

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

This was selected as the best answer
raseshtcsraseshtcs

I have a doubt with the possible solution. What will happen in case the user saved the changes in the pop VF page(related object) and did not save the opportunity. There will be bad data in the system.

mmrrmmrr

It works perfectly!!!! Thank you so much....

my vf page is with standard controller - opportunity and the related object fields are few of them which has to be taken care for updation.  (let me know how to mark your reply as solved).

mmrrmmrr

I just added one more condition to the query, now it does not work, I dont understand whats the issue, can you please help me..

 

<apex:page standardController="opportunity" >
<script src="/soap/ajax/22.0/connection.js"></script>
<script src="/soap/ajax/22.0/apex.js"></script>
<script>
var arrId = '{!$CurrentPage.parameters.id}';
var queryresult = sforce.connection.query("Select StageName, updated__c from Opportunity where id='"+arrId+"'");
var records = queryresult.getArray("records");
if(records[0].StageName=='Closed Sold - WRAP' && record[0].updated__c==false )
{
<!---window.open('/apex/popup1?id='+arrId);--->
window.open('/apex/popup1?id='+arrId ,'lookup','width=800,height=480,scrollbars=yes,left=200,top=100');
}

</script>

</apex:page>

mmrrmmrr

updated__c is a checkbox