Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Reading and Editing a Contact Item

From Wiki
Jump to: navigation, search

This article shows how to read and edit a contact item using Symbian C++.

Article Metadata
Platform Security
Capabilities: WriteUserData
Keywords: CContactDatabase
Created: vvsnaresh (21 Mar 2007)
Last edited: vineet.jain (15 Feb 2012)

Opening a contact for reading

Whenever a contact item is opened for editing, it is locked to prevent simultaneous edits from other clients of the Contacts Model and it remains locked until it is either committed or closed. Therefore, unless you wish to edit a contact item, the item should be opened as read only with the CContactDatabase::ReadContactL() or ReadContactLC() function.

The following code shows how to read information from a contact, in this case the "own card" contact:

// Open the default contacts database:
CContactDatabase* contactsDb = CContactDatabase::OpenL();
// Get the ID of the own card and open the contact:
TContactItemId ownCardId = contactsDb->OwnCardId();
if (ownCardId == KNullContactId ) User::Leave(KNullContactId ); //Own card may not be set
CContactItem* ownCard = contactsDb->ReadContactL(ownCardId);
TInt count = ownCard->CardFields().Count();
CleanupStack::PopAndDestroy(2); // ownCard, contactsDb

Opening a contact for editing

The following code example shows how to open a contact for editing. The fields within a CContactItemFieldSet are indexed and the index of a particular field may be obtained by calling the CContactItemFieldSet::Find() function with the UID of the field that you are searching for. In the following example, the index that represents the forename field of the contact is obtained and this is subsequently used to modify the text in the field. Once editing the contact has been completed, the changes can be committed to the database by calling the CContactDatabase::CommitContactL() function. The CContactDatabase::CloseContactL() function closes the contact without saving the changes.

ownCard = contactsDb->OpenContactL(ownCardId);
TInt index = ownCard->CardFields().Find(KUidContactFieldGivenName);
if(index != KErrNotfound) {
CleanupStack::PopAndDestroy(2); // ownCard contactsDb
This page was last modified on 15 February 2012, at 09:52.
32 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.