1

I have one custom field on opportunity as ABC__c it is a picklist field and contains value a,b,c,d,e my requirement is depending upon ABC__C field StageName standard field on opportunity should be updated values for StageName is f,g since it a standard field so cannot be dependant picklist.

mapping between ABC__c and StageName looks like:

ABC__c      StageName

a              f
b              f
c              f
d              g
e              g

To achieve this I wrote method in trigger handler class for before insert and update:

public static void StageFieldUpdate(boolean isBefore,boolean isInsert,boolean isUpdate,List<Opportunity> newOppList){

 for(opportunity opp : newOppList){
        if(opp.ABC__c == 'a' || opp.ABC__c == 'b' || opp.ABC__c =='c')
            opp.StageName = 'f';
        if(opp.ABC__c == 'd' || opp.ABC__c == 'e')
            opp.StageName = 'g';
      }
 }

But I have hardcoded the values, but don't want to hardcode them. Can I use custom setting in this scenario if yes then how, please help me in this?

1

Yes you could use a custom setting. Or another custom object, though settings are nice because they can be easy retrieved without the hassle of DML.

One way to do it would be to create a setting that is just one text field. That field then would have the mapping in it, and then you would parse each setting to split that field into the different pick list values. So the field could be like a:f and I. Your code you would split on the : giving you a list of strings.

  • 1
    and, if you make the custom setting value a JSON string, you can read and deserialize into a map in one apex statement – cropredy Aug 2 '14 at 19: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.