I have a Visualforce page that I am using to bulk upload records from a csv file. In using the JSforce framework, I am creating my connection like this:
var conn = new jsforce.Connection({
accessToken: '{!$Api.Session_Id}',
serverUrl: 'https://cs7.salesforce.com',
proxyUrl: '/services/proxy'
});
This org also has the My Domain option configured, and I have tried setting the serverUrl with the custom domain name as well.
I am able to create a job, and batches, and execute them, but when the "onresponse" event fires, I start getting this error message:
XMLHttpRequest cannot load https://mydomain--demo.cs7.my.salesforce.com/_ui/common/request/servlet/JsLoggingServlet. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://mydomain--demo--c.cs7.visual.force.com' is therefore not allowed access.
In my current codebase, I am creating the job manually:
var job = conn.bulk.createJob('SMBulk__c','insert');
And adding the batches to that job:
var batch = job.createBatch();
batch.execute(subfile);
I have also tried this using the bulk load method as well:
conn.bulk.load("SMBulk__c","insert",subfile,
function(err,rets){});
Any help or advice would be greatly appreciated!!
Jim
In Visualforce, you don't have to use proxyUrl or serverUrl in connection constructor - it is for web apps that resides out of salesforce.com domain. Bulk API endpoint is also in the same domain as your "My Domain" domain.
When I run my Visualforce page without the proxyUrl attribute, I get this error:
The bulk job does not process at all.
When I run it with the proxyUrl attribute, the bulk job processes, but I get the error I mentioned earlier:
I have tried various combinations of instanceURL and serverURL with no better results. My best result so far is with the proxyUrl, which allows the bulk job to process, but with the jslogginservlet error message.
There is no need to specify serverUrl and proxyUrl in Visualforce page. Please confirm that you are using the latest version (now 1.3.1).
The first one seems you are specifying serverUrl in connection option, and the second one is raised from other error than JSforce.
I downloaded the latest version of the code 1.3.1, but I still get the same
as before, when my connection looks like this:
conn = new jsforce.Connection({
accessToken: '{!$Api.Session_Id}'
});
and no batch is processed. When I add the proxyURL like this:
conn = new jsforce.Connection({
accessToken: '{!$Api.Session_Id}'
,proxyUrl: '/services/proxy'
});
then the batch does get processed.
I was wrong. It still needs proxyUrl when using bulk API, surely it accepts bulk API request but it redirects to other domain than Visualforce page. I think @jimrae 's last setting is the one how to connect to bulk API from Visualforce page.
conn = new jsforce.Connection({
accessToken: '{!$Api.Session_Id}',
proxyUrl: '/services/proxy'
});
Thank you for the validation. That is the way I ended up setting up the
configuration for my project.
Most helpful comment
I was wrong. It still needs
proxyUrlwhen using bulk API, surely it accepts bulk API request but it redirects to other domain than Visualforce page. I think @jimrae 's last setting is the one how to connect to bulk API from Visualforce page.