1

For those who are looking for an example to update salesforce records from .Net(c#) Here is an example: I am trying to update a field(TestAccount__c) from the object Account in Salesforce, I have the entreprise wsdl already linked in .Net (C#). I hope you find it useful.

I used this code in the codebehind of a button

  sforce is the name of the sf wsdl

 // setup binding (in init code)

   sforce.SforceService binding = new sforce.SforceService();
   sforce.LoginResult lr = binding.login("username", "password+token");
   binding.Url = lr.serverUrl;
   binding.SessionHeaderValue = new sforce.SessionHeader();
   binding.SessionHeaderValue.sessionId = lr.sessionId;

   // update account

   sforce.Account updateAccount = new sforce.Account();
   updateAccount.Id = "..."; // account id
   updateAccount.TestAccount__c = "Done";
   sforce.SaveResult[] result = binding.update(new sforce.sObject[] {updateAccount });

    // todo: check result
2
  • Are you getting any errors? Apr 1, 2014 at 2:36
  • hi Bachovski, it's working now, I will update my question with the right approach so others can see it. Thank you for trying to help me!
    – Carlos
    Apr 1, 2014 at 2:50

1 Answer 1

0

As far as I understood what you're after, you can do that by checking the success property of the SaveResult object:

if (result.success)
{
    // success
    // result.records[0] returns the updated sforce.Account
}
else
{
    // error
    // the message is : result.errors[0].message;
}
3
  • Bachovski, one question for you, if I just want to update fields that have a checkox == true, where should I put this comparison?
    – Carlos
    Apr 1, 2014 at 15:51
  • Can you please explain? Apr 1, 2014 at 22:21
  • Bachovski, I just post another question that expands this question. Could you please help me? thank you very much
    – Carlos
    Apr 2, 2014 at 20:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .