• banders5144
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 11
    Replies

I am quoting apex documentation:

 

Example 1

 

In addition, the sObject field key can be used with insertupdate, or upsert to resolve foreign keys by external ID. For example:

  Account refAcct = new Account(externalId__c = '12345');

  Contact c = new Contact(account = refAcct, lastName = 'Kay');

 

Example 2

 

 

For example, suppose that custom object C1 has a foreign key c2__c that links to a child custom object C2. You want to create a C1 object and have it associated with a C2 record named 'xxx' (assigned to the value c2__r). You do not need the ID of the 'xxx' record, as it is populated through the relationship of parent to child. For example:

 

insert new C1__c(name = 'x', c2__r = new C2__c(name = 'xxx')); 

 

Now i have used this method a couple of times for different object relationship but the only one that i have not gotten to work is with Who or What relationships. Example:

insert new Task(name = 'test', subject = 'test', What = new Account(extid__c = 'test'));

 

Has anyone ever gotten this to work?

 

So what I am trying to accomplish is to upsert  List<sObject> with a field specification of what the external Id is. However this is the error message I get back when I try to save the class.

 

List<sObject> newlist = new List<sObject>();

 

upsert newlist ext_Id__c; (Error Msg: "Upsert with a field specification requires a concrete sObject type)

 

 

Any idea of a way around this?

 

 

So what I am trying to accomplish is to upsert  List<sObject> with a field specification of what the external Id is. However this is the error message I get back when I try to save the class.

 

List<sObject> newlist = new List<sObject>();

 

upsert newlist ext_Id__c; (Error Msg: "Upsert with a field specification requires a concrete sObject type)

 

 

Any idea of a way around this?

 

 

I am quoting apex documentation:

 

Example 1

 

In addition, the sObject field key can be used with insertupdate, or upsert to resolve foreign keys by external ID. For example:

  Account refAcct = new Account(externalId__c = '12345');

  Contact c = new Contact(account = refAcct, lastName = 'Kay');

 

Example 2

 

 

For example, suppose that custom object C1 has a foreign key c2__c that links to a child custom object C2. You want to create a C1 object and have it associated with a C2 record named 'xxx' (assigned to the value c2__r). You do not need the ID of the 'xxx' record, as it is populated through the relationship of parent to child. For example:

 

insert new C1__c(name = 'x', c2__r = new C2__c(name = 'xxx')); 

 

Now i have used this method a couple of times for different object relationship but the only one that i have not gotten to work is with Who or What relationships. Example:

insert new Task(name = 'test', subject = 'test', What = new Account(extid__c = 'test'));

 

Has anyone ever gotten this to work?

 

I would like certain fields in our sfdc-environnement only to be filled with data in capital letters. So from the moment users input data that is not in capitals, they should get an error message when trying to save the record.

 

Is this possible?

 

 

 Thanks in advance!

So what I am trying to accomplish is to upsert  List<sObject> with a field specification of what the external Id is. However this is the error message I get back when I try to save the class.

 

List<sObject> newlist = new List<sObject>();

 

upsert newlist ext_Id__c; (Error Msg: "Upsert with a field specification requires a concrete sObject type)

 

 

Any idea of a way around this?

 

 

I need to create a task and link it to an Account based on the account external id.

I use the example from the manual - upsert() call, the section on upset and foreign keys.



I generate the following XML request:
<Subject>User vb16Save and Send Password</Subject><Description>User vb16 sent password and welcome email by tremor_sa</Description><ActivityDate>2008-11-19+15:58</ActivityDate><Status>Completed</Status><Publisher__c>PD00013</Publisher__c><Account><type>Account</type><Publisher_NUM__c>PD00013</Publisher_NUM__c></Account>

where Publisher__c is the Task externalid and Publisher_NUM__cis the account external id

Wraped in SOAP it becomes:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:partner.soap.sforce.com" xmlns:ns2="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><ns1:SessionHeader><ns1:sessionId>511500D80000000LY4g!ARYAQG_TG0xCEstjK2Kou1cnpI3.HAUkxEwZOGtaQ6a2hBngygs0_SPOu0cvZMwvlmgTiihBuX9mJKFgc8z4pejdC0m9oRCR</ns1:sessionId></ns1:SessionHeader></SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:upsert><ns1:externalIDFieldName>Publisher__c</ns1:externalIDFieldName><ns1:sObjects>
<ns2:type>Task</ns2:type><ns2:Id xsi:nil="true"/><Subject>User vb16Save and Send Password</Subject><Description>User vb16 sent password and welcome email by tremor_sa</Description><ActivityDate>2008-11-19+15:58</ActivityDate><Status>Completed</Status><Publisher__c>PD00013</Publisher__c><Account><Publisher_NUM__c>PD00013</Publisher_NUM__c></Account></ns1:sObjects></ns1:upsert></SOAP-ENV:Body></SOAP-ENV:Envelope>


However I get a SF error:

Unable to create/update fields: AccountId. Please check the security settings of this field and verify that it is read/write for your profile.

Can someone help?

Again, this is specifically for a task.
  • November 19, 2008
  • Like
  • 0
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?
  • September 06, 2008
  • Like
  • 0