I have written a function like the one below to check if there is atleast one occurrence of a given Id in either of the two objects. I am having doubts on if I should use an if branch or use a ternary expression like this? Which is more readable?
public static Boolean isPresent(SObject object) {
if(object.Id == null) return false;
return
[SELECT count() FROM A__c WHERE Obj__c =: object.Id LIMIT 1] > 0 ? true :
[SELECT count() FROM B__c WHERE Obj__c =: object.Id LIMIT 1] > 0;
}
Obj__c
as the filter field. Is this specifically a case of wanting to check to see if any of the following objects have a populated relationship field where this record is the value in that field?object
is a value in eitherA__c
orB__c