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
santhosh.usanthosh.u 

Importance of setting SforceService.Url property before calling SforceService.login()

I'm new to Salesforce API, I'm trying to update salesforce case record comments from my applications, when I went through the samples, I see that in few samples, Url property of the SforceService is being set before SforceService.login() is called, this property is later overridden by the value returned by LoginResult.ServerUrl. I'm just wondering the importance of doing so... is it good practice to set Url property before calling login method? if yes, where do I get this Url? should I grab from WSDL? what if this changes later? -Santhosh
Navatar_DbSupNavatar_DbSup

Hi,

 

Actually you do not need to set the URL before doing login, actually this URL acts as a endpoint URL of our http request in the connection established

This is basically returned after doing the login (i.e loginResult =conn.login(usrname,password)). you can see that by printing that in system debug.

 

After doing the Login you now need to set them. As follows

 

   conn.endpoint_x =loginResult.ServerUrl;

  

Now you can access the connection variable conn, to do query and create .

 

Use the below code as reference

 

=================IN Salesforce===============================================

 

 

   partnerSoapSforceCom.soap conn= new partnerSoapSforceCom.soap();

            conn.SessionHeader = new partnerSoapSforceCom.SessionHeader_element ();

            partnerSoapSforceCom.LoginResult loginResult = new partnerSoapSforceCom.LoginResult();

            partnerSoapSforceCom.LoginScopeHeader_element ls=new partnerSoapSforceCom.LoginScopeHeader_element();

          //  ls.portalId='00D60000000bvVs';

            ls.portalId='060800000000sdR';

         

            ls.organizationId='00D9000000dfvVp';

            conn.LoginScopeHeader=ls;

            loginResult =conn.login(usrname,password);

            conn.endpoint_x =loginResult.ServerUrl;

            conn.Sessionheader.sessionid = loginResult.sessionid;

  

    system.debug('____________Login Successful_______________________'+loginResult);

            system.debug('_______________Session__ID_________________________'+conn.Sessionheader.sessionid);

            system.debug('___________conn.endpoint_x_____________________'+conn.endpoint_x);

        

       

        List<sobjectPartnerSoapSforceCom.sObject_x> ConObjects=new List<sobjectPartnerSoapSforceCom.sObject_x>();

        sobjectPartnerSoapSforceCom.sObject_x c1;

        for(Contact con:ct)

        {

        c1=new sobjectPartnerSoapSforceCom.sObject_x();

        c1.type_x='Contact_Clone__c';

        c1.Name=con.FirstName;

        c1.LastName=con.LastName;

        c1.Email=con.Email;

        c1.Languages=con.Languages__c;

      //  c1.Code='Helloo';

      //  sobjectPartnerSoapSforceCom.sObject_x[] ConObjects=new sobjectPartnerSoapSforceCom.sObject_x[]{c1};

        ConObjects.add(c1);

        }

        partnerSoapSforceCom.SaveResult[] lsr=conn.create(ConObjects);

 

 

 

 

======================IN DOT NET================================================

 

  

  

   Partner.SforceService sf = new SforceService();

            Partner.LoginScopeHeader lh = new LoginScopeHeader();

            lh.portalId = "060800000000sdR";

            lh.organizationId = "00D9000000dfvVp";

            sf.LoginScopeHeaderValue = lh;

            Partner.LoginResult lr = new Partner.LoginResult();

 

            lr = sf.login(username, password);

            sf.Url = lr.serverUrl;

            //  sf.SessionHeaderValue.sessionId = lr.sessionId;

            SessionHeader sh = new SessionHeader();

            sh.sessionId = lr.sessionId;

            sf.SessionHeaderValue = sh;

            session = lr.sessionId;

 

            Response.Write(" Login Successsful <br/>" );

            blnCheck1 = true;

            // string strQuery = "select id, Title, Description, FileType from ContentVersion";

            // string strQuery = "select id from OAuth2_0__c";

            string strQuery = "Select Id, Name,TagModel from ContentWorkspace";

 

            QueryResult qr = sf.query(strQuery);

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.