top of page
Search

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 All
Process Builder in Salesforce

Salesforce Provides many automation tools like Approvals, Flows, Workflows and Process Builder which we can use one or many based on the...

 
 
 

コメント


Featured Posts
Recent Posts
Connect
  • Google+ Long Shadow
  • Facebook Long Shadow
  • LinkedIn Long Shadow
  • Twitter Long Shadow
bottom of page