You need to sign in to do that
Don't have an account?
hemm
Setting a lookup field using an External ID in UPSERT
For the life of me, I am unable to perform an upsert and get a lookup field to get populated. I am getting the error "id value of incorrect type: 3". Here's how I have things configured.
Custom object 1
External_Id__c - this is a number field and has the attributes External ID and Unique checked to true. (example value is 3)
Custom object 2
Has a lookup field to Custom Object 1. When upserting, my PHP array sets this values to a value that exists in CustomObject1.External_Id__c (example value is 3)
Upserting a record here gets the error "id value of incorrect type: 3"
If I comment out the lookup field when upserting to Custom Object 2, a record is upserted with no errors.
Any ideas? Do I have to do anything special in the PHP code to get this foreign key relationship to work?
Custom object 1
External_Id__c - this is a number field and has the attributes External ID and Unique checked to true. (example value is 3)
Custom object 2
Has a lookup field to Custom Object 1. When upserting, my PHP array sets this values to a value that exists in CustomObject1.External_Id__c (example value is 3)
Upserting a record here gets the error "id value of incorrect type: 3"
If I comment out the lookup field when upserting to Custom Object 2, a record is upserted with no errors.
Any ideas? Do I have to do anything special in the PHP code to get this foreign key relationship to work?
~Mike
Reading the section "upsert() and Foreign Keys" in the API guide leads me to think this. What I don't know is how to apply this in the PHP toolkit. I was hoping I could just set the field value, but maybe it's not that easy.
Ideas?
I'm not sure how this maps into the PHP toolkit, but hopefully between the c# example, and the actual SOAP message needed, it should get you there.
I am actually trying to associate Custom Object 2 to Custom Object 1, Accounts and Contacts. I was planning on doing some Apex Code anyway to resolve a couple of FKs, so I decided to just implement the logic in Apex Code to resolve all foreign keys. What is actually happening behind the scenes is that I am pushing a set of related MySQL table in Salesforce. I am now able to load each table individually with no dependencies between them. Once it's loaded Apex Code goes and uses the data on each table to resolve all the Foreign Keys I have.
It's similar to using the External ID to resolve it, but just doing it in a different way.
I am still looking for an answer whether the PHP toolkit supports this capability, but my specific needs in this use case are going to be met via Apex Code.
Message Edited by hemm on 09-08-2008 02:32 PM
Thanks in advance!
Case c = new Case(subject='Apex FKs');
Account a = new Account(extId__c='00001');
c.account = a;
insert c;
Thanks, Simon.
SimonF wrote:
Sure, here's a block you can run with execAnonymous
Case c = new Case(subject='Apex FKs');
Account a = new Account(extId__c='00001');
c.account = a;
insert c;
Simon, suppose that an Account didn't exist with that External ID. Would this code create the Account or would it just not be able to populate the lookup field and leave c.account blank on the case record?
This does not work for me.
Have a custom object called test_obj__c with a lookup to Account which has an external Id called ext_id__c.
When i try this code i get an error:
Compile Error: line 3, column 1: Illegal assignment from SOBJECT:Account to Id
Why does this happen?
You have to set the relationship, not the foreign key field itself. (note the __r rather than __c)
I ran into this issue, but I'm using this REST API. How can this be done using the REST API?