You need to sign in to do that
Don't have an account?
How to compare elements in a list?
I have a list with multiple elements associated with one name. I want to check only if the email address in the first element is empty - the others I don't care if they are blank. Here is my list:
public List<Opportunity> opportunity { get { return [SELECT Name, Ashoka_Website_Profile_Link__c, (SELECT Engagement_Role__c.Name, Engagement_Role__c.Contact__r.Email, Engagement_Role__c.Contact__r.Name, Engagement_Role__c.Contact__r.Account.Name, Engagement_Role__c.Contact__r.Id FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) FROM Opportunity WHERE Id = :oppId]; } }
Originally, I did not use a list but instead just created a new Opportunity object. My code all ran fine. I used this if-statement and for-loop after (pardon the terrible naming, it was not my doing):
if (opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email != null) { addresses = opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email; for (Integer i = 1; i < opportunity.R00NR0000000UWbWMAW__r.size(); i++) { if (opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email != null) { addresses += ':' + opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email; } } }
But since replacing my code with the list, my code doesn't work anymore. How then would the syntax look? I suppose first I would need to check if the list is empty in the first place, but after that, how would I check if the email field specifically is empty?
If(opportunity == Null || opportunity == '')
Thank you for your response. But is there a way to specifically to check if the email field is null? Because any of the other fields in my Opportunity can be null, except for the email.