I have what seems to be a simple cross object field update. When the Operational Status on the Parent (Account) is updated, I want the value of the Contract Status field on the Child (Master Contract) to be updated to a corresponding value.
I need to match the Parent to the Child on Acc.Long_Account_Id__c = MC.Account_Id__c (it's a one-to-one relationship)
Here is what I've come up with thus far:
trigger UpdateStatus on Account (after update) {
List<Master_Contract__c> mcs = new List<Master_Contract__c>();
Set<Master_Contract__c> mcSet = new Set<Master_Contract__c>();
Map<ID, Master_Contract__c> mcMap = new Map<ID,Master_Contract__c>();
for (Account acc: Trigger.new)
{
if(acc.Operational_Status__c =='Operational')
{
mcSet.add(acc.Long_Account_Id__c);
}
} mcs = [Select Account_Id__c, Contract_Status__c from Master_Contract__c where Account_Id__c n :mcSet];
for(Account acc: Trigger.new)
{
for(Master_Contract__c mc:mcs)
{
if(acc.Long_Account_Id__c==mc.Account_ID__c && acc.Operational_Status__c =='Operational')
mc.Contract_Status__c = 'Active';
}
}
if(mcs.size() >0)
update mcs; }
I am currently getting this error: Error: Compile Error: Incompatible element type String for collection of SOBJECT:Master_Contract__c at line 9 column 6
Suggestions?