I have an embedded VF page on the Opportunity page layout. When the Stage on an Opportunity reaches a particular stage, a workflow rule fires to update a checkbox field (Stage_To-Contract__c) as TRUE. The code in my embedded VF page below is then meant to check to see if that field is true, the StageName is set to a particular stage, and another custom field is set to "No". If all those events occur, a new VF page is opened and the Stage_To_Contract__c field is marked as false. The issue I am having is that the new VF page that opens is opening twice. Does anyone know why this may be occurring? I do think there is 1 or more before triggers on the Opp that are firing once before this page is called and then after, I just don't know if it's possible to prevent that in the page or if I have to prevent it in the trigger(s).

Embedded VF Page:

<apex:page standardController="Opportunity">
    <apex:includeScript value="/soap/ajax/34.0/connection.js" />
    <script type="text/javascript">
        var SFInitial = new Object();

        SFInitial.openWizard = function(){
                "{!Opportunity.StageName}" === "{!$Label.Eng_OppStage4}" &&
                "{!Opportunity.Includes_Guarantee__c}" == "No" &&

            return this;

        SFInitial.updateOpportunity = function(){
            sforce.connection.sessionId = "{!GETSESSIONID()}";

            var oppToUpdate = new sforce.SObject("Opportunity");
            oppToUpdate.Id = "{!Opportunity.Id}";
            oppToUpdate.Stage_To_Contract__c = false;


            return this;



  • Can you just disable trigger of opportunity in order to check if this is really because of trigger. Becuase I don't think this is because of trigger. Nov 23 '15 at 18:11
  • Thanks Kiran. I did disable the trigger and my VF page opened only once, so the double opening is definitely as a result of the trigger being fired a second time.
    – J. Neilan
    Nov 23 '15 at 18:33
  • Is VFShortFormInit page opening twice? Nov 23 '15 at 18:49
  • Yes, that's the one. It's duplicating the open, I think because the JavaScript fires, updates the Opp, which then fires the trigger again causing the JavaScript to fire a 2nd time.
    – J. Neilan
    Nov 23 '15 at 19:22

For anyone interested, I found a workaround for this issue. I replaced "_blank" in my window.open statement with "newWindow" as a page name and now only one window opens.

  • I tried reproducing this and created a workflow to bring back the value of field to true. But in my case only one page was getting opened. But yes thanks for sharing workaround will keep this in mind. Nov 24 '15 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.