I have a requirement to update Account_Transfer__c(Child) object with District Name(Parent) when a field value matches on child record.
below is the logic that I've achieved so far
insert accTransferPolicy; //inserting Account Transfer Policy record (grand child)
Map<string, District__c> mapATwithDistrict = new Map<string, District__c>();
for (District__c dst : [
SELECT id, Name
FROM District__c
WHERE Status__c = 'OPEN' ]) {
mapATwithDistrict.put(dst.Name, dst);
}
for (Account_Transfer_Policy__c c : accTransferPolicy) {
if (c.Account_Transfer__c != null) {
if (mapATwithDistrict.containsKey(c.Account_Transfer__r.District_From__c)) {
c.Account_Transfer__r.Transfer_From__c = mapATwithDistrict.get(Name).Id;
}
}
update c;
}
From the above code, the hierarchy is as:
Account_Transfer_Policy (grand child) --> Account_Transfer__c (Child) --> District__c (Parent)
Now, from the above code, i'm getting the error as
Variable does not exist: Name
can anyone please let me know on how to update Transfer_From__c field with matching district Name Id when District name on District__c record and District_From__c on Account Transfer record matches