1

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

Connection.js

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");
    getdateTime();
    console.log(dateTime);
    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();
    sforce.connection.create([att],
    {
        onSuccess : function(result, source)
        { // logic},
        onFailure : function(error, source)
        {//logic}
    }

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? – Tushar Sharma Nov 24 '17 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 '17 at 5:32
  • try to save sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/40.0'; – Tushar Sharma Nov 24 '17 at 7:16
  • Then you can accept my answer. – Tushar Sharma Nov 24 '17 at 11:03
2

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';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.