You need to sign in to do that
Don't have an account?

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
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
It should work. Please post your code.
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
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());
}
}
}
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.
We tried partner wsdl also. it s giving the same error.
Actually we have problem with metadata wsdl not with enterprise wsdl.
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());
Thanks Simon!!!!! Its working, it was my mistake in the code that i passed id instd of header :-)
Thanks a lot for your help
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..
Its solved
set url as
SforceServiceLocator sf=new SforceServiceLocator();
sf.setSoapEndpointAddress("https://test.salesforce.com/services/Soap/u/14.0");
Thanks to all.
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