I've read a lot about upserting into Salesforce using the API, though it seems to get a strict on what fields you can use as the 'primary key' when upserting. Salesforce asks that you use an ExternalIDField, which must be a custom field and you must specify it inside salesforce. Well thats not much use and I don't really have time to fix this. Instead you can use the lookupid attribute of default fields. this means, in effect that you could do a call like this:
salesforce.sObject[] objList;
salesforce.Contact connyhuq = new salesforce.Contact();
connyhuq.Title = "Ms.";
connyhuq.HEAPS_Interest__c = "Yes";
connyhuq.Email = "chuq@huqqers.org.uk";
connyhuq.LastName = "Kemp";
objList = new salesforce.sObject[] { connyhuq };
salesforce.UpsertResult[] upResult = binding.writeData("Email", objList);
What we have done is made the Email address the primary key on this upsert. I wish to make the Id of the object the key field but it complains that we do not have access rights to change this. I doubt there is anything you can do about this. So then I decided to try and composite key the fields and create a unqiue key for each entry, I don't have any good externalIDfields yet. However, the upsert routine only lets you use one field. Looks like I need to go into Salesforce to create the composite key field manually.
Monday, 27 April 2009
Monday, 6 April 2009
C# Salesforce Development
You will need the following:
{
salesforce.SforceService binding = new salesforce.SforceService();
try
{
salesforce.LoginResult lr = binding.login(sforceUsername, sforcePassword);
binding.SessionHeaderValue = new salesforce.SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
binding.Url = lr.serverUrl;
binding.Url = lr.serverUrl;
}
catch (Exception)
{ }
return binding;
}
this will connect you to salesforce provided you have the correct username and password. If we can log in we probably want to log out as well.
public void logOut(Page pg)
{
pg.Session.Abandon();
pg.Response.Write("");
}
By calling this function we'll terminate the current session.
- Visual Web Developer Express Edition
- Salesforce Developer Account
- WSDL generated by the salesforce account (http://www.salesforce.com/us/developer/docs/api_meta/index.htm)
- in VWD create a website, not a web project (this si a personal preference)
- Website -> Add Web Reference -> URL = your Enterprise.wsdl
- web reference name = "salesforce"
- Add Reference
- in your App_Code folder create a class called sfconnector.cs
{
salesforce.SforceService binding = new salesforce.SforceService();
try
{
salesforce.LoginResult lr = binding.login(sforceUsername, sforcePassword);
binding.SessionHeaderValue = new salesforce.SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
binding.Url = lr.serverUrl;
binding.Url = lr.serverUrl;
}
catch (Exception)
{ }
return binding;
}
this will connect you to salesforce provided you have the correct username and password. If we can log in we probably want to log out as well.
public void logOut(Page pg)
{
pg.Session.Abandon();
pg.Response.Write("");
}
By calling this function we'll terminate the current session.
Subscribe to:
Posts (Atom)