I have a custom object called 'myObject__c'. This object has a lookup with Account. Now I want to get the values of an existing record (e.g. recordA) and update another record (e.g. recordB).
this is my code:
List<myObject__c> abc = new List<myObject__c>();
List<myObject__c> record1 = [SELECT field1, field2 FROM myObject__c WHERE AccountID = 1];
List<myObject__c> record2 = [SELECT field1, field2 FROM myObject__c WHERE AccountID = 2];
for (myObject__c oldrecord : record1) {
for(myObject__c newrecord : record2) {
newrecord.field1 = oldrecord.field1;
newrecord.field2 = oldrecord.field2;
}
}
update newrecord;
when I try to save the file, it gives me an error:
Variable does not exist: newrecord // last line
record1
is aList
, not a singleSObject
. Are you expecting exactly one result in each query? It's not clear what behavior is desired here.