I am trying to create an Account sObject so that I can reference at my later code. For the purpose I am running a query on Contacts, and then I pick fields from it and assign them to my Account sObject. The issue is that I am trying to assign a value to an Account field called Salesforce_Account_ID__c which is set "External Auto Number". When I try to assign the value, I get the following error:
Field is not writeable: Account.Salesforce_Account_ID__c
I am aware that the reason for this issue is due to the datatype of the field, but was wondering if there is a workaround without changing the field's datatype.
if(constType == 'IN'){
List<Contact> contactResults = [SELECT Id, accountid, Master_ID__c, account.id, account.Status__c, account.Include_in_Funnel__c, account.Salesforce_Account_ID__c FROM Contact WHERE Master_ID__c IN :masterIdSet];
for(Contact c:contactResults){
Account tmpAcct = new Account(
Id = c.AccountId,
Status__c = c.Account.Status__c,
Include_in_Funnel__c = c.Account.Include_in_Funnel__c,
Master_ID__c = c.Master_ID__c,
Salesforce_Account_ID__c = c.account.Salesforce_Account_ID__c
);
if(acctMap.containsKey(c.Master_Id__c)){
acctMap.get(c.Master_Id__c).add(tmpAcct);
} else {
acctMap.put(c.Master_Id__c, new List<Account>{tmpAcct});
}
}