+ Start a Discussion
Josh VJosh V 

Calling callout function from trigger

Hey all,

 

I'm trying to send some GET data to an external server after a product gets updated.  I have both the trigger and class created to the point that I think it should work, but something is going wrong.  I'm getting the error: Method is not visible: httpSendtoService.sendFunc(String). I realize this must mean that this has something to do with scope and the fact that my class is defined as global, but I was under the impression that this was the correct way to define it in order to declare a @future function.

 

Here's my trigger:

trigger httpTest on Product2 (after update) {
		
	string toSend = 'Product';
	
	httpSendtoService.sendFunc(toSend);
	
}

 

 

 And my Class:

global class httpSendtoService {
	@future (callout=true) static void sendFunc(string which){
		
		Http connect = new Http();
		HttpRequest req = new HttpRequest();
		
		req.setMethod('GET');
		req.setEndpoint('http://domain.com/tests/SalesForce-HTTP-Requests.php?Data=' + which);
		
		HttpResponse res = connect.send(req);
		
	}
}

 

 

On a related note, I would prefer to send this data via POST, rather than GET, but I can't seem to find how to structure the data.

 

Any Ideas?

 

Any help would be greatly appreciated,

Josh

 

Best Answer chosen by Admin (Salesforce Developers) 
BritishBoyinDCBritishBoyinDC

I think the method also has to be public...

 

global class httpSendtoService {
	@future (callout=true) 
        public static void sendFunc(string which){
		
		Http connect = new Http();
		HttpRequest req = new HttpRequest();
		
		req.setMethod('GET');
		req.setEndpoint('http://domain.com/tests/SalesForce-HTTP-Requests.php?Data=' + which);
		
		HttpResponse res = connect.send(req);
		
	}
}

 

 

 

 

All Answers

BritishBoyinDCBritishBoyinDC

I think the method also has to be public...

 

global class httpSendtoService {
	@future (callout=true) 
        public static void sendFunc(string which){
		
		Http connect = new Http();
		HttpRequest req = new HttpRequest();
		
		req.setMethod('GET');
		req.setEndpoint('http://domain.com/tests/SalesForce-HTTP-Requests.php?Data=' + which);
		
		HttpResponse res = connect.send(req);
		
	}
}

 

 

 

 

This was selected as the best answer
Starz26Starz26

add the global or public keyword to the method, or instantiate the class in the trigger and call the method using the class variable.

Josh VJosh V

That was exactly it!  Thanks a bunch!  For some reason I didn't think that I could declare both static and public, I just knew that I needed it to be static to be a @future call.

 

Do you by chance know anything about my second question about sending POST data rather than GET?  I'm guessing it's a list that gets defined, but I can't find the documentation for the structure...

 

Thanks so much,

Josh