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
sandeshdsandeshd 

Alert message when I change stage on an opportunity

Hi

 

I need a popup to be displayed when user changes the opportunity stage to a proposal stage and when he saves the page.  I am using standard controller.  If not direct approach do we have any alternative approach  using triggers or some thing like that. We have around 500 fields on that opportunity object. 

 

Please suggest.

 

 

 

 

sfdcfoxsfdcfox

There's no built-in mechanism for this right now. You'd have to write a custom edit page. There's no convenient way to replicate a standard edit page and add functionality.

sandeshdsandeshd

Thank you but do I need to create a custom details page or edit page and there are around 500 fields on that oppty object. So isnt it a complex one. Any further suggestions on it

sfdcfoxsfdcfox

You could use dynamic visualforce binding to minimize the amount of code you need to use. It would look like this:

 

<apex:page standardController="Opportunity" extensions="OppExtension">
  <apex:form>
    <apex:sectionHeader title="{!pageTitle}" subtitle="{!subPageTitle}"/>
    <apex:pageBlock title="Edit">
       <apex:repeat value="{!fields}" var="field">
         <apex:inputField value="{!Opportunity[field]}"/>
       </apex:repeat>
       <apex:pageBlockButtons>
         <apex:commandButton onclick="..." action="{!save}" value="Save"/>
         <apex:commandLink action="{!cancel}" value="Cancel"/>
       </apex:pageBlockButtons>
    </apex:pageBlock>
  </apex:form>
</apex:page>

{!fields} would be a Set<String> or List<String>.

 

There's also the new "Visualforce in Apex Code" bit that's coming out soon. That could also help you make the pages faster. However, ultimately you'd have to decide if it's worth it (and most likely, it is not). It'd be hours of work to implement a single new feature in a workaround method.

goabhigogoabhigo

Try this work around:

Create a VF page with following code:

<apex:page standardController="Opportunity" rendered="{!Opportunity.StageName == 'Proposal'}">
 <script type="text/javascript">
  { window.alert("Your message here"); }
 </script>
</apex:page>

 Go to opportunity and edit opportunity page layout. Drag this new visualforce page on page layout. Edit the visualforce page properties and set Height as 0 pixel. (We don't need to show this page to users.) Save the page layout.

 

Let me know if you have any doubts.

sandeshdsandeshd

Thanks Abhi,

Sorry for the delay .

It solved my problem to 80% but I need alert  to be displayed only for the first time the user changes the stage to proposal and saves it. I tried creating a checkbox and made it to false after the first save on the proposal. In the rendered part I also added the condition to check if that check box is true  along with the condition for opportunity stage. and I am using trigger to update that field once opportunity is saved by using  before update trigger but the problem is before the alert message gets displayed the checkbox is getting updated to false and the rendered condition is  not satisfied and I am not able to see pop up even for the first time.  I tried updating that field in after update trigger but it gives me error saying that I will be able to read only and  I will not be able to do update the field  in after update.

any sggestions on this...

goabhigogoabhigo

You can make use of workflow field update to do this. In the criteria use: ISCHANGED(StageName) && ISPICKVAL(StageName,'Proposal') && Checkbox__c <> true

In the field update, make the checkbox true.

 

Now in the VF page, use the rendered to stop displaying alert everytime.

sandeshdsandeshd

Hi Abhi,

 

even workflow update is also getting executed before popup getting displayed . SO alert message is not gettting displayed.

Ankush SamudralaAnkush Samudrala
Hi sandeshd,

We can show the alert or confirm box while changing the stage picklist val on Opportunity edit layout.
We can achive this via home page component.please find the code below as i dislaying the alert while i changed the Rating picklist vaue on Account edit layout.

<script src="/soap/ajax/28.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/28.0/apex.js" type="text/javascript"></script>
<script src="https://eu2.salesforce.com/resource/1394801498000/jqueryFile" type="text/javascript"></script>
<script type="text/javascript">
    var temoppid;     
  $(document).ready( function()       
   {           
        var test = window.top.location.pathname.substring(1,4);
        if(test != null & test !='' && test =='001')  //For account checkup
         {
           if(document.getElementById('acc9') != null)//Getting Rating picklist id from edit layout.(By inspecting the element)
            {
               $('#acc9').on('change', function() {//Onchange event
                 alert('==Hi u are ===>>'+this.value ); 
               });
            }
         }
                                                 
    });
</script>

I hope it will helps you.
Thnak you.

Ankush Rao
+91-9959635957