I've created a Vf Page to upload the attachment in salesforce. I've a pulic community website where user can Register/ login their self. Logged in user can see the attachment Vf page to upload files.

The Vf Page is working in salesforce, but when I'm testing in from community site by logging as community user, the functionality is not working.

Its giving the error while connecting to salesforce by sforce.connection.

connection.js:595 POST https://dev2.cs4.force.com/services/Soap/u/28.0 500 (Server Error) connection.js:1015 Uncaught sforce.Xml {faultcode: "UNKNOWN_EXCEPTION", faultstring: "UNKNOWN_EXCEPTION: Site under construction"} faultcode : "UNKNOWN_EXCEPTION" faultstring : "UNKNOWN_EXCEPTION: Site under construction" proto : Object

Error in


Below is the Part of javascript used in VF Page :

    userId = sforce.connection.getUserInfo().userId;

    var qr = sforce.connection.query("SELECT contactID FROM USER where ID ='" + userId + "'" );  
    var records = qr.getArray("records");
    var parentId = records[0].ContactId;   

    //Create attachment  
    var att = new sforce.SObject("Attachment");
    att.Name = 'Invoice_'+dateTime; 
    att.ContentType = this.file.type;
    att.ParentId = parentId;
    var binary = "";
    var bytes = new Uint8Array(e.target.result);
    var length = bytes.byteLength;
    for (var i = 0; i < length; i++)
        binary += String.fromCharCode(bytes[i]);
    att.Body = (new sforce.Base64Binary(binary)).toString();
        onSuccess : function(result, source)
        { // logic},
        onFailure : function(error, source)

Its showing message site under construction, but I'm using the site and testing it from site. So this should not be happen.

How to resolve this.

Qustion: is sforce.connection is not working for community site.?

  • This is a public site or authenticated user? Nov 24, 2017 at 5:26
  • This is a public site with registration/login functionality. Means autheticated user only can see upload attachment page. Vf page has a Session ID.
    – user29314
    Nov 24, 2017 at 5:32
  • try to save sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/40.0'; Nov 24, 2017 at 7:16
  • Then you can accept my answer. Nov 24, 2017 at 11:03

1 Answer 1


Its because you need to set server URL correctly. Because in case of site you need to take Site base URL

sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/40.0';

You must log in to answer this question.

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