0

I have below code where I get a run-time error as 'Unexpected Identifier'. My Resultset is not getting evaulated properly. Can someone please help?

Onclick Javascript code in Detail Page button

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var user = sforce.connection.getUserInfo();
var check=false;
var count = sforce.connection.query("SELECT COUNT() FROM Contract_vod__c WHERE Signature_Available_abv__c = false and Account_Name_abv__c='{!Account.Id}'");
alert('Count@Check'+count);
check=sforce.apex.execute("CheckAOCAccess","AOCAccess",{LoggedUser:"{!User.Id}"});
alert('check@'+check);
var vUrl = '/apex/ABV_AoCSignatureCapturOnline?actId={!Account.Id}';
if(check == 'true' && count>0)
{alert('check@1'+check);
alert('count@@1'+count);
window.open(vUrl);} 
else if(check == 'false')
{alert('check@2'+check); alert('You are have not the privilege for Acknowledgement of Contents!');}
else {alert('count@2'+count); alert('You have no Acknowledgement of Contents pending to sign!');}
  • What is Resultset and Statement? And you are usign this on button click. Right? – manjit5190 Nov 29 '16 at 8:49
1

Your current main error is this line here:

var count = sforce.connection.query("SELECT COUNT(*) AS total FROM Contract_vod__c WHERE Signature_Available_abv__c = false and Account_Name_abv__c=:"+{!Account.Id});

The ":" bind expression is only valid in Apex Code, not in any other language where SOQL might be used. Here's the correct way to write that line:

var count = sforce.connection.query("SELECT COUNT() AS total FROM Contract_vod__c WHERE Signature_Available_abv__c = false and Account_Name_abv__c='{!Account.Id}'");

This will place the account's Id in between two quotes, which is how SOQL expects the query to be written.

  • Thanks but it now throws exception as 'count()' is not identifiable. I have updated my latest version code. – Testing_SFDC Nov 29 '16 at 9:58
  • It's now saying the select query as faultstring. – Testing_SFDC Nov 29 '16 at 10:05
  • @SFDC_Learner Yes, sorry, it's count() not count(*). I always forget that one, too. – sfdcfox Nov 29 '16 at 10:16
0

replace int with var on count initialization

  • Sorry I changed my mistakes and updated the code. Though it shows same error. – Testing_SFDC Nov 29 '16 at 9:03
0

Paste the JavaScript from the 3rd line to the end into http://jshint.com/ and you will see a number of errors e.g. you have int instead of var and Statement instead of var. JavaScript does not support strongly typed variables.

First correct those errors. Then when you run the code also check your browser's console to ensure no runtime errors are reported.

  • Hello Keith. Sorry I changed my mistakes and updated the code. Though it shows same error. – Testing_SFDC Nov 29 '16 at 9:03
  • @SFDC_Learner You still have int check instead of var check. – Keith C Nov 29 '16 at 9:06
  • Changed it, now it says 'Invalid or unexpected token'. – Testing_SFDC Nov 29 '16 at 9:09

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.