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
BigPBigP 

How to remove spaces in a text field before update, before insert,after insert?

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

You can just use the below line in the trigger in for loop of Trigger.new as below.
 
FieldAPINAME.replaceAll( '\\s+', '');

trigger acctrigger on Account (before insert,before update) {   
    for(Account acc: Trigger.new){   
        
        acc.name=acc.name.replaceAll( '\\s+', '');

     }  
  }


Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,