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
iSfdciSfdc 

Deleting Unwanted line spaces in a Description field

Hi,
We have a requirement where to trim the unwanted lines in a Description field. Is it possible through Triggers.
Any kind of pointers would be appreciated.
 
Example:
 
Platform-as-a-Service enables developers to create and deliver any kind of business application, entirely on-demand The Salesforce Foundation was created through our unique 1/1/1 integrated philanthropy model: 1% time, 1% product, and 1%
 
 
equity. We call this global vision the power of us. More than 4,000 nonprofits including hundreds of educational institutions participate in the Salesforce CRM product donation and discount program.
 
must be modified to,
 
Platform-as-a-Service enables developers to create and deliver any kind of business application, entirely on-demand The Salesforce Foundation was created through our unique 1/1/1 integrated philanthropy model: 1% time, 1% product, and 1%
equity. We call this global vision the power of us. More than 4,000 nonprofits including hundreds of educational institutions participate in the Salesforce CRM product donation and discount program
 
without any unwanted lined.
 
Thanks
Gani
SiriusBlackOpSiriusBlackOp
Yes this is possible via a trigger, if that is the behavior you want.  I would run a trigger on ever before update and before insert, get the description, remove the returns and set the new value.
 
 
Example:  (this should at least get you going)
 
Code:
trigger cleanAccountVars on Account (before update, before insert) {
    for (Integer i = 0; i < trigger.new.size(); i++) {
        if (trigger.new[i].Description != null) {
            String[] sDescLines = trigger.new[i].Description.split('\\r+');
            String sDesc = '';
            if (sDescLines.size() > 1) {
                for (Integer ii = 0; ii < (sDescLines.size() - 1); ii++) {
                    sDesc += sDescLines[ii].substring(1); //gets the chunk and strips the CR. May want to add a spage back in, but you get the point.
                }
            } else {
                sDesc = sDescLines[0];
            }
            trigger.new[i].Description = sDesc;  //set the new description.  :)
        }
    }
}

 
SiriusBlackOpSiriusBlackOp

oops x2.  :smileysurprised:

 

"...on ever before update..." should say "...on every before update..."

"spage" should say "space"