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
JavagalJavagal 

Text field get the value from custom setting trigger

Hi i am trying to write a trigger .

i have 1 Custom object and a Custom settings object.

i have a picklist field on custom object ( Description)  and a text field. on custom  setting i have code, description2 , column. if some one selected a picklist value in the desciption  i have to look in custom setting and populate the Code value in a text filed. i tried something. but not got enough solution any help will be appriciated.  i am sorry if i wrote my code in a not a good way.

trigger UpdateCode on Order_Note__c (before insert, before update) {

ServiceMax_Codes__c settings = ServiceMax_Codes__c.getInstance();
String  CT_CODE = settings.CT_CODE__c;
String  CT_DESCRIPTION = settings.CT_DESCRIPTION__c;
Set<String> NextActionSet = new Set<String>();
Map<String,Id> mapnextActionwithCode = new Map<String,Id>();

//List<ServiceMax_Codes__c> SMC= ServiceMax_Codes__c.getall().values();
String NAL = [SELECT CT_CODE__c FROM ServiceMax_Codes__c WHERE CT_DESCRIPTION__c IN ];
//Next_Action_New__cis a picklist value on custon object.
for (Order_Note__c obj: trigger.new){
        if(!String.isBlank(obj.Next_Action_New__c)){
          NextActionSet.add(obj.Next_Action_New__c);
          obj.Next_Action_Code__c = NAL ;
        }

 
Andy BoettcherAndy Boettcher
Are the values you're storing in the Custom Setting too big to just be a part of a Formula Field?
JavagalJavagal
Yes i have lot of Values.. so i have to get from Custom setting!!
Andy BoettcherAndy Boettcher
Actually I'd populate your map as a Map<String, String> based on the ServiceMax_Codes__c custom setting object - so in your trigger you can just reference that map with the value from trigger.new and plop the value in whatever field you want to fill.