function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce Dev in TrainingSalesforce Dev in Training 

Capitalize any letters in Account Name field after an apostrophe

Is it possible to create a Trigger to decapitalize any letters in Account Name field after an apostrophe if the letter following is an "S"?

Example: St. Paul'S (decapitalize it) so that it would equal St. Paul's.

We had a developer write a code to capitalize all first letters and unfortunately the developer doesn't communicate with us anymore.

 

Pankaj MehraPankaj Mehra
Hi,

This is a simple trick, you need to add a single line to replace 'S with 's

It would be

if(account.Name.endswith('\'s')) {
  account.Name = account.Name.replace('\'S','\'s');
}

A working snippet
String ss = 'John\'S';
System.debug(ss);
boolean bb = ss.endsWith('\'S');
if(bb) {
   ss = ss.replace('\'S','\'s') ;
}

System.debug(ss);



Thanks

 
Salesforce Dev in TrainingSalesforce Dev in Training
Is there a way to say "contains", in case the Account name is St. John's Household. The "'s" wouldn't be on the end technically.
Jared M NeuferJared M Neufer
Yes, you can - just use the .contains() method:
for (Account a : accountsToUpdate){
    if (a.Name.contains('\'S')){
        aName = a.Name.replace('\'S','\'s');
    }
}

For future reference, here is a link to all String class methods in the developer guide: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm - if you're looking to do anything like this in the future, the functions needed should be in here.