I have a trigger that is designed to write unique values of a Picklist from a child object (VIP_Type__c) to the associated Account record. I am having trouble figuring out how to convert the picklist value to a string value to check if the Account field contains the picklist value. The line of code I have is:
if(!a.VIP_Types__r.contains(vip.VIP_Type__c))
Where vip.VIP_Type__c is the picklist field and VIP_Types__r is the text field on the Account. I am getting an error:
"Method does not exist or incorrect signature: void contains(String) from the type List<VIP_Type__c>"
Any ideas? My full trigger is below:
trigger UpdateAcctVIP on VIP_Type__c (after insert, after update, after delete){
Set<Id> acctIds = new Set<ID>();
// Get all the Account Ids in the Set
if (Trigger.isDelete)
{
for(VIP_Type__c vip : Trigger.old){
acctIds.add(vip.Account__c);
}
}
else
{
for(VIP_Type__c vip : Trigger.new){
acctIds.add(vip.Account__c);
}
}
// QUery the Accounts
List<Account> acct = new List<Account>();
// Use the VIP Types to get all the related Types for the Account
acct = [SELECT Id, VIP_Types__c,(Select VIP_Type__c FROM VIP_Types__r)
FROM Account
WHERE Id in :acctIds];
// Iterate over each Account and VIP record
for(Account a : acct){
// for(VIP_Type__c vip: a.Id){
for(VIP_Type__c vip: a.VIP_Types__r){
if(!a.VIP_Types__c.contains(vip.VIP_Type__c) || a.VIP_Types__c == null){ // Check if the Type is already in the Account Field. if not add it otherwise skip
a.VIP_Types__c += vip.VIP_Type__c + ';';
}
}
}
// Update the Account
update acct;
}