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
Sumesh ChandranSumesh Chandran 

Upsert operation error, says invalid field name

I have a custom object named MDU_Squad to which I insert records using the Data Import Wizard. 
I have set 2 external ID fields in there, which are
1. Street_address [allow duplicates]
2. CIty_Name [allow duplicates]
Both the fields above have duplicate records as well.

I have created a batch class that pulls in all the records from the above MDU_Squad custom object and inserts into City_Master & Address_Master custom objects getting rid of all the duplicates. So at the end I will be having a master City_Master & Address_Master custom objects with no duplicates
The City_Master & Address_Master custom objects have external ids set, which are city_Name_Ext_Id & address_Ext_Id. Both the fields can't have any duplicates.

I am trying to use the upsert method, to have it insert if the record does not exist in the City_Master or Address_Master custom object or update if they exist in the object.
Here in the below code the addressList and the cityList objects have non-duplicate records which are extracted from the MDU_Squad which are to be saved to the Address_Master and City_Master custom objects.
Database.SaveResult[] saveAddressMaster = Database.Upsert(addressList, sumchans__MDU_Squad__c.STREET_ADDRESS__c, all);  
Database.SaveResult[] saveCityMaster = Database.Upsert(cityList, sumchans__MDU_Squad__c.City_Name__c, all);
Someone please help.

Suraj MakandarSuraj Makandar
Hi Sumesh,

We have to use External Id fields for upsert operation:

A. Please make sure STREET_ADDRESS__c and City_Name__c fields are marked as External Id.
B. Make sure you have Field Level Security(FLS) access for these two fields.

Hope this helps!

Note: Please mark it as best answer if the information is informative.

Sumesh ChandranSumesh Chandran
Hello Suraj,

I am using External Id fields here, and also they have FLS access as well. Also the addressList and cityList objects are of type Address_Master & City_Master respectively, so am I using the external Id of the MDu_Squad custom object or of the above.