I am trying to perform upsert on
opportunity based on
external Id. I am building the opportunity objects based on
sObject as I am using that function for other objects too.
Opportunity object contains the reference to
Account and it has
BasicId__c field which I am trying to update.
in order to dynamically update the
Opportunity data and
Account reference filed I have written the following code.
SObject sObj = Schema.getGlobalDescribe().get('Opportunity').newSObject(); //for normal Opportunity field (this works fine) sObj.put('Name','John'); sObj.put('OfficePhone__c','9998889890'); //for reference field update `Account.BasicId__c` SObject sRefObj = Schema.getGlobalDescribe().get('Account').newSObject(); sRefObj.put('BasicId__c','44322'); sObj.putSObject('Account',sRefObj);
Now, when I perform an upsert after casting
Opportunity it throws following error
INVALID_FIELD: Field name provided, BasicId__c is not an External ID or indexed field for Account
Not sure how would i able to update the reference field.
BasicId__c is not the external Id in