function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shanshanshanshan 

Expression Cannot Be Assigned

I'm getting Expression Cannnot be assigned when I'm trying to populate the Account field 

for(Account acc : newAcc){
            Account oldAcc = oldMap.get(acc.Id);
            for(String fieldAPI : FieldSet){
                if(acc.get(fieldAPI) != oldAcc.get(fieldAPI)){    
                    //getting error from the below field
                    acc.get(fieldAPI) = oldAcc.get(fieldAPI);
                }
             }//loop
}//end loop

 
Best Answer chosen by shanshan
Alex SelwynAlex Selwyn
for assignment try this,

acc.put(fieldAPI,oldAcc.get(fieldAPI);

Read below for better understanding.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_map_sobject.htm