First Character of each word in a text using APEX TRIGGER
- subhashrdssv
- Jan 23, 2016
- 1 min read
Here is a Trigger of Before Insert and Before Update to get the First Character of each word in a text or a String. In this Example, I have used to get the Shortcut of the Company Name by getting the first characters in each word so that to store in a seperate field.
Example:
trigger CompanyShort on Company__c (before insert, before update){ String Comp; Integer NumberOfWords; List<String> words; String CompanyShort=''; for(Company__c cc : trigger.new){ Comp = cc.Name; Comp = Comp.toUpperCase(); words = Comp.split('\\s+'); NumberOfWords = words.size(); for(integer i = 0; i < NumberOfWords; i++){ CompanyShort += words[i].substring(0,1); } if(CompanyShort != null){ cc.Company_in_Shortcut__c = CompanyShort; } } }
Recent Posts
See AllConverting a Number to related Text using Apex Trigger and Apex Class Example: trigger NumberToWordFieldUpdate on Salary__c (before...
Limits of Process Builder: A Process API Name must be unique across all process and flows in organization. Description ...
Salesforce Provides many automation tools like Approvals, Flows, Workflows and Process Builder which we can use one or many based on the...
コメント