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
SurpriseSurprise 

WSdl

Hi All,
 

For connecting salesforce salesforce using Enterprise Wsdl api's,I have written the below given code.Where di i specify the code to associate URL with the session header below.Can somebody help.

 

enterpriseSoapSforceCom.LoginResult lr=new enterpriseSoapSforceCom.LoginResult();
enterpriseSoapSforceCom.soap s=new enterpriseSoapSforceCom.soap();
lr=s.login('nitins1234@yahoo.com','mummy123');
String g=lr.sessionid;
s.inputHttpHeaders_x = new Map<String, String>();
//Setting a basic authentication header
s.inputHttpHeaders_x.put('Authorization', 'g');
System.debug('The value of the session id in the new variable s is'+s);


Avidev9Avidev9
Can you elaborate a lil ?
What are you planning to do ?
SurpriseSurprise

Thanks Avidev ,

Everthing here is purely sopa based.I am trying to connect salesforce to salesforcce so that changes in one org can be reflected in another salesoforce org.So I am consuming enterprise wsdl of the salesforce other org and generating wsdl to apex classes and using it's login functionlaity to establish connection with the other org and finally I am tryiing to query some records using query Api of the enterprise Wsdl.


When I run below given code it gives me an error by saying that destinaltion URL is not reset.I understand that First call to the login() api uses different URL and then login() api returns another url which we need to send with the subsequent  API' calls and session ID as well.Can u help in setting up sesion id and Destination URL

 

 In the end is the WSDl to apex generated classes is given .I am trying to do it using anonymous block s ,once it's starts working then I will write class and try to do it that way.

 

Somehow I have posted this question twice in the same section.



enterpriseSoapSforceCom.LoginResult lr=new enterpriseSoapSforceCom.LoginResult();
enterpriseSoapSforceCom.soap s=new enterpriseSoapSforceCom.soap();

lr=s.login('jack@yahoo.com','password);
String g=lr.sessionid;
System.debug('The value of the session id in the new variable s is'+g);
string url=lr.serverurl; // This is the returned URL from login api.How to setup this so that  it goes with the object calling query() api.


system.debug('The value of the url in the new variable s is'+url);
s.inputHttpHeaders_x = new Map<String, String>();  //
//Setting a basic authentication header
s.inputHttpHeaders_x.put('Authorization', 'g');Setting up input headers and assigning  session id to the header as per salesforce documentation
//s.inputHttpHeaders_x .put('New Url',url);
QueryResult qResult = null;
System.debug('The value of the session id in the new variable s is'+s);
String soqlQuery='SELECT name FROM Contact';
qResult = s.query(soqlQuery);//Calling Query APi fo the enterprise Wsdl
System.debug('The value of the opportunity object opp is'+qResult);


 

 

public class enterpriseSoapSforceCom {
    public class getUserInfo_element {
        private String[] apex_schema_type_info = new String[]{'urn:enterprise.soap.sforce.com','true','

false'};
        private String[] field_order_type_info = new String[]{};
    }
    public class LoginResult {
        public String metadataServerUrl;
        public Boolean passwordExpired;
        public Boolean sandbox;
        public String serverUrl;
        public String sessionId;
        public String userId;
        public enterpriseSoapSforceCom.GetUserInfoResult userInfo;
        private String[] metadataServerUrl_type_info = new String[]{'metadataServerUrl','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] passwordExpired_type_info = new String[]{'passwordExpired','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] sandbox_type_info = new String[]{'sandbox','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] serverUrl_type_info = new String[]{'serverUrl','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] sessionId_type_info = new String[]{'sessionId','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] userId_type_info = new String[]{'userId','urn:enterprise.soap.sforce.com','ID','1','1','true'};
        private String[] userInfo_type_info = new String[]{'userInfo','urn:enterprise.soap.sforce.com','GetUserInfoResult','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:enterprise.soap.sforce.com','true','false'};
        private String[] field_order_type_info = new String[]{'metadataServerUrl','passwordExpired','sandbox','serverUrl','sessionId','userId','userInfo'};
    }
    
    public class Soap {
        public String endpoint_x = 'https://login.salesforce.com/services/Soap/c/28.0/0DFi0000000PCEo';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        public enterpriseSoapSforceCom.QueryOptions_element QueryOptions;
        public enterpriseSoapSforceCom.EmailHeader_element EmailHeader;
        public enterpriseSoapSforceCom.DebuggingInfo_element DebuggingInfo;
        public enterpriseSoapSforceCom.MruHeader_element MruHeader;
        public enterpriseSoapSforceCom.PackageVersionHeader_element PackageVersionHeader;
        public enterpriseSoapSforceCom.SessionHeader_element SessionHeader;
        public enterpriseSoapSforceCom.UserTerritoryDeleteHeader_element UserTerritoryDeleteHeader;
        public enterpriseSoapSforceCom.LoginScopeHeader_element LoginScopeHeader;
        public enterpriseSoapSforceCom.AllowFieldTruncationHeader_element AllowFieldTruncationHeader;
        public enterpriseSoapSforceCom.DebuggingHeader_element DebuggingHeader;
        public enterpriseSoapSforceCom.AllOrNoneHeader_element AllOrNoneHeader;
        public enterpriseSoapSforceCom.LocaleOptions_element LocaleOptions;
        public enterpriseSoapSforceCom.OwnerChangeOptions_element OwnerChangeOptions;
        public enterpriseSoapSforceCom.AssignmentRuleHeader_element AssignmentRuleHeader;
        public enterpriseSoapSforceCom.DisableFeedTrackingHeader_element DisableFeedTrackingHeader;
        public enterpriseSoapSforceCom.StreamingEnabledHeader_element StreamingEnabledHeader;
        private String QueryOptions_hns = 'QueryOptions=urn:enterprise.soap.sforce.com';
        private String EmailHeader_hns = 'EmailHeader=urn:enterprise.soap.sforce.com';
        private String DebuggingInfo_hns = 'DebuggingInfo=urn:enterprise.soap.sforce.com';
        private String MruHeader_hns = 'MruHeader=urn:enterprise.soap.sforce.com';
        private String PackageVersionHeader_hns = 'PackageVersionHeader=urn:enterprise.soap.sforce.com';
        private String SessionHeader_hns = 'SessionHeader=urn:enterprise.soap.sforce.com';
        private String UserTerritoryDeleteHeader_hns = 'UserTerritoryDeleteHeader=urn:enterprise.soap.sforce.com';
        private String LoginScopeHeader_hns = 'LoginScopeHeader=urn:enterprise.soap.sforce.com';
        private String AllowFieldTruncationHeader_hns = 'AllowFieldTruncationHeader=urn:enterprise.soap.sforce.com';
        private String DebuggingHeader_hns = 'DebuggingHeader=urn:enterprise.soap.sforce.com';
        private String AllOrNoneHeader_hns = 'AllOrNoneHeader=urn:enterprise.soap.sforce.com';
        private String LocaleOptions_hns = 'LocaleOptions=urn:enterprise.soap.sforce.com';
        private String OwnerChangeOptions_hns = 'OwnerChangeOptions=urn:enterprise.soap.sforce.com';
        private String AssignmentRuleHeader_hns = 'AssignmentRuleHeader=urn:enterprise.soap.sforce.com';
        private String DisableFeedTrackingHeader_hns = 'DisableFeedTrackingHeader=urn:enterprise.soap.sforce.com';
        private String StreamingEnabledHeader_hns = 'StreamingEnabledHeader=urn:enterprise.soap.sforce.com';
        private String[] ns_map_type_info = new String[]{'urn:fault.enterprise.soap.sforce.com', 'faultEnterpriseSoapSforceCom', 'urn:enterprise.soap.sforce.com', 'enterpriseSoapSforceCom', 'urn:sobject.enterprise.soap.sforce.com', 'sobjectEnterpriseSoapSforceCom'};
        public enterpriseSoapSforceCom.SearchResult search_x(String searchString) {
            enterpriseSoapSforceCom.search_element request_x = new enterpriseSoapSforceCom.search_element();
            enterpriseSoapSforceCom.searchResponse_element response_x;
            request_x.searchString = searchString;
            Map<String, enterpriseSoapSforceCom.searchResponse_element> response_map_x = new Map<String, enterpriseSoapSforceCom.searchResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'urn:enterprise.soap.sforce.com',
              'search',
              'urn:enterprise.soap.sforce.com',
              'searchResponse',
              'enterpriseSoapSforceCom.searchResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.result;
        
            public enterpriseSoapSforceCom.LoginResult login(String username,String password) {
            enterpriseSoapSforceCom.login_element request_x = new enterpriseSoapSforceCom.login_element();
            enterpriseSoapSforceCom.loginResponse_element response_x;
            request_x.username = username;
            request_x.password = password;
            Map<String, enterpriseSoapSforceCom.loginResponse_element> response_map_x = new Map<String, enterpriseSoapSforceCom.loginResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'urn:enterprise.soap.sforce.com',
              'login',
              'urn:enterprise.soap.sforce.com',
              'loginResponse',
              'enterpriseSoapSforceCom.loginResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.result;
        }
            
            
        }
        
        
        }