Understanding Secondary Fields Related to a Lookup

A dynamic choice list (DCL) field represents a many-to-1 foreign key reference between one object and a another object of the same or different type.

For example, a TroubleTicket object might have a DCL field named Contact that represents a foreign key reference to the specific Contact object that reported the trouble ticket.

When defining a DCL field, you specify a primary display field name from the reference object. For example, while defining the Contact dynamic choice list field referencing the Contact object, you might specify the Contact Name field.

When you define a DCL field like Contact, you get one primary field and two secondary fields:

  • The DCL Display Field

    This primary field is named Contact_c and it holds the value of the primary display field related to the referenced object, for example the name of the related contact.

  • The DCL Foreign Key Field

    This secondary field is named Contact_Id_c and it holds the value of the primary key of the reference contact.

  • The DCL Related Object Accessor Field

    This secondary field is named Contact_Obj_c and it allows you to programmatically access the related contact object in script code

To access additional fields besides the display name from the related object, you can use the related object accessor field like this:

// Assume script runs in context of TroubleTicket object
def contactEmail = Contact_Obj_c?.EmailAddress_c

If you reference multiple fields from the related object, you can save the related object in a variable and then reference multiple fields using this object variable:

// Assume script runs in context of TroubleTicket object
def contact = Contact_Obj_c
def email = contact?.EmailAddress_c
def linkedIn = contact?.LinkedInUsername_c

To change which contact the TroubleTicket is related to, you can set a new contact by using one of the following techniques. If you know the primary key value of the new contact, then use this approach:

// Assume script runs in context of TroubleTicket object
def newId = /* ... Get the Id of the New Contact Here */
Contact_Id_c = newId

If you know the value of the contact's primary display field, then use this approach instead:

// Assume script runs in context of TroubleTicket object
Contact_c = 'James Smith'
Tip: If the value your script assigns to a dynamic choice list field (e.g. Contact_c) uniquely identifies a referenced object, then the corresponding value of the foreign keyfield (e.g. Contact_Id_c) will automatically update to reflect the primary key of the matching object.
Attention: If the value your script assigns to a DCL field does not uniquely identify a referenced object, then the assignment is ignored.