0

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#), but due to my lack of experience I found this quite tricky, can anybody help me please: here is what I have so far:

sforce is the name of the sf wsdl

namespace UpdateSF
 {
public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        sforce.Account updatefield= new sforce.Account();



        if (updateField != null)
        {
            updateField.TestAccount__c = "Done";

        }
        else
        {

        }

     //this is not right
     sforce.SaveResult[] result = updateField.update(new sforce.sObject[] { updateField });

     }

    }

   }

 }

1 Answer 1

1

I believe it should be something like that:

// setup binding (in init code)

sforce.SforceService binding = new sforce.SforceService();
sforce.LoginResult lr = binding.login("username", "password");
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
Sign up to request clarification or add additional context in comments.

8 Comments

Hello Alex, first of all thank you for helping me and your time. I tried your solution and I am getting this error and I run the page UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService. Any ideas?
I've updated the answer adding missing Url initialisation. It probably should work now.
I added binding.Url = "login.salesforce.com"; before the binding.login and now I am getting this error: Client found response content type of 'text/html;charset=UTF-8', but expected 'text/xml'.
You are the man!!! thank you so much Alex. You made my day I truly appreciate it. One more question, where can I find more info about this topic? thank you in advance!
In most cases just google it :) Also SalesForce has a pretty good developer documentation with samples (in c# as well) on theirs site.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.