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
David.HEDavid.HE 

Problem invoking apex class from a button

Hi to all.

I am copying the behaviour of a button into a new button.

 

I want to invoke an Apex class from a button.

 

This is my code for the class:

 

global class  Observacion {

webservice static  String insertarComentario(String comentario,Id id){
		System.debug('entramos en insertar comentario con los siguientes parámetros');
		System.debug('comentario:'+comentario);
		System.debug('Id:'+id);

		Observaciones__c obs = new Observaciones__c(observacion__c=comentario,comentario__c=id);
		try{
		insert obs;
			}catch(Exception e){
				System.debug('Error insertando observación ' + e.getMessage());
				return 'KO';
			}
	return 'OK';		
 }
}

 

And this is the code inside the button:

sforce.apex.execute("Observacion",
 "insertarComentario",
{comentario:"comentario",
Id:"{!Opportunity.Id}"}
)

 And when I click on the button, I obtain following error :

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'soapenv:Client',faultstring:'No service available for class 'Observacion",}

 

I've been reading in other posts and some peple suggest that it could be a namespace problem, but I don't have any namespaces.

the original code, that it's working fine, is this:

var s = sforce.apex.execute("Escalateaccount","escalate", {varId: leadid });

 

Any tip?

David.HEDavid.HE

I'm sorry.

All was Ok.

But I was creating the class in one sandbox and testing in another one.