You need to sign in to do that
Don't have an account?
Justin George
Bulkify Trigger to Update Owner
I have written a trigger that updates the owner field to a queue on a custom object. The queue is selected based on fields on a related object. The logic is as follows:
- The trigger must traverse through a lookup and return the value of a field on the lookup object:
- The Claim__c owner field should then be updated to '1234AB'
Here is the working trigger:
The issue is the trigger is not bulkified. I have attempted to bulkify the trigger, but I got lost is the logic and I could not find a similar piece of sample code to reference. Can someone point me in the right direction or give me some guidance.
Thanks
- The trigger must traverse through a lookup and return the value of a field on the lookup object:
Claim__c.Location_Lookup__r.Node__c = '1234'
- Trigger must also reference a field on the object:
Claim__c.Coverage__c = 'AB'
- Trigger should concatenate '1234AB' and return a queue with the same name (1234AB).- The Claim__c owner field should then be updated to '1234AB'
Here is the working trigger:
trigger ReassignOwnerClaim on Claim__c (before insert, before update) { for(claim__c newClaim : Trigger.new){ Hierarchy__c location = [Select Node__c from Hierarchy__c where ID =: newClaim.Location_Lookup__c LIMIT 1]; Group[] queue = [Select Id, Name from Group where Name =: location.Node__c + newClaim.Coverage__c LIMIT 1]; if (queue.size() > 0) { newClaim.OwnerId = queue[0].Id; } } }
The issue is the trigger is not bulkified. I have attempted to bulkify the trigger, but I got lost is the logic and I could not find a similar piece of sample code to reference. Can someone point me in the right direction or give me some guidance.
Thanks
NOTE: This code has not been tested and may contain typographical or logical errors
All Answers
NOTE: This code has not been tested and may contain typographical or logical errors