Field Set in Salesforce π️
What is a Field Set in Salesforce? π€
A Field Set in Salesforce is like a container where you can group multiple fields from an object. Think of it as a shopping basket π where you can put different items (fields) together, and later, you can decide which ones to display on a page or use in code (like Visualforce pages or Apex).
Why Use Field Sets? π€·♂️
Field Sets are useful when you want to:
✅ Dynamically control which fields are displayed – Instead of hardcoding fields in a Visualforce page or Lightning Component, you can just use a Field Set.
✅ Make configuration easier – Admins can update the Field Set without a developer changing the code.
✅ Reuse fields in multiple places – You can use the same Field Set in different pages or components.
Real-Life Example: Online Shopping App π️
Imagine you’re shopping on an e-commerce website like Amazon / Flipkart. When you go to a product page, you see details like:
- Product Name π·️
- Price π°
- Description π
- Ratings ⭐
- Availability ✅
Now, suppose the company wants to show different sets of product details in different places, like:
- On a search results page, they only show Product Name, Price, and Ratings.
- On a detailed product page, they show everything.
Instead of creating separate configurations for each page, they can use Field Sets to dynamically select and display only the required fields.
How to Practice Field Sets in Salesforce? π️
You can try this in your Salesforce Developer Org using the Contact object.
Step 1: Create a Field Set
1️⃣ Go to Setup ⚙️ → Object Manager → Contact.
2️⃣ Click on Field Sets (left sidebar).
3️⃣ Click New and give it a name (e.g., "Contact Information").
4️⃣ Drag and drop fields into the Field Set (e.g., First Name, Last Name, Email, Phone).
5️⃣ Click Save.
Step 2: Use the Field Set in Visualforce Page / LWC
Now, instead of manually coding field names, developers can refer to the Field Set in Apex/Visualforce /LWC
This means whenever an admin updates the Field Set, the page automatically reflects the changes without modifying the code! π
Where Can You Use Field Sets? π
πΉ Visualforce Pages – Display dynamic fields on custom UI.
πΉ Apex Code – Query only the required fields instead of fetching all fields.
πΉ Dynamic Lightning Components – Control displayed fields easily.
Final Thought π‘
Think of Field Sets as a playlist on Spotify π΅. You can add, remove, or reorder songs (fields) anytime, and the playlist (Field Set) will update automatically wherever it's used. πΆ
Comments
Post a Comment