Show/Hide Toolbars

Use ContactService when working with contact records.

Whenever a Service operation requires ContactService, set up ContactService using the following code:

ContactService contactService = platform.getContactService();

Creating a Person Contact

The following sample creates a person contact record. During contact creation, you can use API interface methods to set objects in the contact record, including the contact address.

Person personContact = ContactService.newPerson("Bob", "Dole");

Address address = person.addAddress("ADDR_HOME");

address.setStreet("1234 Fake St.");

address.setCity("Austin");

address.setState("TX");

address.setPostalCode("78704");

address.setCountry("USA");

Creating a Company Contact

The following sample creates a company contact record. During contact creation, you can use API interface methods to set objects in the contact record, including the contact address and email.

Company companyContact = ContactService.newCompany("myLittleCompany");

Address address = company.addAddress("ADDR_BUS1");

address.setStreet("1234 Fake St.");

address.setCity("Austin");

address.setState("TX");

address.setPostalCode("78704");

address.setCountry("USA");

Email email = company.addEmail("MAIL_BUS1", "you@yourcompany.com");

Updating a Contact

The following sample updates a contact record. When you update a contact, you can use API interface methods to update objects in the contact record, including the contact fax number, email, and web address.

//Adding or updating a business fax number

FaxNumber faxNumber = person.addFaxNumber("FAXX_BUS1", "5123827322");

 

//Adding or updating a personal email

Email email = person.addEmail("MAIL_PER1", "you@yourcompany.com");

 

//Adding or updating a mobile phone number

PhoneNumber phoneNumber = person.addPhoneNumber("PHON_MOBI", "5123827322");

 

//Adding or updating a business web address

InternetAddress internetAddress = person.addInternetAddress("INET_BWEB", "www.mitratech.com");

 

//Adding or updating a default skill

Skill skill = person.addSkill("SKIL_DEFA", 2);

Reading a Contact

The following sample reads a contact record. When you read a contact, you retrieve the contact so that you can make changes to it, such as updating or deleting it.

//The id initialized here is the id of an existing person contact

long personId = 49L;

Person personContact = ContactService.readPerson(personId);

//The id initialized here is the id of an existing company contact

long companyId= 23L;

Company companyContact = ContactService.readCompany(CompanyId);

Deleting a Contact

The following sample deletes a contact record. When you delete a contact, if the contact is associated with a user or any other object, remove the association first.

ContactService.delete(personContact);

ContactService.delete(companyContact);