You need to sign in to do that
Don't have an account?
Kiransssssssssssssssssss
Before Trigger is not updating record
I want to capture the Territory Ids the user is assigned to. I wrote the trigger and the logs show the value that i am expecting, but the record is not getting updated. Could you suggest me please?
trigger preventTerritoryAssignmentDeletion on User (before update) { Set<Id> userIds = new Set<Id>(); List<User> UT2List = new List<User>(); for(User u : Trigger.New){ if(u.Resource_ID__c == 'testresourceid'){ //u.Territory_Backup_IDs__c = 'workinig'; userIds.add(u.Id); } } UT2List = [SELECT ID,Territory_Backup_IDs__c, (SELECT ID,Territory2Id FROM UserTerritory2Associations) FROM User WHERE Id IN :userIds]; for(User u : UT2List){ string terrString =','; for(UserTerritory2Association ut2a : u.UserTerritory2Associations){ terrString = terrString + ut2a.Territory2Id +','; system.debug('terrString inside inner for loop'+terrString); } system.debug('terrString in out for loop'+terrString); system.debug('u.Territory_Backup_IDs__c'+ u.Territory_Backup_IDs__c); u.Territory_Backup_IDs__c =u.Territory_Backup_IDs__c+ terrString; system.debug('u.Territory_Backup_IDs__c'+ u.Territory_Backup_IDs__c); } }Thank you in advance!
To each Territory you assign users or groups. So if you want to remove a user from a Territory you do it through configuration or trigger. But removal will be taken care either by Salesforce if user is deactivated or manually removed from the Territory. So what is the use case you are thinking of that Territory is being lost?
Can any one help me on this please..
I have finished the requirement. And I got a hint of what might have gone wrong here. IF any one can help me it would be great. With your thoughts