When creating a contact record, you need to further specify the type of contact you are creating. This is done through the contact argument. To specify a person type contact, pass in a contact created through the PersonCreate object. To specify a company type contact, pass in a contact created through the CompanyCreate object. When you instantiate the PersonCreate or CompanyCreate objects, they are used to store contact record properties. Both the PersonCreate and CompanyCreate objects extend ContactCreate, an abstract class.
protected ContactRepository contactRepository;
PersonCreate person = new PersonCreate();
//firstName is a required field
person.setFirstName("John");
//lastName is a required field
person.setLastName("Doe");
ContAddressCreate address = new ContAddressCreate();
address.setTypeUniqueKey("HOME");
//where the typeUniqueKey value, "HOME", is an existing item's Tree Position value under the system lookup table, Address Type
address.setStreet("2468 Washington Ave.");
address.setCity("Los Angeles");
address.setState("CA");
address.setPostalCode("90026");
person.getAddressCreates().add(address);
String uniqueKey = contactRespository.insertContact(person);
//when you create a contact, the record's unique key is returned
//alternatively you could create a company contact like contactRespository.insertContact(company)
//where company would be an instance of the CreateCompany object
protected ContactRepository contactRepository;
CompanyCreate company = new CompanyCreate();
//name is a required field
company.setName("ACME Inc.");
//taxNumber is used to identify vendor contacts if you are using CSM/Collaborati
company.setTaxNumber("0112498531");
String uniqueKey = contactRespository.insertContact(company);
//when you create a contact, the record's unique key is returned
protected ContactRepository contactRepository;
PersonCreate person = createPerson();
String personUniqueKey = contactRepository.insertContact(person);
private PersonCreate createPerson() {
String firstName = "first" + new Date().getTime();
PersonCreate person = new PersonCreate();
person.setFirstName(firstName);
person.setBirthdate(Calendar.getInstance().getTime());
ContAddressCreate address = new ContAddressCreate();
address.setTypeUniqueKey("ADDR_HOME");
address.setCity("Portland");
address.setState("OR");
address.setCountryCodeUniqueKey("COUN_0002");
person.getAddressCreates().add(address);
Category cat = new Category();
//the next two lines identify a category and then add the category to the contact record
cat.setUniqueKey("CONT_EXTE");
person.getCategories().add(cat);
Category cat2 = new Category();
person.getCategories().add(cat2);
cat2.setUniqueKey("CONT");
//the next four lines create a placeholder for an existing Boolean custom field, identify the known custom field name (synched), set the custom field value, and add the custom field placeholder to its parent category
BooleanCustomField synched = new BooleanCustomField();
synched.setFieldName("synched");
synched.setValue(true);
cat2.getBooleanCustomFields().add(synched);
TextCustomField primaryLanguage = new TextCustomField();
primaryLanguage.setFieldName("primaryLanguage");
primaryLanguage.setValue("Englishe US");
cat2.getTextCustomFields().add(primaryLanguage);
return person;
}