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
anchoviesanchovies 

Self-dependent picklist

Hi all,

 

What's the best approach to create a self-dependent picklist?

 

What I'm trying to do is to restrict values available for selection based on the current picklist value. E.g. if an opportunity stage is 'Negotiation' it can't go back to 'Prospecting'.

 

Thanks in advance

Carolina Ruiz MedinaCarolina Ruiz Medina
Hi Anchovies, ( I like the nick name :-) ) 

I think what you need is a Dependent picklist. 
The first thing that you will need is to create the new picklist that will be depented on Stage picklist, after you can click in the Opportunities field depencies, select the controlling field( in you case Stage picklist) select the Dependent field (in you case the new picklist that will contain 'Negotiation')  and just after set the matrix of values that you woul like to be abailable dependent on the Stage value.

Might be this link will help :http://help.salesforce.com/HTViewHelpDoc?id=fields_defining_field_dependencies.htm&language=en_US

Hope the info helps.

Kind Regards,
Carolina.

MagulanDuraipandianMagulanDuraipandian
You can check this condition in trigger. Salesforce doesn't support self dependent.

If this solves your problem, kindly mark it as the best answer.

Regards,
Magulan
http://www.infallibletechie.com
Carolina Ruiz MedinaCarolina Ruiz Medina
Hi Anchovies,
Sorry, I misunderstood totally the question, just realised when read Magu answer.

As Magu just said, to do that you will need to use a trigger. ( However I would do slightly different that in infallible techie).

You will need to create a trigger on Opportunity Object ( be careful when creating triggers in standards objects because if something goes wrong we could stop the user to create, update or delete opportunities)


Then the trigger will check in after update ( or in after insert if you also would like to check the status that the opportunity is created with) . Attached here is some example code that could help:


trigger OpportunityTrigger on Opportunity (before insert, after insert, before update, after Update) {
   
     // after update
     if(! Trigger.isBefore && Trigger.isUpdate)
     {
          //Trigger.new, Trigger.oldMap
          Map<Id, SObject> oldOpportunities = Trigger.oldMap;
          for(Opportunity opp: Trigger.new)
          {
                Opportunity oldOpp  = (Opportunity)oldOpportunities.get(opp.Id);
                if(opp.StageName == 'Prospecting' && oldOpp.Stagename== 'Negotiation' )
                {
                     throw new AppException('This change is not allowed');
                }
          }


     }

}


Remember when implementing Triggers to bulkify. Also here I would like to attach a link to some apex patters that  might be help you when implementing:https://github.com/financialforcedev/fflib-apex-common


Hope it helps ( at least more than before, that I misunderstood the question  :P)
Kind Regards,
Carolina.
anchoviesanchovies
Thank you Magu and Carolina! I was hoping to avoid using triggers but it looks like I'll have to =)