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
Anoop Patel 7Anoop Patel 7 

Open a VF page based on picklist value but only if the value is changed not each time the page is refreshed

I have created 2 VF pages, with one of them redirecting to the other VF form. The script below is the one causing me problems. This is the one that is added to the page layout and currently when saved or refreshed it fires. The apex works as expected however I only want it to fire when the value is changed. i.e from no to yes.

The requirement is to have the Marketing_Contributions VF appear only if the Partner_Agreements__c is equals 'Yes'. This code fires each time the page is refreshed.

<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 Partner_Agreements__c from account where id='"+arrId+"'");
var records = queryresult.getArray("records");
if(records[0].Partner_Agreements__c=='Yes');
var confirmflag = confirm('Do you want to add Marketing Contributions?');
if(confirmflag == true)
{
window.parent.location.href="/apex/Marketing_Contributions";
}

</script>

</apex:page>
Best Answer chosen by Anoop Patel 7
logontokartiklogontokartik
HI Anoop,
Yes it happens everytime because the users choice is not saved anywhere. if I am user and I click Yes to "Do you want to add Marketing Contributions?". You redirect, but my Yes is just for that session, when I navigate back and come again, it will ask me the same question. 


The question you ask - is it per user of per record? If its per record you can maybe add another flag that you set to true when they want to add Marketing Contributions and check that everytime if its true and immediately navigate w/o asking.


All Answers

logontokartiklogontokartik
HI Anoop,

I am not sure if I understand your requirement, 

You have an Inline Visualforce Page you added to Standard Layout? It checks for a flag on the Records and asks user to confirm? If user confirms, it navigates to the new page? Is that right?

from what you are asking, the user clicking yes, must be persisted? Is that right? From your code, it wouldnt do that and everytime the user opens the detail page it asks him to confirm. 

Let me know if my understanding is right?




Anoop Patel 7Anoop Patel 7
Hi Kartik,

Thats correct. I have added my VF page to the standard Acccount page layout and it should check if a field value has changed to 'Yes', if it does then it should navigate to the other VF page.

As you mention, it doesnt do it just on that but everytime the user opens or refeshes the page it asks to confirm.
logontokartiklogontokartik
HI Anoop,
Yes it happens everytime because the users choice is not saved anywhere. if I am user and I click Yes to "Do you want to add Marketing Contributions?". You redirect, but my Yes is just for that session, when I navigate back and come again, it will ask me the same question. 


The question you ask - is it per user of per record? If its per record you can maybe add another flag that you set to true when they want to add Marketing Contributions and check that everytime if its true and immediately navigate w/o asking.


This was selected as the best answer