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
mohan s 37mohan s 37 

syntax error & in java script button

Hi Friends,

                  I am geeting the following issue when i try to check the syntax error on onclick javascript button. "Syntax error &". in the following code. Can any one please help me resolving this issue.
Code:
{!REQUIRESCRIPT("/soap/ajax/38.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/38.0/apex.js")} 
try 


var partnerType; 
var accList = []; 
var result = sforce.connection.query( 
"Select Id, Name,Account__c,RecordType.Name,Account__r.Partner_Type_New__c FROM custom_c where id='{!custom__c.Id}' "); 
var iter = new sforce.QueryResultIterator(result); 

while(iter.hasNext()) 

var record=iter.next(); 
partnerType = record.RecordType.Name;
accList.push(record.Account__c); 

if(partnerType=='customer') 

sforce.apex.execute("SampleClass","sampleMethod1",{refreshAccList:accList}); 
parent.window.location = "{! URLFOR($Action.custom__c.View,custom__c.Id,null)}"; 
}
else if(partnerType =='newcustomer'){ 
sforce.apex.execute("Sampleclass1","sampleMethod",{refAccList:accList}); 
parent.window.location = "{! URLFOR($Action.custom__c.View,custom__c.Id,null)}"; 
}

catch(err){ 
alert(err); 
alert("System is currently unable to process your request."); 
}
Best Answer chosen by mohan s 37
Timothy Gentet O'BrienTimothy Gentet O'Brien
{!REQUIRESCRIPT("/soap/ajax/38.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/38.0/apex.js")} 

try { 
	var partnerType; 
	var accList = []; 
	var result = sforce.connection.query("Select Id, Name,Account__c,RecordType.Name,Account__r.Partner_Type_New__c FROM custom_c where id = '{!custom__c.Id}'"); 
	var iter = new sforce.QueryResultIterator(result); 

	while(iter.hasNext()) { 
		var record=iter.next(); 
		partnerType = record.RecordType.Name;
		accList.push(record.Account__c); 
	}

	if(partnerType == "customer"){ 
		sforce.apex.execute("SampleClass", "sampleMethod1", {refreshAccList:accList}); 
		parent.window.location = "{! URLFOR($Action.custom__c.View,custom__c.Id,null) }"; 
	} else if(partnerType == "newcustomer"){ 
		sforce.apex.execute("Sampleclass1", "sampleMethod", {refAccList:accList}); 
		parent.window.location = "{! URLFOR($Action.custom__c.View,custom__c.Id,null) }"; 
	}
} catch(err){ 
	alert(err); 
	alert("System is currently unable to process your request."); 
}

Try that... also try and keep consitency throughout your code, if you chane from using single quotes to double quotes you will often make mistakes and issues... also ensure when you are saving in Salesforce, that all of the quotes and apostrophes are saved as them not as an HTML entity

All Answers

Timothy Gentet O'BrienTimothy Gentet O'Brien
{!REQUIRESCRIPT("/soap/ajax/38.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/38.0/apex.js")} 

try { 
	var partnerType; 
	var accList = []; 
	var result = sforce.connection.query("Select Id, Name,Account__c,RecordType.Name,Account__r.Partner_Type_New__c FROM custom_c where id = '{!custom__c.Id}'"); 
	var iter = new sforce.QueryResultIterator(result); 

	while(iter.hasNext()) { 
		var record=iter.next(); 
		partnerType = record.RecordType.Name;
		accList.push(record.Account__c); 
	}

	if(partnerType == "customer"){ 
		sforce.apex.execute("SampleClass", "sampleMethod1", {refreshAccList:accList}); 
		parent.window.location = "{! URLFOR($Action.custom__c.View,custom__c.Id,null) }"; 
	} else if(partnerType == "newcustomer"){ 
		sforce.apex.execute("Sampleclass1", "sampleMethod", {refAccList:accList}); 
		parent.window.location = "{! URLFOR($Action.custom__c.View,custom__c.Id,null) }"; 
	}
} catch(err){ 
	alert(err); 
	alert("System is currently unable to process your request."); 
}

Try that... also try and keep consitency throughout your code, if you chane from using single quotes to double quotes you will often make mistakes and issues... also ensure when you are saving in Salesforce, that all of the quotes and apostrophes are saved as them not as an HTML entity
This was selected as the best answer
mohan s 37mohan s 37
Hi  Timothy Gentet O'Brien,

                                              Thanks for your quick reply. Your answer is good but, some times it's not working.

Thanks,
Mohan S