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
Srihari Nama Ananda KumarSrihari Nama Ananda Kumar 

Salesforce Bulk 2.0 Account.Id is not indexed field

We are trying to do Bulk Upsert for Contacts and map all the new contacts that are are upserted with an existing Account Id. So while preparing the CSV we are using Account.Id and the value is the actual Id of the account for all CSV records. However I seem to get an error 
INVALID_FIELD:Field name provided, Id is not an External ID or indexed field for Account:--

As per the documentation https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_csv_rel_field_header_row.htm any indexed fields can be used. And Describe response for account clearly says idLookup property for Id field is set to true. Can anybody help why this is failing?
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Srihari,

"The property idLookup means that it can be used to specify a record in an upsert call. The Id field of each object has this property and some Name fields".  Here there is an explanation of the difference: https://salesforce.stackexchange.com/questions/98112/difference-between-idlookup-from-external-id

As per the External Id message, is true that the field Id on Account is not an External Id. You can find that information by querying the describe of the sObject Account and looking for the property externalId in the Id field description.

User-added image


If you have the Account Id already and just want to keep the relationship between the Contact and Account just change your CSV from "Account.Id" to "AccountId".

The difference is, you can use the Id field of an Account to upsert itself. So if you have a CSV of Accounts you can use this field to upsert them. The fact that is not an external id means that from Contacts you cannot use the Account.Id to refer to an External Id of Account but you do can use AccountId to link them.

As you're are upserting Contacts, you cannot use the Account.Id to refer to an External field of an Account.

Don't know if it's clear, let me know if you need further assistance. 

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
 
Srihari Nama Ananda KumarSrihari Nama Ananda Kumar
Hello Zuinglio,

Thanks a lot for the explanation, however I need your help in answering more queries on this.
I understand that idLookup fields can be used fo identify a record uniquely for an upsert operation. However while working with data fields having relations in Bulk interactions confirm our understanding

1. Field referring to other object Id 
1.a Contact.AccountId -> AccountId(CSV Header, and value containing the direct account id)
1.b Contact.AccountId -> Account.ExternalId

2. Field referring to field of the same object type
2.a Contact.ReportsToId -> ReportsToId (direct Contact Id of another contact)
2.b Contact.ReportsToId -> ReportsTo.ExternalId
2.c Contact.ReportsToId -> ReportsTo.Email (Assuming this is valid and Email is not ExternalId Field)

3. Fields having polymorphic relations referring to 
3.a Task.WhoId -> WhoId (Contact Id in the value)
3.b Task.WhoId -> Contact:Who.ExternalId
3.c Task.WhoId -> Contact:Who.Email (Email is an idLookup of the other object)

So considering the validity of the above scenarios it is correct to say that
A) When reference fields are used in data of the upsert and referred though Id field no relationshipName is required. 
B) When referring through ExternalId RelationshipName.ExternalId to be used. 
C) Referring to objects via an idLookup field is supported only when the referred field is of the same object, and idLookup of other objects cannot be used with relationshipName while doing bulk operations.
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Srihari,

You got it right but I would to add one more thing to your third conclusion:

"C) Referring to objects via an idLookup field is supported only when the referred field is of the same object, and idLookup of other objects cannot be used with relationshipName while doing bulk operations." unless the other object field that has the idLookup property is also an External Field. Every External field implies in having the idLookup property set to true.

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.