I have a custom object called ‘FinanceCapture’, it has a lookup field to Account and a field called Contract_Term. I am trying to write a Apex Trigger to make the value of Contract_Term equal to the Contract Term value in Contract Object.
Draft the following code, but it's not working, needs your help please. Thanks
trigger populate_record on FinanceCapture__c (before insert) {
List<Contract> ContractList = new List<Contract>();
Map<Id,FinanceCapture__c> fin = new Map<Id,FinanceCapture__c>(
[SELECT Id, FinanceCapture__lookup_Account__c FROM FinanceCapture__c WHERE Id IN :Trigger.New]);
for (FinanceCapture__c a : Trigger.new){
//in Contract object, if its account ID matches with the account ID in FinanceCapture object, make the Contract_Term__c same as ContractTerm value
If (ContractList.AccountId == fin.get(a.TMS_lookup_Account__c)){
a.Contract_Term__c = ContractList.ContractTerm
}
}
}