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

Change Query Owner using After Update Trigger
Hi All,
Need some help please.
I have created a trigger which should update the OwnerId on Case object using UserId from field Back_Up__c On Case object.
But i cant get this to work. Yet i get no error messages. Any help would be most appreciated.
trigger CaseOutofOffice on Case (after update) {
If (Trigger.isAfter){
List<Case> Cases = new List<Case>();
for (Case c : cases) {
If (c.Status != 'Closed' && (c.Back_Up__c!=null || c.Back_Up__c!='')){
c.OwnerId = c.Back_Up__c;
c.IsBackUp__c = True;
}
Update c;
}}}
Need some help please.
I have created a trigger which should update the OwnerId on Case object using UserId from field Back_Up__c On Case object.
But i cant get this to work. Yet i get no error messages. Any help would be most appreciated.
trigger CaseOutofOffice on Case (after update) {
If (Trigger.isAfter){
List<Case> Cases = new List<Case>();
for (Case c : cases) {
If (c.Status != 'Closed' && (c.Back_Up__c!=null || c.Back_Up__c!='')){
c.OwnerId = c.Back_Up__c;
c.IsBackUp__c = True;
}
Update c;
}}}
Try with below code as trigger.new record is always read only so you can not update trigger.new records .You need to query with the relared id from daabase .
Let me know any issue .
Thanks
Mnaoj
All Answers
Try with below code as trigger.new record is always read only so you can not update trigger.new records .You need to query with the relared id from daabase .
Let me know any issue .
Thanks
Mnaoj
Thast perffect! You Legend :-)
Thanks you so much. i can ask last question plz? if i wanted to simplify this by only displayign an error message (adderror) rather than change the ownerId would i use the same code as above or would this require significant changes?
You need to change the trigger for sure ,If you want to display error message ,then first you need to change the event to before from after .
Second no need to update the record .
I think below code is enough please have a try .
Let me know any issue .
Thanks
Manoj
This did not work. The trigger is firing everytime, even when the Back_Up__c is BLANK or NULL.
What exactly you want ,when to throw the error ? According to the trigger it will trrow you error when case =close and backup is null .
Please clarify.
Thnaks
Manoj
I have created a custom field called "Back_Up__c" on the User Object. I have then created a custom field called "Back_Up__c" on the Case Object also.
If a user is out of the office they must then populate the custom field "Back_Up__c" in the User Object. Therefore, if a User then tries to assign a Case to a User which has Out of Office then the trigger should fire and erro rmessage should be adderror('Please assign Case to Back_Up__c (i.e.John Smith etc). But the problem im having is that the trigger is firing even when the User is NOT (= BLANK or NULL ) out of the office. Instead error message is displayed 'Please assign Case to null'. I think my Back_Up__c field on the Case object is not being populated in time, when changing the owner..