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
JeffGressJeffGress 

queryresults/update

Simon posted this code a while back.
sforce.Account a1 = new sforce.Account();
a1.Name = "Account 1";
sforce.Account a2 = new sforce.Account();
a2.Name = "Account 2";
sforce.SObject [] objs = new sforce.SObject [] { a1, a2 };

sforce.SaveResult [] sr = binding.create(objs);
foreach (sforce.SaveResult s in sr)
{
if (s.sucess)
{
Console.WriteLine("new Id {0}", s.id);
}
else
{
Console.WriteLine("failed with error {0} {1}" s.errors[0].statusCode, s.errors[0].message);
}
}
Does this line:  sforce.SObject [] objs = new sforce.SObject [] { a1, a2 };
 create a single instance of sObject that contains a1 and a2 or multiple instances of objs?  Is there a way to just create a1, then add that to objs and create the next a1 repeatedly until objs has everything in it to pass to update?

I am tring to replicate this in a way where I don't have to name things A1, A2, etc?  What I would essentially like to do is run a query, take the results of the query and update a custom date field so that I don't pull this again.  Not knowing how many records I am going to pull makes it both difficult and cumbersome to create a1,a2.etc.  Can anyone help me with this?  My C# is rusty.   I think I am making it harder than it actually is.  I am used to creating an instance, using it and then creating a new instance, but since the update needs everything at once I don't know how to do that.

 

   Thanks,

 

     Jeff





force_devforce_dev

Hi Jeff,

 

Are you using Enterprise or Partner WSDL?

force_devforce_dev

I am going to give a tentative solution which you can extend based upon your implementation and WSDL

 

 

QueryResult qr = binding.query( YOUR_QUERY_HERE);

if(qr != null && qr.size > 0)
{
    List<sObject> lstSObjectToUpdate = new List<sObject>();

    foreach(sObject sObj in qr.records)
    {
        // update your field here e.g. sObj.Any[0].InnerText = "xyz";

        

        // add your record to the collection to update

        lstSObjectToUpdate.Add(sObj);
    }

 

    SaveResult sr = binding.update(.....................

}