You need to sign in to do that
Don't have an account?
jojo5
OR statement in triggers
I entered a contact in the Name and Attendees field and now I want to be able to make sure that if I deleted a Contact from the name field it gets removed from the Invitees field and vise versa. To make this happen, I did an IF statement to check if the value of isParent == false OR isInvitee == false. This works for the isParent == false, but it doesn't seem to catch it if the isInvitee == false. Can anyone help me on why 'OR' is not working and have any suggestions on how to make this work? Thanks.
if (trigger.isUpdate){ List<EventRelation> erLst = [SELECT EventId, RelationId, isParent, isInvitee FROM EventRelation where EventId IN :sEvents ]; for(EventRelation sObj: erLst ){ if (sObj.IsParent == false || sObj.IsInvitee == false ){ delete sObj; } else{ sObj.IsParent = true; sObj.IsInvitee = true; UpdatedLst.add(sObj); update UpdatedLst; } } }
if (trigger.isUpdate){ List<EventRelation> erLst = [SELECT EventId, RelationId, isParent, isInvitee FROM EventRelation where EventId IN :sEvents ]; for(EventRelation sObj: erLst ){ if (sObj.IsParent == false || sObj.IsInvitee == false ){ delete sObj; } else{ sObj.IsParent = true; sObj.IsInvitee = true; UpdatedLst.add(sObj); update UpdatedLst; } } }
In OR statement, either of the condition is TRUE then it gets executed.
For example, if your are checking '(isParent == false OR isInvitee == false'), then let's say if isParent' value is actually FALSE , then condition returns TRUE, then isInvitee==false is not going to execute.
isInvitee == false is going to execute only if ('isParent == false' ) condition returns FALSE.
Also, if you want to make both condition to check then try with AND operator.
Share your thoughts!
Thanks,
Sucharita
All Answers
In OR statement, either of the condition is TRUE then it gets executed.
For example, if your are checking '(isParent == false OR isInvitee == false'), then let's say if isParent' value is actually FALSE , then condition returns TRUE, then isInvitee==false is not going to execute.
isInvitee == false is going to execute only if ('isParent == false' ) condition returns FALSE.
Also, if you want to make both condition to check then try with AND operator.
Share your thoughts!
Thanks,
Sucharita
Glad that it'll helped you. Please mark this answer as correct, so it can help other users also.
Thanks,
Sucharita