You need to sign in to do that
Don't have an account?

Trigger works but new field value is not save???
I wrote a trigger so that when the Account Name is updated, the Subgrantee Profile (custom object, linked by look up relationship) Name is also updated.
For example: Account name is ABC, and Subgratee Profile name is 123-ABC. When the Account name is updated to EFG, Subgrantee Profile name should become 123-EFG.
I checked the debug pritn out, and all the values is as it should be, but the new name for the subgrantee profile is not being save???
trigger updateAcountNameonSubProfile on Account(after update) { for (Account a:Trigger.new) { try { //select the related Subgrantee Profile List<Subgrantee_Profile__c> lstRR=[Select r.Id,r.Name, r.Subgrantee__c from Subgrantee_Profile__c r where r.Subgrantee__c in : Trigger.newMap.keyset()]; system.debug('>>>list size: '+lstRR.size()); for(Subgrantee_Profile__c objRR : lstRR) { system.debug('>>>updating this sub profile:'+objRR.name); if(Trigger.newMap.containskey(objRR.Subgrantee__c) ) objRR.Name=Trigger.newMap.get(objRR.Subgrantee__c).Mailing_State__c + Trigger.newMap.get(objRR.Subgrantee__c).Associated_Project_Number__c+' - '+Trigger.newMap.get(objRR.Subgrantee__c).Name; system.debug('>>>New subgrantee profile name:'+objRR.Name); } update lstRR; //the new name is correct, but the record in Salesforce is not updated???? System.debug('>>>after updating list - new sub profile name: '+ lstRR.get(0).name ); }catch(Exception ex) { Trigger.new[0].addError('Error in resource request updates --'+ ex.getMessage()); } } }
You may need to use a new list for the update rather than re-using lstRR. If you do something like this does it work?