You need to sign in to do that
Don't have an account?
Skeeter
Trigger to not fire if lookup field is null
I need to update my trigger to not fire if the Staff__c lookup field on the escalated ticket is not null. I wasn't sure where to include
Staff__c != null
I tried at this line but it didn't work.
if(mapOfTicket.get(n.ParentId).client__c == n.OwnerId){
Staff__c != null
I tried at this line but it didn't work.
if(mapOfTicket.get(n.ParentId).client__c == n.OwnerId){
trigger NoteAI on Note (after insert) { //Collect all ParentIds into a set Set<Id>incIds = new Set<Id>(); for(Note n : trigger.New){ if(n.ParentId.getSobjectType() == EscalatedTicket__c.SobjectType){ incIds.add(n.ParentId); } } Map<Id,EscalatedTicket__c> mapOfTicket = new Map<Id,EscalatedTicket__c>([select Id,client__c , ClientUpdated__c from EscalatedTicket__c where id in:incIds]); Boolean updateValues = false; for(Note n : trigger.new){ if(mapOfTicket.ContainsKey(n.ParentId)){ if(mapOfTicket.get(n.ParentId).client__c == n.OwnerId){ mapOfTicket.get(n.ParentId).ClientUpdated__c = true; updateValues = true; } } } if(updateValues){ update mapOfTicket.values(); } }
If i understand, you need add Staff__c field to your query, and add this condoition in loop
Please see code below and i recomended avoid updatating not needed records(line 25). You update map of all records. You can create list, that contains only records that need to changed.
see code below
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
All Answers
If i understand, you need add Staff__c field to your query, and add this condoition in loop
Please see code below and i recomended avoid updatating not needed records(line 25). You update map of all records. You can create list, that contains only records that need to changed.
see code below
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex