AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    Administration interface basicsDevelopers and adminsBusiness usersChangelogGlossary
  • Guides
    Welcome to Xperience by KenticoAdministration interface basicsCustomer journeysDigital marketingConfigurationDevelopmentArchitectureUpgrade to Xperience by Kentico
  • Training
    For AdminsFor Business usersFor DevelopersFor Solution architects
  • API Examples
    ConfigurationContent managementDevelopmentDigital marketing
  • Changelog
    Documentation updatesSecurity advisories
  1. Home
  2. Digital marketing
  3. Contacts

Contacts


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Dependency injection
    • Initialize required services
  • Contacts
    • Get the current contact
    • Create contacts
    • Update contacts
    • Update multiple contacts
    • Delete contacts
    • Delete contacts in bulk

Dependency injection

Initialize required services

C#
// Initializes all services and provider classes used within
// the API examples on this page using dependency injection.
private readonly IInfoProvider<ContactInfo> contactInfoProvider;
private readonly IContactsBulkDeletionService contactDeletionService;

public ContactsServices(IInfoProvider<ContactInfo> contactInfoProvider, IContactsBulkDeletionService contactDeletionService)
{
    this.contactInfoProvider = contactInfoProvider;
    this.contactDeletionService = contactDeletionService;
}
> Back to list of examples

Contacts

Get the current contact

C#
// Gets the contact related to the currently processed request
ContactInfo currentContact = ContactManagementContext.CurrentContact;
> Back to list of examples

Create contacts

C#
// Creates a new contact object
ContactInfo newContact = new ContactInfo()
{
    ContactLastName = "Smith",
    ContactFirstName = "John",

    // Enables activity tracking for the new contact
    ContactMonitored = true
};

// Saves the contact to the database
contactInfoProvider.Set(newContact);
> Back to list of examples

Update contacts

C#
// Gets the first contact whose last name is 'Smith'
ContactInfo updateContact = contactInfoProvider.Get()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .TopN(1)
                                    .FirstOrDefault();

if (updateContact != null)
{
    // Updates the contact's properties
    updateContact.ContactCompanyName = "Company Inc.";

    // Saves the updated contact to the database
    contactInfoProvider.Set(updateContact);
}
> Back to list of examples

Update multiple contacts

C#
// Gets all contacts whose last name is 'Smith'
var contacts = contactInfoProvider.Get()
                                  .WhereEquals("ContactLastName", "Smith");

// Loops through individual contacts
foreach (ContactInfo contact in contacts)
{
    // Updates the properties of the contact
    contact.ContactCompanyName = "Company Inc.";

    // Saves the updated contact to the database
    contactInfoProvider.Set(contact);
}
> Back to list of examples

Delete contacts

C#
// Gets the first contact whose last name is 'Smith'
ContactInfo deleteContact = contactInfoProvider.Get()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .TopN(1)
                                    .FirstOrDefault();

if (deleteContact != null)
{
    // Deletes the contact
    contactInfoProvider.Delete(deleteContact);
}
> Back to list of examples

Delete contacts in bulk

C#
var dateOneWeekAgo = DateTime.Now.AddDays(-7);

// WhereCondition that selects contacts that are at least 7 days old and have an empty email address
var condition = new WhereCondition()
                .WhereLessThan(nameof(ContactInfo.ContactCreated), dateOneWeekAgo)
                .And()
                .WhereEmpty(nameof(ContactInfo.ContactEmail));

// Deletes contacts matching the specified condition
// Doesn't specify a batch size, which means that contacts are deleted in batches of 1000 (automatically repeats)
await contactDeletionService.BulkDelete(condition);
> Back to list of examples