Ever come across acronyms like NASA, HTML, or CEO and wished you had a quick way to get their full meanings inside your Salesforce app?
In this post, we’ll build a simple Apex method that does exactly that using Custom Settings in Salesforce.
This example is great if you’re learning how to:
Work with Custom Settings
Query custom data using SOQL
Return text dynamically from user input
🧠 What Are We Trying to Do?
Let’s say you have a Custom Setting named Acronym_Master__c
, where each record includes:
The Name (short form like “CEO”)
The Full Version (like “Chief Executive Officer”)
We want to:
Accept an acronym as input
Search the custom setting for a match
Return the full form if found
Return a friendly fallback if not found
Perfect for training apps, learning platforms, or company-specific glossaries!
🔍 Code Explanation
public with sharing class ApexUseCaseEleven {
public static String checkFullFormForAcronym(String acronym){
We define a class called ApexUseCaseEleven
with a method checkFullFormForAcronym
. It takes a single input: the acronym to search for.
List<Acronym_Master__c> acronymMasters = [SELECT Id, Name, Full_Version__c
FROM Acronym_Master__c
WHERE Name = :acronym
LIMIT 1];
We run a SOQL query on our Custom Setting Acronym_Master__c
to fetch the record whose name matches the input acronym.
🔎
Name
is a default field in custom settings and custom metadata. It’s often used to store the “label” of the data.
if(acronymMasters.size() == 1){
return acronymMasters[0].Full_Version__c;
}
If the query finds exactly one match, we return the value from the Full_Version__c
field — the full form of the acronym.
return 'Nothing found!';
}
}
If no match is found, we return a default string: 'Nothing found!'
.
✅ Why This Is Useful
This method teaches you:
How to work with List queries
How to return dynamic content
How to gracefully handle no results
It’s reusable for many use cases like:
Glossaries
Product codes
Error code translations
Company-specific terminology
And because it uses Custom Settings, admins can update the data without changing the code!
🧾 Final Code Snippet
public with sharing class ApexUseCaseEleven {
public static String checkFullFormForAcronym(String acronym){
List<Acronym_Master__c> acronymMasters = [SELECT Id, Name, Full_Version__c
FROM Acronym_Master__c
WHERE Name = :acronym
LIMIT 1];
if(acronymMasters.size() == 1){
return acronymMasters[0].Full_Version__c;
}
return 'Nothing found!';
}
}
🎥 Watch It in Action!
Want to see this method in action? Check out my video where I demo creating the custom setting and calling this method from the Developer Console.