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
bharath kumar 52bharath kumar 52 

Ajax/Soap API not working in javascript

Hi All,

Below is the piece of code which is executing in salesforce platform(flawlessly) but not in communities(When i execute the below code in communities i am able to get a javascript alert and nothing beyond that). Would be glad if someone can tell me where im going wrong.
{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")}



var p = new sforce.SObject('Deal__c');
p.id = "{!Deal__c.Id}";


function fixTime(time){
   if(time < 10) {time = "0" + time};
   return time;
}

function fixDate(date){
  var Month = fixTime(date.getMonth() + 1);
  var Day = fixTime(date.getDate());
  var UTC = date.toUTCString();
  var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);

  var Minutes = fixTime(date.getMinutes());
  var Seconds = fixTime(date.getSeconds());
  return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
}
 
var oldStat = "{!Deal__c.Status__c}";
if(oldStat == 'Closed'){
alert(' This deal is already closed ');

}
else{
p.Status__c = "Closed";
p.End_date__c = fixDate(new Date()); 
var result = sforce.connection.update([p]);
window.location.reload();
}


Thanks,

Bharath
 
Austin MuellerAustin Mueller
You may have to include the session ID before you make the AJAX callout.
 
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>

 
bharath kumar 52bharath kumar 52
Hi Austin,

It's an onclick button in a page layout not a vf page.
Thanks for the reply.