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

Newbie -- Using C# to create SalesForce User

I am newbie. I want to create a user with SOAP Partner WSDL. Here are steps I’ve already taken:


-       Downloaded the partner WSDL

-       Reference that file in Virtual Studio 2010


Now can you give me an example code that create a new user using C# and how I can use “using” statement to import salesforce names spaces.


Thanks a lot

Chad Saar 8Chad Saar 8
I have an example of creating a Contact, just change Contact to User if you have an object named User. It took me forever to find the document on how to create vs just update.

Anywhere it says "SalesForce" that is what I named my Service Reference. If it is named the default "WebReference" you would need to change SalesForce to WebReference.

Keep the ID blank. Your login password must be your password followed by your secret key. For example, if my password was "password" it would look like this. passwordX84739434759834753894534
string userName;
            string password;
            userName = "";
            password = "";

            SalesForce.SforceService SfdcBinding = null;
            SalesForce.LoginResult CurrentLoginResult = null;
            SfdcBinding = new SalesForce.SforceService();
                CurrentLoginResult = SfdcBinding.login(userName, password);

            catch (System.Web.Services.Protocols.SoapException ex)
                // This is likley to be caused by bad username or password
                SfdcBinding = null;
            catch (Exception ex)
                // This is something else, probably comminication
                SfdcBinding = null;

            //Change the binding to the new endpoint
            SfdcBinding.Url = CurrentLoginResult.serverUrl;

            //Create a new session header object and set the session id to that returned by the login
            SfdcBinding.SessionHeaderValue = new SalesForce.SessionHeader();
            SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;

            SalesForce.Contact contact = new SalesForce.Contact();

            contact.Id = "";

            contact.FirstName = "";
            contact.Middle_Name__c = "";
            contact.LastName = "";

            SalesForce.SaveResult[] results = SfdcBinding.create(new SalesForce.sObject[] { contact });