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

Error in Javascript for Custom button



This is my first attempt to write javascript for an action button.


I want to iterate through a list of Strings (generated by splitting a long comma separated string).

I want to process these Strings in batches equal to Quanta value.


Problem is that when I push the button I get this Error:


Unexpected token: ILLEGAL


This is my code:




var quota = {!$Setup.testtt__Gateway_Setting__c.testtt__Max_Quota__c};
var Id = '{!testtt__Micro_Campaign__c.Id}'
var recipients = {!testtt__Micro_Campaign__c.testtt__Distribution_List__c}.split(',');
var startSlice = 0;
var endSlice = quota;
var silices = 0;
var timeout;

function timedPublish(){
	var result;
	while(silices < quota){	
		result = executePublish(recipients.slice(startSlice, endSlice));
		if(result == 0){
			alert(" Messages are being processed and published. This might take time depending on the number of recipients");
			alert("Some error was found and publishing as stopped. please check the logs.");
		startSlice = endSlice++;
		if(endSlice <=  recipients.lenght)
			endSlice = i*quota;
			endslice = recipients.lenght;
		timeout = setTimeout("timedPublish()",2000);	
function executePublish(toNumbers){
	return result = sforce.apex.execute( 
					 "testtt/MicroCampaignAPI", // class 
					 "publishCampaign", // method 
					 {campaignID: Id, recipients: toNumbers});     //arguments 		


Any idea what am I doing wrong?


Many Thanks


Ensure your visualforce page...its may be incorrect script call...

Rahul SharmaRahul Sharma

Hello kruvi,


I think the problem may be due to recipients.lenght, Change it to recipients.length,

And also i is not defined here: endSlice = i*quota;
And Check the datatype of the variables wherever you are assigning or comparing the values.


Put alerts in places and find exact line number of error.