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!');}
1
  • What is Resultset and Statement? And you are usign this on button click. Right?
    – manjit5190
    Nov 29, 2016 at 8:49

3 Answers 3

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.

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

replace int with var on count initialization

1
  • Sorry I changed my mistakes and updated the code. Though it shows same error. Nov 29, 2016 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.

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

You must log in to answer this question.

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