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

get metadata for all objects C# code
I am trying to get metadata for all objects using Partner API,
got some samples in internet for calling binding .describeGlobal();
but when I am calling describeGlobal its expecting SessionHeader, CallOptions, PakageVersions[]
also there is no URL property for my binding object , and If I pass nulls for binding .describeGlobal(); instead of parameters, Giving following exception
UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService
Please somebody give me a code snippet to get Metada for all objects using partner API, I wanna use partner API because I want my code to work for any organization without any change.
The initial login request will be passed to a login server in salesforce, but future requests will have to be directed to your instance of salesforce. This instance URL is the destination URL.
Both of these (Session ID and Destination URL) must be set in the SforceService. This ensures all future queries hit the destination URL.
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
Hi ,
I am using same steps, but there is no option to set returned URL . Please check my code and if there is any working code please suggest me...
public partial class Form1 : Form
{
//EnterpriseService.SoapClient loginClient;
private partner.SoapClient binding;
private partner.LoginResult lr;
//private SaveExpenditureWebServiceService myBinding = new SaveExpenditureWebServiceService();
public Form1()
{
InitializeComponent();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
//use default binding and address from app.config
//using (EnterpriseService.SoapClient loginClient = new EnterpriseService.SoapClient("Soap"))
using (partner.SoapClient binding = new partner.SoapClient("Soap"))
{
//set account password and account token variables
string sfdcPassword = "pwd$";
string sfdcToken = "Zpm2Mmdi5Ni0nQqRedERYX6tZ";
//set to Force.com user account that has API access enabled
string sfdcUserName = "andy@hotmail.com";
//create login password value which combines password and token
string loginPassword = sfdcPassword + sfdcToken;
binding.ClientCredentials.UserName.UserName = sfdcUserName;
binding.ClientCredentials.UserName.Password = sfdcPassword;
//call Login operation from Enterprise WSDL
lr =
binding.login(null, null, //LoginScopeHeader
sfdcUserName, //username
loginPassword); //password
//get response values
string sessionId = lr.sessionId;
string serverUrl = lr.serverUrl;
//print response values
Console.WriteLine(string.Format("The session ID is {0} and server URL is {1}", sessionId, serverUrl));
Console.WriteLine("");
Console.WriteLine("Press [Enter] to continue ...");
Console.ReadLine();
//binding = new partner.SoapClient("SoapBinding2");
describeGlobal();
}
}
private void describeGlobal()
{
partner.SessionHeader sheader = new partner.SessionHeader();
sheader.sessionId = lr.sessionId;
binding.Endpoint.ListenUri = new Uri(lr.metadataServerUrl);
describeGlobalRequest dgrq = new describeGlobalRequest(sheader, null, null);
//dgrq.SessionHeader = sheader;
partner.DescribeGlobalResult dgr = binding.describeGlobal(sheader, null, null);
//Loop through the array echoing the object names to the console
StringBuilder sb = new StringBuilder();
for (int i = 0; i < dgr.sobjects.Length; i++)
{
sb.Append(dgr.sobjects[i].name + " , ");
}
MessageBox.Show(sb.ToString());
}
The Binding is going out of scope after you login. After you leave this code, the object is out of scope and it isn't the same one as your class level variable.
Use only the class level varible: