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
ParamParam 

getting error when i am trying to access any object

Hi

i am getting error when i am trying to access any object. the error is

Destination URL not reset. The URL returned from login must be set in the SforceService

 

i have a login class and a method in it where i am login and setting the header.

 

    public void getLogin() throws ServiceException, ApiFault, RemoteException, MalformedURLException {
           
        SforceService service = new SforceServiceLocator();
        sfdc = (SoapBindingStub)service.getSoap();

        System.out.println("Connecting to: " + service.getSoapAddress());
       
     try{  
                       
        // login
            LoginResult loginResult = sfdc.login("username", "password");
System.out.println("Logged in");           
        // Reset the SOAP endpoint to the returned server URL
            sfdc = (SoapBindingStub) new SforceServiceLocator().getSoap(new java.net. URL(loginResult.getServerUrl()));
        // Create a new session header object
        // add the session ID returned from the login
            _SessionHeader sh = new _SessionHeader();
            sh.setSessionId(loginResult.getSessionId());
            sessionID = loginResult.getSessionId();
            serverURL = loginResult.getServerUrl();
        // Set the session header for subsequent call authentication
            sfdc.setHeader(service.getServiceName().getNamespaceURI(),"SessionHeader", sh);
System.out.println("get Session Id " + loginResult.getSessionId()); 
System.out.println("get user Id " + loginResult.getUserId());
System.out.println("get user Id " + loginResult.getServerUrl());   

     }catch(Exception e ){System.out.println("error in login class " + e);}      
        }

 

so when i am calling this method in another class i am getting this error.

 

so could anybody help me on this.

 

thank u

 

SuperfellSuperfell
You didn't change the endpoint URL, see the samples in the docs.
ParamParam

Hi Simon

thanks for replying

i have gone through the doc. it says that i have to set the  ENDPOINT_ADDRESS_PROPERTY.

so i added

 sfdc._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,loginResult.getServerUrl()); 

in the method in the login class. the code for login is

 

        SforceService service = new SforceServiceLocator();

        sfdc = (SoapBindingStub)service.getSoap();

      

     try{  

                       

        // login

            LoginResult loginResult = sfdc.login("psohal@njtransit.com", "nanki");

 

        sfdc._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,loginResult.getServerUrl());   

 

        // Reset the SOAP endpoint to the returned server URL

            sfdc = (SoapBindingStub) new SforceServiceLocator().getSoap(new java.net. URL(loginResult.getServerUrl()));

        // Create a new session header object

        // add the session ID returned from the login

            _SessionHeader sh = new _SessionHeader();

            sh.setSessionId(loginResult.getSessionId());

            sessionID = loginResult.getSessionId();

            serverURL = loginResult.getServerUrl();

        // Set the session header for subsequent call authentication

            sfdc.setHeader(service.getServiceName().getNamespaceURI(),"SessionHeader", sh);

 

     }catch(Exception e ){System.out.println("error in login class " + e);} 

i am still getting the same error:

Destination URL not reset. The URL returned from login must be set in the SforceService

could u please help me

thank u

SuperfellSuperfell
and are you sure the following code uses the sfdc instance you creted in the login method ?
ParamParam

Hi

this is my Login class

public class Login_SupportForce

{

    public SoapBindingStub sfdc = null;

    private String sessionID;

                private String serverURL;

   // public void getLogin() throws ServiceException, ApiFault, RemoteException, MalformedURLException {

     public boolean getLogin() throws ServiceException, ApiFault, RemoteException, MalformedURLException {

           

        SforceService service = new SforceServiceLocator();

        sfdc = (SoapBindingStub)service.getSoap();

 

     try{  

                        

        // login

            LoginResult loginResult = sfdc.login("psohal@njtransit.com", "nanki");

 

        sfdc._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,loginResult.getServerUrl());   

 

        // Reset the SOAP endpoint to the returned server URL

            sfdc = (SoapBindingStub) new SforceServiceLocator().getSoap(new java.net. URL(loginResult.getServerUrl()));

        // Create a new session header object

        // add the session ID returned from the login

            _SessionHeader sh = new _SessionHeader();

            sh.setSessionId(loginResult.getSessionId());

            sessionID = loginResult.getSessionId();

            serverURL = loginResult.getServerUrl();

        // Set the session header for subsequent call authentication

            sfdc.setHeader(service.getServiceName().getNamespaceURI(),"SessionHeader", sh);

 

     }catch(Exception e ){System.out.println("error in login class " + e);}    

    

     return true;

        }

}

 

 

I am calling this Login_SupportForce call in Cu_Form_Servlet class. The code is

 

public class Cu_Form_Servlet extends HttpServlet {

 

    public void doPost(HttpServletRequest request, HttpServletResponse response)    throws IOException, ServletException

    {

 

        try{

// Create binding object for sforce

            SoapBindingStub sfdc = (SoapBindingStub) new SforceServiceLocator().getSoap();

 

 Login_SupportForce ls = new Login_SupportForce();

 ls.getLogin();

 System.out.println("get login true or false -- "  + ls.getLogin());

 System.out.println("value of _set server property " + sfdc._getProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY));

 

      QueryResult queryResult = null;

 System.out.println("after query result");    

      

      ID case_Id = null;

        // Invoke the query call and save the results

System.out.println("before query result");       

        queryResult = sfdc.query("select casenumber,subject,ContactId,OwnerId,RecordTypeId,type,Id from Case where casenumber='00004660'");  (getting error here)

 

what have to do or what wrong i am doing here.

SuperfellSuperfell
doPost has its own instance of the stub, as does the login class, so the changes made to the stub in the login class won't affect the stub made to do the query call.
darozdaroz
FYI - You might want to edit your posts and remove your login/password from the code.
ParamParam

Hi Simon

thank u for ur help. i got it

thanks again

 

ParamParam

Hi

thank u for ur help

i got it