You need to sign in to do that
Don't have an account?
executebatch(b,>5)returns too many callouts, how to seperate login & callout methods
Hi All,
I am coding for a S2S integration. I am using batch program to accomplish this. I have written a class for login and callout to external system. I had written both login and callout statements in a single method. The WS is working fine till database.executebatch(batchname,5) i.e scope of 5, scope more than 5 is returning too many callout error.
I was told to seperate the login to external system in Start method of batch and callout in execute method of batch.But I am not able to seperate the same. Please help me.
public class TestWebService {
public String errMsg{get;set;}
public String displayError{get;set;}
public TestWebService()
{
displayError = 'none';
}
public void login(){
//-----------------------------------
// Login via SOAP/XML web service api
//-----------------------------------
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.salesforce.com/services/Soap/u/26.0');
request.setMethod('POST');
errMsg+=' 1';
request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
request.setHeader('SOAPAction', '""');
request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + 'uname'+ '</username><password>' + 'pwd'+ '</password></login></Body></Envelope>');
Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement().getChildElement('Body','http://schemas.xmlsoap.org/soap/envelope/').getChildElement('loginResponse','urn:partner.soap.sforce.com').getChildElement('result','urn:partner.soap.sforce.com');
// Grab session id and server url
//--------------------------------
final String SERVER_URL = resultElmt.getChildElement('serverUrl', 'urn:partner.soap.sforce.com').getText().split('/services')[0];
final String SESSION_ID = resultElmt.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText();
errMsg+=SERVER_URL+' <--> '+SESSION_ID;
MyclassWS.myclass ws = new MyclassWS.myclass();
MyclassWS.SessionHeader_element session = new MyclassWS.SessionHeader_element();
session.sessionId=SESSION_ID;
ws.SessionHeader=session;
errMsg+= ' ****** ' + ws.mastermetdh('test') + 'juice in org2';
}
}
I am calling this login() from Batch execute. But i want to split login() to login ( and call it from start) and callout ( and call it from execute ) from this.