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
jdeviajdevia 

How to populate sObject

Hi, following the sForce_API PDF, and trying to execute the CREATE call sample. I can't find a way to understand this line:

sObject[] records = new sObject[] {account};

I can´t understand the "... = new sObject[] {account};", how is the way to be done??

On my code source i have this on this way:
pruebaCreacionFeb3V1.sforce.SaveResult saveResults = ??????;

How do i populate the sobject array??

Thanks

(C#.net & Enterprise.wsdl)

Message Edited by jdevia on 02-03-2006 08:09 AM

Gareth DaviesGareth Davies

jdevia wrote:
Hi, following the sForce_API PDF, and trying to execute the CREATE call sample. I can't find a way to understand this line:

sObject[] records = new sObject[] {account};



sObject is a class called sObject.

sObject[] is an Array of this class.
The Syntax
{} is a way of declaring an array.

for instance string a[] = new string [] {"hello","world"}
a[0] == "hello" is true
a[1] == "world" is true.

in your example account is an instance of an sObject class
and records[0] = account.




I can´t understand the "... = new sObject[] {account};", how is the way to be done??

On my code source i have this on this way:
pruebaCreacionFeb3V1.sforce.SaveResult saveResults = ??????;

How do i populate the sobject array??

Thanks

(C#.net & Enterprise.wsdl)

Message Edited by jdevia on 02-03-2006 08:09 AM





saveResults is another object which is the return type from methods of the SforceService class.

If what you are trying to do is query your SFDC then you want to look at query method which returns a QueryResult object. the saveResult object is returned from updates and creates (in APIv7 you might want to investigate the new upsert method)

Perhaps you would be better to start with the Enterprise API rather than the partner one. A lot of the complextity that you are experiencing is caused by the flexibility of the P-API which is needed to cross customisation boundaries. The E-API hides this in a way that you may find more efficient for your needs.
This thread (3072) has a good discussion

Hope that helps, good luck

Gareth

Message Edited by Gareth Davies on 02-03-2006 09:13 AM

DevAngelDevAngel
What is happening there is we are creating an array of sobjects and down-casting an account to an sobject. Using the enterprise wsdl, you can create an instance of an Account and set the properties and fields. Then, you need to send the object as part of an array in the create or update call.

See the .Net samples for complete examples.
jdeviajdevia
Thanks, but let me ask again,

this is the API sample:

sObject[] records = new sObject[] {account};

And this is my code:

pruebaCreacionFeb3V1.sforce.sObject records = new pruebaCreacionFeb3V1.sforce.sObject {account};

My problem is how do I add the account to the RECORDS array??

And it shows this error:

A new expression requires () or [] after type over the { & } characters..

Message Edited by jdevia on 02-03-2006 08:48 AM

Gareth DaviesGareth Davies
try this:

sObjects[] records = new sObjects[] {account}

---- I just compiled this to check for you

sObject obvious = new sObject();
sObject [] collection_of_obvious = new sObject[] {obvious};

And this is the correct syntax.

Message Edited by Gareth Davies on 02-03-2006 09:09 AM