Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:54:56+00:00 2026-05-29T04:54:56+00:00

I’m attempting to Create a Job and Add a Batch using the Salesforce Bulk

  • 0

I’m attempting to Create a Job and Add a Batch using the Salesforce Bulk API, but I receive an XML Parsing Error back from Salesforce.

As advised in the Connecting to SalesForce bulk API using C# question, I’m using the partner WSDL to perform the login; that and the Create Job call are working. (Before I had attempted to perform the login by POSTing XML as the documentation had mentioned; I couldn’t get that to work, either.)

Unfortunately, I’m a bit rusty with C#, but here is the code I’m working with.

...
using SalesforceTest.sforce;
...

namespace SalesforceTest
{
    public partial class InvokeBulkAPI : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e) { }

        public string SalesforceLogin(string username, string password)
        {
            SforceService binding = new SforceService();
            binding.Timeout = 60000;

            try
            {
                LoginResult lr = binding.login(username, password);
                binding.Url = lr.serverUrl;

                return lr.sessionId;
            }
            catch (SoapException e) { return e.Message; }
        }

        public string CreateJob(string sfSessionId, string sfOperation, string sfObjectName)
        {
            string str = "";
            string reqURL = "";

            byte[] bytes;

            XmlDocument reqDoc;
            XmlDocument respDoc;

            str = ""
                + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" // added \r\n as recommended by L.B's answer
                + "<jobInfo xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">"
                + "    <operation></operation>" // removed "+sfOperation+"
                + "    <object></object>" // removed "+sfObjectName+"
                + "    <contentType>XML</contentType>" // should be CSV, NOT XML
                + "</jobInfo>"
            ;

            reqURL = "https://cs12-api.salesforce.com/services/async/23.0/job";
            reqDoc = new XmlDocument(); 
            reqDoc.LoadXml(str);

            // added XML modifications
            reqDoc.GetElementsByTagName("operation")[0].InnerText = sfOperation;
            reqDoc.GetElementsByTagName("object")[0].InnerText = sfObjectName;

            bytes = System.Text.Encoding.ASCII.GetBytes(reqDoc.InnerXml);
            respDoc = Post(bytes, reqURL, sfSessionId); // create job

            string JobId = (respDoc != null) ? 
                (respDoc.GetElementsByTagName("id").Count > 0) ?
                    (respDoc.GetElementsByTagName("id")[0].InnerText) :
                    "" :
                ""
            ;

            return JobId;
        }

        public void AddBatch(string sfSessionId, string sfJobId, byte[] fileBytes)
        {
            string reqURL = "https://cs12-api.salesforce.com/services/async/23.0/job/" + sfJobId + "/batch";
            XmlDocument respDoc = Post(fileBytes, reqURL, sfSessionId);
        }

        public XmlDocument Post(byte[] bytes, string reqURL, string sfSessionId)
        {
            WebRequest req = WebRequest.Create(reqURL);
            req.Method = "POST";
            req.ContentLength = bytes.Length;
            req.ContentType = "application/xml; charset=UTF-8"; // should be text/csv; when passing a CSV file
            req.Headers.Add("X-SFDC-Session: " + sfSessionId);

            System.IO.Stream strm = req.GetRequestStream();
            strm.Write(bytes, 0, bytes.Length);
            strm.Close();

            WebResponse resp = req.GetResponse();
            System.IO.Stream respStrm = resp.GetResponseStream();

            XmlDocument respDoc = new XmlDocument();
            respDoc.Load(respStrm);

            return respDoc;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string SessionId = SalesforceLogin(this.TextBox1.Text, this.TextBox2.Text);
            string JobId = CreateJob(SessionId, "insert", "Contact");

            if (JobId.Length > 0)
            {
                AddBatch(SessionId, JobId, this.FileUpload1.FileBytes);
            }
        }
    }
}

The file I’m posting is the same as the example in the documentation.

FirstName,LastName,Department,Birthdate,Description
Tom,Jones,Marketing,1940-06-07Z,"Self-described as ""the top"" branding guru on the West Coast"
Ian,Dury,R&D,,"World-renowned expert in fuzzy logic design. 
Influential in technology purchases."

My question is why would I receive an XML Parsing Error from Salesforce on Line Number 1, Column 1?

This is what I receive:

XML Parsing Error: syntax error
Location: https://####.salesforce.com/services/async/23.0/job/###/batch/###/request
Line Number 1, Column 1:

FirstName,LastName,Department,Birthdate,Description
^

Any help would be appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:54:59+00:00Added an answer on May 29, 2026 at 4:54 am

    First of all never create an xml with string manipulations. Use an XML parser like XmlDocument or XDocument.

    Xml Declaration should be on a seperate line <?xml version=\"1.0\" encoding=\"UTF-8\"?>. you forget \r\n

    Third, you should set text/csv as content type when sending csv

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.