I am trying to build custom validation in my custom controller for a VF page. I have a field which is a multi select pick list. I would like to check if 'Other' is part of the list of values selected, and if yes, display an error. This is what I have done so far, based on my research:
if (acc.Donor_Interests__c.contains('Other') && acc.Donor_Interests_Other__c == null){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.ERROR, 'Please provide details of Donor Interests - Other in the field below.');
ApexPages.addMessage(myMsg);
return null;
}
In this case I get an error "Attempt to de-reference a null object"