Show/Hide Toolbars

When updating contacts, use the PersonUpdate or CompanyUpdate objects as parameters to the ContactRepository updateContact method.

Some data associated with a contact record is stored through separate objects. For example, a contact's rates are added through the ContRateCreate object. In addition, contact rates are updated through the ContRateUpdate object. The same concepts apply to a contact's mailing addresses (ContAddressCreate), email addresses (ContEmailAddressCreate), internet addresses (ContInetAddressCreate), phone numbers (ContPhoneNumberCreate), fax numbers (ContFaxNumberCreate), relations (ContRelationCreate), skills (ContSkillCreate), and territories (ContTerritoryCreate).

To delete certain data associated with a contact record (for example, rates, mailing addresses, email addresses, internet addresses, phone numbers, fax numbers, relations, skills, territories), use the following:

PersonUpdate.getRateDeleteUniqueKeys().add(newItem);

where newItem is the unique key of the rate to delete. Note that you need to repeat the line above for each rate to delete.

Also see the code snippets under Creating Contacts for comments about required contact fields.

Code Snippet for updating existing properties

protected ContactRepository contactRepository;

//for this example, it is assumed that you already know the target contact record's unique key (where uniqueKey is a String variable)

PersonUpdate personUpdate = new PersonUpdate();

personUpdate.setUniqueKey(uniqueKey);

personUpdate.setLastName("Doe II");

contactRepository.updateContact(personUpdate);

Code Snippet for clearing existing property values

protected ContactRepository contactRepository;

//for this example, it is assumed that you already know the target contact record's unique key (where uniqueKey is a String variable)

PersonUpdate personUpdate = new PersonUpdate();

personUpdate.setUniqueKey(uniqueKey);

personUpdate.getClearedProps().addAll(getPropertiesToClear());

private List<String> getPropertiesToClear() {

List<String> properties = new List<String>();

properties.add("firstName");

properties.add("lastName");

properties.add("address.type");

properties.add("address.state");

return properties;

}

Code Snippet for adding contact rates

protected ContactRepository contactRepository;

//for this example, it is assumed that you already know the target contact record's unique key (where uniqueKey is a String variable)

PersonUpdate personUpdate = new PersonUpdate();

personUpdate.setUniqueKey(uniqueKey);

ContRateCreate rate = new ContRateCreate();

Date today = new Date();

rate.setFirstEffectiveDate(today);

rate.setLastEffectiveDate(new Date(today.getTime() + 100000));

rate.setRate(new BigDecimal(20));

rate.setTaskCategoryCode("TASK_DEFA");

personUpdate.getRateCreates().add(rate);

contactRepository.updateContact(personUpdate);

Code Snippet for updating a contact's custom field values

protected ContactRepository contactRepository;

//for this example, it is assumed that you already know the target contact record's unique key (where uniqueKey is a String variable)

PersonUpdate personUpdate = new PersonUpdate();

personUpdate.setUniqueKey(uniqueKey);

Category cat = new Category();

personUpdate.getCategories().add(cat);

//The category should already exist. You should get its unique key (tree position) from TeamConnect.

cat.setUniqueKey("CONT_EXTE");

TextCustomField primaryLanguage = new TextCustomField();

cat.getTextCustomFields().add(primaryLanguage);

primaryLanguage.setFieldName("primaryLanguage");

primaryLanguage.setValue("Chinese PRC");

contactRepository.updateContact(personUpdate);