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
chikkuchikku 

How to get data picklist values with trigger?

I have picklist field name is Type__c and in that values are Disbursal and payment, where Disbursal=1000 & Payment is =5000.
My requirement is when I choose disbursal I need a trigger and show the values of disbursal of 1000 and the same as payment need to show if I chose a payment.
This code of trigger.
trigger TransactionAct on Loan_Transaction__c (after insert) {
    List<Timeline_Event__c> timelineList=new List<Timeline_Event__c>();
    TimelineEventController tobj=new TimelineEventController();
    ITimelineEventController timeAssignCtrl=new TimelineEventController();
    IController conCtrl=new contactController();
    
  	for( Loan_Transaction__c trans :Trigger.New){
        Timeline_Event__c tEvent=new Timeline_Event__c();
               string rtype='', subtitle='';
        
        if( Trigger.isAfter){
                sObject c=conCtrl.getById(trans.Loan__c);

            if(trans.Type__c=='Disbursal'){
                subtitle=rtype+'Disbursal of';
  tEvent=(Timeline_Event__c)timeAssignCtrl.timelineTrigger(trans ,'trans Disbural',subtitle,'insert','trans' );
         timelineList.add(tEvent);
            }    
            else if(trans.Type__c=='Payment'){
                 subtitle=rtype+'Payment of';
                 tEvent=(Timeline_Event__c)timeAssignCtrl.timelineTrigger(trans,'trans Payment','',subtitle,'insert','tarns'  );
                 timelineList.add(tEvent);
            }
            
            
        }
 
          }
   tobj.createMany(timelineList);  

}

 
chikkuchikku
Actually this code already I have written in the code above in question. I need to get values stored in picklist values disbursal=1000 OR payment=5000 when they updated the picklist in the object  Loan_Transaction__c.
David Zhu 🔥David Zhu 🔥
You may use the following method to get the keyvalue pair.
 getPickistKeyValuePair(Loan_Transaction__c,'Type__c');

public static map<string,string> getPicklistKeyValuePair(SObject objName, String fieldName) {
  Map<String,String> result = new Map<String,String>();
  Schema.sObjectType objType = objName.getSObjectType(); 

  Schema.DescribeSObjectResult objDescribe = objType.getDescribe();       

  list<Schema.PicklistEntry> values = objDescribe.fields.getMap().get(fieldName).getDescribe().getPickListValues();

  for (Schema.PicklistEntry a : values) { 
     result.put(a.getValue(),a.getLabel());
  }
  
  return result;
}