+ Start a Discussion
Naveen saini 10Naveen saini 10 

Salesforce Custom Button

This is my code on custom button
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';


caseObj.OwnerId = '{!$User.Id}';

var result = sforce.connection.update([caseObj]);

if(!result[0].getBoolean("success")){
alert('Case owner can NOT be changed');
}
window.location.reload();

How can i show standard validation error instead of alert??
Nayana KNayana K
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';


caseObj.OwnerId = '{!$User.Id}';

var result = sforce.connection.update([caseObj]);

if(result[0].getBoolean("success")){

window.location.reload();
}
else
{
alert(result);
}

 
Nayana KNayana K
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!$User.Id}';
var result = sforce.connection.update([caseObj]);
if(result[0].getBoolean("success"))
{
	window.location.reload();
}
else
{
	var errorMessage = ''; 
	for (var i=0; i<result.length; i++) 
	{ 
	errorMessage += 'Error: ' + result[i].errors.message + ' \n'; 
	} 
	alert(errorMessage); 
}

For userfriendly error message display , you can use above code.
 
Naveen saini 10Naveen saini 10
Thanks for the reply.
But I want to show exact validation message not window alert.
so how can i??