Current functionality when Opportunity stage moved from discovery to Bid quote , suppose in discovery if user manually enter 5% Probability when stage changed to bid quote it is showing 0 and if user manually enrter 70% Probability in bid quote and change it to some other stage it will change to 0 Probability but when stage changed to closed won it will change to 95%. We want if probability is edited by sales then it should move that value to next stage other wise it should move default value and we should always give user capability to change probability. Please let me know the solution if anyone know.

Thank you very much inadvance


As this Help article says, you can't disable the built-in functionality of setting Probability to the Stage's Default Probability value when you change the Stage.

You would need to write a custom trigger to override that functionality, by comparing the old Opportunity.Probability value to the previous OpportunityStage's DefaultProbability value. If they are different, then you assume that the Probability was manually set and put back the old value. The new value would still show when changing the stage using the standard page layout, unfortunately, but the end result would be what you're looking for.

Something like this:

trigger CustomProbabilityReset on Opportunity (before update) {
    String oldStage;
    Decimal oldProb;

    //get the StageNames and default percentages into a Map
    Map<String,Decimal> defaultProbabilities = new Map<String,Decimal>();

    for (OpportunityStage s : [SELECT ApiName, DefaultProbability 
                         FROM OpportunityStage
                         WHERE IsActive = TRUE] ) {

    for (Opportunity o : Trigger.new) {
        oldStage = Trigger.oldMap.get(o.Id).StageName;
        oldProb =  Trigger.oldMap.get(o.Id).Probability;

        // if we're not changing the stage, no need to do anything
        if (o.StageName == oldStage) {

        // if the Opp used the default Probability before, do nothing
        if (oldProb == defaultProbabilities.get(oldStage) ) {

        // if the Opp is closing, best to use the default Probability
        if (o.IsClosed) {

        // Opp is open and had a custom probability before, so put it back
            o.Probability = oldProb;
| improve this answer | |
  • 1
    nicely commented – cropredy Jul 8 '16 at 3:21
  • Thanks for sharing the trigger, can you explain what is OpportunityStage ? and ApiName ? is ApiName - stage Api Name? can you help me with test class too ? Thank you very much for the help – sai Jul 11 '16 at 16:19
  • OpportunityStage is a standard object where Opportunity.StageName values and their attributes are stored; ApiName is a field on that object. developer.salesforce.com/docs/atlas.en-us.object_reference.meta/… – Thomas Taylor Jul 12 '16 at 1:19
  • Thanks Thomas. Will this resolved using workflow ? Please let me know – sai Jul 12 '16 at 18:19
  • HI Thomas, your code is working fine but there is any issue with the functionality. When I select stage, it will give a pop up window then I change my stage and give probability of the changed stage then it is not updating probability. again i need to give probability 2nd time and save then it is updating probability. So do you have any solution for this please help me and Thank you so much for the help – sai Jul 22 '16 at 21:53

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.