+ Start a Discussion
Chris987654321Chris987654321 

Callout from triggers are currently not supported:

I am getting the following error when trying to call a webservice from a trigger:

Callout from triggers are currently not supported: Class.esbLearntodayInfo.ServiceHTTPBehaviour.GetRasIDBySSN: line 78, column 13

 

I read on another post that there must be an @future, but I am uncertain where I should put it. I tried to put it right before  public String GetRasIDBySSN(String ssn) { but it said that @future must be in the upper most class. 

 

This is the class for the webservice:

 

//Generated by wsdl2apex

public class esbLearntodayInfo {

public class GetRasIDByFirstAndLastNameAndEmailAddress_element {
public String firstname;
public String lastname;
public String emailAddress;
private String[] firstname_type_info = new String[]{'firstname','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] lastname_type_info = new String[]{'lastname','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] emailAddress_type_info = new String[]{'emailAddress','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'firstname','lastname','emailAddress'};
}
public class GetRasIDByFirstAndLastNameAndEmailAddressResponse_element {
public String GetRasIDByFirstAndLastNameAndEmailAddressResult;
private String[] GetRasIDByFirstAndLastNameAndEmailAddressResult_type_info = new String[]{'GetRasIDByFirstAndLastNameAndEmailAddressResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'GetRasIDByFirstAndLastNameAndEmailAddressResult'};
}
public class GetRasIDBySSN_element {
public String ssn;
private String[] ssn_type_info = new String[]{'ssn','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'ssn'};
}
public class GetRasIDBySSNAndDOBResponse_element {
public String GetRasIDBySSNAndDOBResult;
private String[] GetRasIDBySSNAndDOBResult_type_info = new String[]{'GetRasIDBySSNAndDOBResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'GetRasIDBySSNAndDOBResult'};
}
public class GetRasIDBySSNAndDOB_element {
public String ssn;
public String dob;
private String[] ssn_type_info = new String[]{'ssn','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] dob_type_info = new String[]{'dob','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'ssn','dob'};
}
public class GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResponse_element {
public String GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResult;
private String[] GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResult_type_info = new String[]{'GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResult'};
}
public class GetRasIDBySSNResponse_element {
public String GetRasIDBySSNResult;
private String[] GetRasIDBySSNResult_type_info = new String[]{'GetRasIDBySSNResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'GetRasIDBySSNResult'};
}
public class GetRasIDByFirstAndLastNameAndEmailAddressAndStudentID_element {
public String firstname;
public String lastname;
public String emailAddress;
public String studentID;
private String[] firstname_type_info = new String[]{'firstname','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] lastname_type_info = new String[]{'lastname','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] emailAddress_type_info = new String[]{'emailAddress','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] studentID_type_info = new String[]{'studentID','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'https://esb.learntoday.info/','true','false'};
private String[] field_order_type_info = new String[]{'firstname','lastname','emailAddress','studentID'};
}
public class ServiceHTTPBehaviour {
public String endpoint_x = 'https://esb.learntoday.info/RasmussenIdentificationService.svc';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'https://esb.learntoday.info/', 'esbLearntodayInfo'};
public String GetRasIDBySSN(String ssn) {
esbLearntodayInfo.GetRasIDBySSN_element request_x = new esbLearntodayInfo.GetRasIDBySSN_element();
esbLearntodayInfo.GetRasIDBySSNResponse_element response_x;
request_x.ssn = ssn;
Map<String, esbLearntodayInfo.GetRasIDBySSNResponse_element> response_map_x = new Map<String, esbLearntodayInfo.GetRasIDBySSNResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'https://esb.learntoday.info/IRasmussenIdentificationService/GetRasIDBySSN',
'https://esb.learntoday.info/',
'GetRasIDBySSN',
'https://esb.learntoday.info/',
'GetRasIDBySSNResponse',
'esbLearntodayInfo.GetRasIDBySSNResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.GetRasIDBySSNResult;
}
public String GetRasIDByFirstAndLastNameAndEmailAddress(String firstname,String lastname,String emailAddress) {
esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddress_element request_x = new esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddress_element();
esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressResponse_element response_x;
request_x.firstname = firstname;
request_x.lastname = lastname;
request_x.emailAddress = emailAddress;
Map<String, esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressResponse_element> response_map_x = new Map<String, esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'https://esb.learntoday.info/IRasmussenIdentificationService/GetRasIDByFirstAndLastNameAndEmailAddress',
'https://esb.learntoday.info/',
'GetRasIDByFirstAndLastNameAndEmailAddress',
'https://esb.learntoday.info/',
'GetRasIDByFirstAndLastNameAndEmailAddressResponse',
'esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.GetRasIDByFirstAndLastNameAndEmailAddressResult;
}
public String GetRasIDBySSNAndDOB(String ssn,String dob) {
esbLearntodayInfo.GetRasIDBySSNAndDOB_element request_x = new esbLearntodayInfo.GetRasIDBySSNAndDOB_element();
esbLearntodayInfo.GetRasIDBySSNAndDOBResponse_element response_x;
request_x.ssn = ssn;
request_x.dob = dob;
Map<String, esbLearntodayInfo.GetRasIDBySSNAndDOBResponse_element> response_map_x = new Map<String, esbLearntodayInfo.GetRasIDBySSNAndDOBResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'https://esb.learntoday.info/IRasmussenIdentificationService/GetRasIDBySSNAndDOB',
'https://esb.learntoday.info/',
'GetRasIDBySSNAndDOB',
'https://esb.learntoday.info/',
'GetRasIDBySSNAndDOBResponse',
'esbLearntodayInfo.GetRasIDBySSNAndDOBResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.GetRasIDBySSNAndDOBResult;
}
public String GetRasIDByFirstAndLastNameAndEmailAddressAndStudentID(String firstname,String lastname,String emailAddress,String studentID) {
esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressAndStudentID_element request_x = new esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressAndStudentID_element();
esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResponse_element response_x;
request_x.firstname = firstname;
request_x.lastname = lastname;
request_x.emailAddress = emailAddress;
request_x.studentID = studentID;
Map<String, esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResponse_element> response_map_x = new Map<String, esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'https://esb.learntoday.info/IRasmussenIdentificationService/GetRasIDByFirstAndLastNameAndEmailAddressAndStudentID',
'https://esb.learntoday.info/',
'GetRasIDByFirstAndLastNameAndEmailAddressAndStudentID',
'https://esb.learntoday.info/',
'GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResponse',
'esbLearntodayInfo.GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.GetRasIDByFirstAndLastNameAndEmailAddressAndStudentIDResult;
}
}
}

 

 This is the trigger

 

trigger ESB_Trigger on Enrollment_Application__c (before update) {
// Check if the thing that changed was the Student_Approval__c checkbox at the end of the Enrollment App when the student indicates
// that they have finished
if (trigger.new[0].Student_Approval__c==true && trigger.old[0].Student_Approval__c==false) {

// include the student information (ssn) here
Contact c = [select SSN__c FROM Contact WHERE Id=:trigger.old[0].Contact__c];
string SSN=c.SSN__c;
System.debug('SSN='+SSN);

if (SSN!=null) {
string [] splitSSN = SSN.split('-');
string SSN_nodashes = splitSSN[0] + splitSSN[1] + splitSSN[2];
System.debug('SSN_nodashes='+SSN_nodashes);

esbLearntodayInfo.ServiceHTTPBehaviour newSSn = new esbLearntodayInfo.ServiceHTTPBehaviour();
string output = newSSn.GetRasIDBySSN(SSN_nodashes);
// String output back to the contact record
System.debug('RasID: '+output);
}
}
}

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Chris987654321Chris987654321
Thanks Wes. I ended up creating another class w/ an @future method which calls the WSDL class. This worked great.

All Answers

WesNolte__cWesNolte__c

Hey

 

The @future annotation needs to be directly before the method that makes the callout. This whole area can be a bit trickey at this call is made asynchronously.. a nice post can be found on Jeff Douglas' blog

 

Cheers,

Wes 

Chris987654321Chris987654321
Thanks Wes. I ended up creating another class w/ an @future method which calls the WSDL class. This worked great.
This was selected as the best answer