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
visualforce_devvisualforce_dev 

Solved! login problem

I downloaded metadata from my dev instnce and developed code on that(java code to create objects), now i am trying to use another login, but i ma not able to use my metadata for that login..

 

 

any suggestion to overcome this, its very urgent...

 

i am getting the following error

 

 

 

INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: 511800D80000000LvBm!AQQAQB3QNt1eH_4MOjT9PEAvJzrqfBdQHHNeD1XCpTmp3NauNvj95SxX_COjVj570Fek0b4VbjCSRNTdTZibUpYDw0GnqPNE

Message Edited by visualforce_dev on 02-09-2009 10:47 PM
Best Answer chosen by Admin (Salesforce Developers) 
visualforce_devvisualforce_dev

Its solved

 

set url as

 

SforceServiceLocator sf=new SforceServiceLocator();
            sf.setSoapEndpointAddress("https://test.salesforce.com/services/Soap/u/14.0");

 

 

Thanks to all.

All Answers

NaishadhNaishadh

It should work. Please post your code. 

 

 

visualforce_devvisualforce_dev

 

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.io.File;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import java.lang.System;
import java.util.Collections;
import java.lang.Object;
import java.io.InputStream;
import java.io.FileInputStream;

import com.sforce.soap._2006._04.metadata.Encoding;
import com.sforce.soap._2006._04.metadata.LogInfo;
import com.sforce.soap._2006._04.metadata.Metadata;
import com.sforce.soap._2006._04.metadata.ObjectNameCaseValue;
import com.sforce.soap._2006._04.metadata.CustomField;
import com.sforce.soap._2006._04.metadata.CustomObject;
import com.sforce.soap._2006._04.metadata.CustomObjectTranslation;
import com.sforce.soap._2006._04.metadata.TabVisibility;
import com.sforce.soap._2006._04.metadata.WebLink;
import com.sforce.soap._2006._04.metadata.WebLinkAvailability;
import com.sforce.soap._2006._04.metadata.WebLinkDisplayType;
import com.sforce.soap._2006._04.metadata.WebLinkPosition;
import com.sforce.soap._2006._04.metadata.WebLinkTranslation;
import com.sforce.soap._2006._04.metadata.WebLinkType;
import com.sforce.soap._2006._04.metadata.WebLinkWindowType;
import com.sforce.soap._2006._04.metadata.CustomPageWebLink;
import com.sforce.soap._2006._04.metadata.CustomPageWebLinkTranslation;
import com.sforce.soap._2006._04.metadata.MetadataBindingStub;
import com.sforce.soap._2006._04.metadata.MetadataServiceLocator;
import com.sforce.soap._2006._04.metadata.MetadataService;
import com.sforce.soap._2006._04.metadata.MetadataPortType;
import com.sforce.soap._2006._04.metadata.ValidationRule;
import com.sforce.soap._2006._04.metadata.ValidationRuleTranslation;
import com.sforce.soap._2006._04.metadata.AsyncResult;
import com.sforce.soap._2006._04.metadata.Picklist;
import com.sforce.soap._2006._04.metadata.WorkflowActionType;
import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.Soap;
import com.sforce.soap.enterprise.SforceServiceLocator;
import com.sforce.soap.enterprise.SforceService;
import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.enterprise.fault.InvalidFieldFault;
import com.sforce.soap.enterprise.fault.InvalidSObjectFault;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.MalformedQueryFault;
import com.sforce.soap.enterprise.fault.UnexpectedErrorFault;
import com.sforce.soap.enterprise.SessionHeader;
import com.sforce.soap._2006._04.metadata.*;
import jxl.*;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import common.Logger;

/*----------------------------------CLASS STARTS-------------------------------------------------------------*/

public class demoFeb3 {

// public SoapBindingStub binding;
private SforceService service;
private LoginResult lr;
private static final String prodURL = "https://www.salesforce.com/services/Soap/u/7.0";
static BufferedReader rdr = new BufferedReader(
new java.io.InputStreamReader(System.in));

/*--------------------------------------CONSTRUCTOR---------------------------------------------------------*/

public demoFeb3() {
// empty constructor
}

/*------------------------------------------MAIN METHOD-----------------------------------------------------*/

public static void main(String[] args) {
demoFeb3 exercises = new demoFeb3();

exercises.login();
}

/*-----------------------------------------------------------------------------------------------*/

/*------------------for user input-------------------------*/

String getUserInput(String prompt) {
System.out.print(prompt);
try {
return rdr.readLine();
} catch (IOException ex) {
System.out.println(ex);
return null;
}
}

/* ------------------for user input------------------------- */

/*------------------------------------------LOGIN-----------------------------------------------------*/

private boolean login() {
LoginResult loginResult = null;
SoapBindingStub sfdc = null;

try

{
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "xxx");
System.setProperty("http.proxyPort", "8080");
System.setProperty("http.proxyUser", "aaaa");
System.setProperty("http.proxyPassword", "xcvbbn");
System.out.println("Logging into Salesforce.....");
// Create binding object
sfdc = (SoapBindingStub) new SforceServiceLocator().getSoap();
sfdc.setTimeout(1000000);
// login

/*------------------for user input-------------------------*/


String username = getUserInput("Enter user name: ");
String password = getUserInput("Enter password: ");
loginResult = sfdc.login(username,password);

/*------------------for user input-------------------------*/

//loginResult = sfdc.login("username",
// "password");

System.out.println("Login successful!!!!!.");
System.out.println("\nThe session id is: "
+ loginResult.getSessionId());
System.out.println("\nThe new server url is: "
+ loginResult.getServerUrl());

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

// Create a new session header object and set the session id to that
// returned by the login

SessionHeader sh = new SessionHeader();
sh.setSessionId(loginResult.getSessionId());
sfdc.setHeader(new SforceServiceLocator().getServiceName()
.getNamespaceURI(), "SessionHeader", sh);

MetadataBindingStub msfdc = null;

try {

msfdc = (MetadataBindingStub) new MetadataServiceLocator()
.getMetadata();
msfdc.setTimeout(1000000);
msfdc.setHeader(new MetadataServiceLocator().getServiceName()
.getNamespaceURI(), "SessionHeader", sh);

System.out.println("inside try ..statement 1");


/*------------------------------OBJECT CREATION---------------------------------*/

String objname = "myobject";
objname=objname.replace(" ","_");

CustomObject co = new CustomObject();

System.out.println("Setting API name for the object");
co.setFullName(objname + "__c");

String objdescription = "desc";
co.setDescription(objdescription);


CustomField nf = new CustomField();

String recfldname = "namefld";
nf.setLabel(recfldname);
co.setNameField(nf);

String recfldtype = "Text";
if (recfldtype.equals("Text"))
nf.setType(FieldType.Text);
else if (recfldtype.equals("Auto Number"))
{ nf.setType(FieldType.AutoNumber);
String recfldsrtnum = "1";
int srtpt = Integer.parseInt(recfldsrtnum);
nf.setStartingNumber(srtpt);
}
String Name = "Name";

AsyncResult[] ars1 = msfdc.create(new Metadata[] { co });
System.out.println("Object Created " + co.getFullName());

} catch (Exception ex) {
System.out.println("An unexpected error has occurred."
+ ex.getMessage());
return false;
}

}

}

 Hi,

 

here is my code, i changed some parts like proxy and login details , but its wht all about..hope u can help me out ..

thanks in advance

 

NaishadhNaishadh

Here is the code.

 

import javax.xml.rpc.ServiceException;

import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.SforceServiceLocator;
import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.enterprise.fault.ExceptionCode;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sungard.constant.IPropertyNames;

public class Testing {   
   
    private SoapBindingStub binding = null;
   
    public static void main(String[] args) {
       
        Testing t = new Testing();
       
        t.init();
    }
   
    public void init() {
       
        //first user
        run("username","password");
        //second user
        run("username1","password1");
       
    }
   
    private void run(String userName,String passwd) {
        System.setProperty(IPropertyNames.HTTP_PROXY_HOST, "255.255.255.255");
        System.setProperty(IPropertyNames.HTTP_PROXY_PORT, "8000");
       
        try {
            binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // Time out after a milliseconds
        binding.setTimeout(60000);
        // Test operation
        LoginResult loginResult;

        try {
            loginResult = binding.login(userName, passwd);
           
            System.out.println(loginResult);
           
            System.out.println(loginResult.getSessionId());
        } catch (LoginFault ex) {
            System.out.println(ex);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}
 

visualforce_devvisualforce_dev

Thanks for the help.

 

If I am correct , think this is for different users in same instance. Our problem is with different instances.

 

With metadta wsdl of Instance A I am able to login and create objects in A, but for instance B I have to download the metadata and compile it again

 

Both A and B are developer instance.

 

 

NaishadhNaishadh
If both the instance are different then use partner wsdl in place of enterprise wsdl.
Message Edited by Naishadh on 02-09-2009 05:42 AM
visualforce_devvisualforce_dev

We tried partner wsdl also. it s giving the same error.

 Actually we have problem with metadata wsdl not with enterprise wsdl.

 

 

SuperfellSuperfell
You need to set the endpointUrl of the metadata stub based on the metadataServerUrl returned by the login call.
visualforce_devvisualforce_dev

We tried it but getting the same error

 

Pls find the code, and correct if we r wrong

sfdc._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl()); // Create a new session header object and set the session id to that // returned by the login SessionHeader sh = new SessionHeader(); sh.setSessionId(loginResult.getSessionId()); sfdc.setHeader(new SforceServiceLocator().getServiceName() .getNamespaceURI(), "SessionHeader", sh); MetadataBindingStub msfdc = null; try { msfdc = (MetadataBindingStub) new MetadataServiceLocator() .getMetadata(); msfdc.setTimeout(1000000); sh.setSessionId(loginResult.getSessionId()); msfdc._setProperty(MetadataBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getMetadataServerUrl()); msfdc.setHeader(new MetadataServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", loginResult.getSessionId());

 


 

visualforce_devvisualforce_dev

Thanks Simon!!!!! Its working, it was my mistake in the code that i passed id instd of header :-)

 

Thanks a lot for your help

visualforce_devvisualforce_dev

its working only for developer instances,

 

we tried with one test envt. its giving error message , not able to login..

 

 how can we set url for different instances like pilot,test,developer etc..

Message Edited by visualforce_dev on 02-09-2009 09:08 PM
visualforce_devvisualforce_dev

Its solved

 

set url as

 

SforceServiceLocator sf=new SforceServiceLocator();
            sf.setSoapEndpointAddress("https://test.salesforce.com/services/Soap/u/14.0");

 

 

Thanks to all.

This was selected as the best answer
NaishadhNaishadh
Please put your final solution and mark it as solved so that it will be helpful to other.
Message Edited by Naishadh on 02-09-2009 11:46 PM
anu08anu08

Hi All,

 

How to Create Custom Object From Java ,Here taken Metadata.wsdl file but LoginResult Class generated from enterprise wsdl how to login into SF & Create Custom app

 

Abovesomew written code for creating custom app ,he was took bodh wsdl's ,can u please tell how ur integrating login as well as creting app........? 

 

thanks

vasu