+ Start a Discussion
GYAN ANDRUSGYAN ANDRUS 

Hi Anyone please help for this trigger

trigger ColorCodes on PBSI__PBSI_Item__c (after insert,after update) {
    
 Set<string> aliasscope = new Set<String>();  
   
 List<Item_Master_Color__c> mo = Item_Master_Color__c.getall().values();
 system.debug('ItemTransDataLIST ------->'+mo);
    
    for (PBSI__PBSI_Item__c  itemCod : Trigger.new) {
    aliasscope.add(itemCod.Color__c);

    }
    
    
}

I have created the custom Settings(list) called Item_Master_Color__c,I have name and Color Code fileds in Item_Master_Color__c(Custom settings).I want to update the the custom Setting color code dynamically in (-Item_Color_Code__c)Custom field in  PBSI__PBSI_Item__c object,If i insering and updating the record in PBSI__PBSI_Item__c object,I want to automatically update the  custom Setting COlor Code

In Custom Setting i have a  name -PINK
                                        color_Code-789
 
Yury BondarauYury Bondarau
Hi Gyan,

You need to call (insert/update/upsert) DML operation for changing value in custom settings after you set desired code.
For instance in the end of trigger put something like
mo[0].ColorCode__c = 'whatever you want';
update mo;

 
GYAN ANDRUSGYAN ANDRUS
Can you please tell,Where to put this,Its not updating


trigger ColorCodes on PBSI__PBSI_Item__c (after insert,after update) {
    
 Set<string> aliasscope = new Set<String>();  
   
    Map<string,Item_Master_Color__c> mapCodes = Item_Master_Color__c.getAll();
    mapCodes.containsKey(Color_Code__c);
 system.debug('ItemTransDataLIST ------->'+mapCodes);
  String  colorName;
  String  colorCode;
    
  for (PBSI__PBSI_Item__c  itemCod : Trigger.new) {
 

    }
    
    
}

 
Prem Anandh 1Prem Anandh 1
Hi Gyan,

Please try below code. Instead of PINK you should pass your PBSI__PBSI_Item__c  field API name which is contains color name. 
for (PBSI__PBSI_Item__c  itemCod : Trigger.new) { 
      itemCod.Item_Color_Code__c = mapCodes.get('PINK');
    }