I'm using the following code to associate Contact to Account based on Domain field (type=text).
trigger AssociateContact on Contact (before insert)
{
List<String> contactEmaildomains = new List<String>();
for(Contact contact:Trigger.new)
{ if(contact.Autocreated__c && string.isNotBlank(contact.Domain__c))
contactEmaildomains.add('%'+contact.Domain__c+'%');
}
System.debug(contactEmaildomains);
List<Account> accounts = [SELECT
Id, Domain__c
FROM
Account
WHERE
Domain__c LIKE :contactEmaildomains];
System.debug(accounts);
Map<String, Id> domains = new Map<String, Id>();
for(Account record: accounts)
{
for(String dom:record.Domain__c.Split(','))
domains.put(dom, record.Id);
}
for(Contact record: Trigger.new)
{
if(domains.get(record.Domain__c) != null )
{
record.AccountId = domains.get(record.Domain__c);
} else if (string.isNotBlank(record.email) && record.Autocreated__c == true) { record.AccountId = '0016100000J1K3c';}
}
}
I'd like to change the field type to Long Text Area. In order to do that, I need to update the trigger to avoid this error:
field 'Domain__c' can not be filtered in query call
I hope that someone can help me with that.