You need to sign in to do that
Don't have an account?
AWilkinson
Adding Contacts
Is there a way to add contacts through the java api coding?
if so, could you post the coding to perform the action?
thank you.
Message Edited by AWilkinson on 08-01-2003 08:35 AM
Hi AWilkinson,
You can find sample code for inserting data on the sforce website at http://www.sforce.com/us/resources/code.jsp.
The pertinent code is excerpted below:
org.w3c.dom.Element value = null;
salesforce.MapEntry[] record = new salesforce.MapEntry[2];
record[1] = new salesforce.MapEntry();
record[1].setKey("industry");
record[1].setValue("Software");
record[0] = new salesforce.MapEntry();
record[0].setKey("name");
record[0].setValue("newaccount");
value = (org.w3c.dom.Element)binding.insert("account", record);
Download the sample to obtain context for this snippet.
in salesforce.com I would like to click on the accounts tab, select the account and within the account will be contacts under the account information, I believe I need to write a new struct to do this but I just wanted to make sure there was no other way. thank you
Hi AWilkinson,
The contact contains a field called accountID. If you inspect the properties of this field you will see a property called "referenceTo". Under this property it will have a value of account. So to relate a contact to an account you will need to set this field to the account id that you want to relate the contact to. This means that you need to obtain the account id either as a result of a query or an insert. All inserts work the same way. You build the struct using the pertinent fields for the entity that you are inserting. This is referred to as a record. You call the insert method and pass the method the name of entity you are inserting and the record that describes the entity.
So, at a minimum for a standard contact (one that has not been modified from the original provisioning), you would need the following:
org.w3c.dom.Element value = null;
salesforce.MapEntry[] record = new salesforce.MapEntry[1];
record[0] = new salesforce.MapEntry();
record[0].setKey("lastName");
record[0].setValue("Wilkinson");
value = (org.w3c.dom.Element)binding.insert("contact", record);
if (outputNode != null) System.out.println(" referenceTo: " + outputNode.getNodeValue());
else System.out.println(" referenceTo: (na)");
this part was in the main Demo page, is this what you were referring to?