Thursday 25 April 2013

How to call  method from one salesforce account to another salesforce account


1.Create WSDL FOR class in which Methods is  there.
2. Create Apex class From that wsdl in to other Account
Create  class
global class CallCreatereservation {
public Static void  call(){
        //-----------------------------------
        // Login via SOAP/XML web service api
        //-----------------------------------
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://' + LOGIN_DOMAIN + '.salesforce.com/services/Soap/u/22.0');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
        request.setHeader('SOAPAction', '""');
        //not escaping username and password because we're setting those variables above
        //in other words, this line "trusts" the lines above
        //if username and password were sourced elsewhere, they'd need to be escaped below
        request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</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();
System.debug('session id'+SESSION_ID );
System.debug('session url'+SERVER_URL );
soapSforceComSchemasClassGdGdxtran.SessionHeader_element obj1 =new soapSforceComSchemasClassGdGdxtran.SessionHeader_element();
obj1.sessionId=SESSION_ID;
soapSforceComSchemasClassGdGdxtran.GDXTransaction obj =new soapSforceComSchemasClassGdGdxtran.GDXTransaction();
obj.SessionHeader=obj1;
System.debug(obj.createReservation('Baljeet'));
}
  CallCreatereservation.call();

No comments:

Post a Comment