• Zhixun
  • NEWBIE
  • 24 Points
  • Member since 2010


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
trigger NAICSUpdate on Account (before insert, before update) {
List<NAICS_Code__c> codes = [SELECT Name, Description__c from NAICS_CODE__C];
Set<NAICS_CODE__C> setcodes = new set <NaICS_code__c>();
setcodes.addAll(codes);    
for (Account acct :Trigger.new)
 {
   if(acct.NaicsCode != NULL)
   {
       try {
     string twoDigit =  acct.NaicsCode.left(2);
     string threeDigit =  acct.NaicsCode.left(3);
     NAICS_Code__c nCode2desc = [SELECT Name, Description__c from NAICS_CODE__C where Name = :twoDigit limit 1]; 
     NAICS_Code__c nCode3desc = [SELECT Name, Description__c from NAICS_CODE__C where Name = :threeDigit limit 1]; 
     acct.NAICS_2_Digit_Desc__c = nCode2desc.Description__c;
     acct.NAICS_3_Digit_Desc__c = nCode3desc.Description__c;           
}
       catch (Exception e) {
           system.debug('Failed');
       }
   }
       
     
     
 }
}

I'm trying to remove the two queries in the for loop. I can't use a map since I'm searching by name and not ID. I'm not really sure how to utilize set to return the right description if I use contains. Any help would greatly be appreciated.
 
Now I have a `Matter__c` object that has a custom field called `Project_Name__c` which is a lookup to `Opportunity`. Now that `Opportunity` has a custom field called `RVM_Committed_Spend__c`. Now what I want to happen is to get the value of `RVM_Committed_Spend__c` and transfer it to the the newly created custom field in `Matter__c` called `RVM_Commited_Spend_Matter__c`

This is the only part I need so that I can finish my before Insert/before Update Trigger. Thank you in advance. Hoping you can answer my question.
hi all. 
I need to do a select 28 records fields(picklist) from the custom object "caseCustom__c" and insert those records in GC_R_Filtro_Text__c field from case object.

I can do the select of case object, but I can´t insert in it  picklist records from Casecustom__c

 could you help me ?

this  is  my script :


trigger caseCustomAfterInsert on CaseCustom__c (after Insert) {
   
   List<case> listcases = new List<case>();
   map<id, CaseCustom__c > mapcasecustom = new map<id, CaseCustom__c>();
   
   for(CaseCustom__c cc:trigger.new){
       mapcasecustom.put(cc.textCaseId__c,cc);
   }
   
   if(mapcasecustom != null && mapcasecustom.size() > 0){
       for(case cs :[select id, survey_status__c,GC_R_Filtro_Text__c from case where id in :mapcasecustom.keyset()])
       
       {
         cs.GC_R_Filtro_Text__c = String.valueof(mapcasecustom.get(cs.id).CCAnswerFiltro1__c) != null?                  String.valueof(mapcasecustom.get(cs.id).CCAnswerFiltro1__c):'';
cs.GC_R_Filtro_Text__c = String.valueof(mapcasecustom.get(cs.id).CCAnswerFiltro2__c) != null?                  String.valueof(mapcasecustom.get(cs.id).CCAnswerFiltro2__c):'';
cs.GC_R_Filtro_Text__c = String.valueof(mapcasecustom.get(cs.id).CCAnswerFiltro3__c) != null?                  String.valueof(mapcasecustom.get(cs.id).CCAnswerFiltro3__c):'';
          cs.survey_status__c = 'Aplicado';
          listcases.add(cs);
       }
    }
   system.debug('---'+listcases);
   if(listcases != null && listcases.size() > 0)
      update listcases;
}
trigger NAICSUpdate on Account (before insert, before update) {
List<NAICS_Code__c> codes = [SELECT Name, Description__c from NAICS_CODE__C];
Set<NAICS_CODE__C> setcodes = new set <NaICS_code__c>();
setcodes.addAll(codes);    
for (Account acct :Trigger.new)
 {
   if(acct.NaicsCode != NULL)
   {
       try {
     string twoDigit =  acct.NaicsCode.left(2);
     string threeDigit =  acct.NaicsCode.left(3);
     NAICS_Code__c nCode2desc = [SELECT Name, Description__c from NAICS_CODE__C where Name = :twoDigit limit 1]; 
     NAICS_Code__c nCode3desc = [SELECT Name, Description__c from NAICS_CODE__C where Name = :threeDigit limit 1]; 
     acct.NAICS_2_Digit_Desc__c = nCode2desc.Description__c;
     acct.NAICS_3_Digit_Desc__c = nCode3desc.Description__c;           
}
       catch (Exception e) {
           system.debug('Failed');
       }
   }
       
     
     
 }
}

I'm trying to remove the two queries in the for loop. I can't use a map since I'm searching by name and not ID. I'm not really sure how to utilize set to return the right description if I use contains. Any help would greatly be appreciated.