2

I have an embedded Visualforce page that contains some Javascript code. The purpose of the code is to open a custom VF page once the Stage of an Opportunity reaches a certain point. I want this to occur only when the Opportunity Stage is changed to a particular stage. The problem I am running into with the code below is that the Javascript executes every time the page of that Opportunity is refreshed, as long as it remains in the particular Stage. I tried using a Workflow rule to mark a checkbox, but the WF fires before the Javascript executes, so the conditions are never met. Is there any way to get this Javascript to execute only when the Opportunity Stage is moved to Stage 4 an not just when it shows up as Stage 4? Thanks,

<apex:page standardController="Opportunity">
<script type="text/javascript">
    if("{!Opportunity.StageName}" === "{!$Label.Eng_OppStage4}"
    {
        window.open("/apex/DealSummaryInitialTestOpp?Id={!Opportunity.Id}","_blank");
    }
</script>

1
  • is this embedded vf page opening another apex page? have you disabled csrf in your org?
    – Rao
    Commented Aug 18, 2015 at 21:31

2 Answers 2

0

Why not do this in the backend in the controller? You can have a checkbox field that gets checked first and then have a page reference to a new page that only is operational when the checkbox is active. Then you can uncheck the checkbox so this doesn't keep getting fired.

0

Thanks for the suggestions. I ended up using the code below in a VF page embedded in the Opportunity and it worked for me! Thanks again!

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

    DSInitial.openWizard = function(){
        if(
            "{!Opportunity.StageName}" === "{!$Label.Eng_OppStage4}" &&
            {!Opportunity.Deal_Summary_Created__c}
        ){
            window.open(
                "/apex/DealSummaryInitialTestOpp?Id={!Opportunity.Id}",
                "_blank"
            );
        }

        return this;
    };

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

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

        sforce.connection.update([oppToUpdate]);

        return this;
    };

    DSInitial.updateOpportunity().openWizard();
</script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .