Sub topic 2
Picklists, Relationships, and Specialized Salesforce Fields
Assume you know Salesforce objects, records, fields, and basic Setup navigation. This chapter focuses on choosing fields that constrain values, identify records, store locations, or connect objects.
Picklists and global value sets
A picklist stores one selected value from a defined list. Use it when the allowed choices are stable and users should not enter arbitrary text. For example, Status__c might contain New, In Progress, and Closed.
A multi-select picklist stores zero or more values from a list. Use it sparingly. Reports and filters are harder because several selections are stored together. In SOQL, use INCLUDES:
SELECT Id, Name
FROM Contact
WHERE Interests__c INCLUDES ('Golf;Tennis', 'Chess')A global value set defines picklist values once and lets multiple picklist fields reuse them. Changes to the shared set affect every field that uses it. Use it when the same choices must stay consistent across objects.
Email, Phone, and URL fields
These field types describe the intended data and provide useful user-interface behavior:
- Email validates email-shaped input and can provide email actions.
- Phone formats or links phone numbers according to the user's locale and device.
- URL displays a web address as a link.
They do not prove that an email address or phone number is real. Add validation or verification when accuracy matters.
Auto Number
An Auto Number field generates a unique-looking identifier, such as CASE-{00000}. Salesforce assigns the value when the record is created. Users cannot edit it.
Use Auto Number for readable record references, not for business meaning. Numbers can have gaps because deleted records and failed transactions may consume sequence values.
Geolocation
A Geolocation field stores latitude and longitude as one logical value. It fits locations such as a store, service address, or delivery point. It supports distance-based queries and exposes separate latitude and longitude components in code.
Relationship fields
Relationship fields connect records. A lookup creates a flexible link, while a master-detail relationship creates a stronger parent-child dependency.
Lookup, master-detail, and junction objects
Choose lookup when the child can exist independently, ownership should remain separate, or the relationship may be optional. Choose master-detail when the child depends on the parent. Master-detail supports inherited security, cascade deletion, and roll-up summary fields.
A junction object models a many-to-many relationship. For example, Enrollment__c can connect Student__c and Course__c with two master-detail fields. Each enrollment then represents one student taking one course.
Exercise
Which relationship should you choose for an optional connection where the child record can exist without its parent?
Show answer
Choose a lookup relationship.