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
Kiran.sfdc14Kiran.sfdc14 

Trigger not working in Production

 

Hi All,

 

I am writting a trigger which is updating a field removing all the Html tags.

 

trigger UpdateSearsDescriptionFieldUpdate on ECS__Product__c (before insert, before update) {    

             for(ECS__Product__c pro : Trigger.new){   

                 if(pro.ECS__Description__c != null && pro.ECS__Description__c != ''){       

                      string result = pro.ECS__Description__c.replaceAll('\'<\'br/\'>\'',' ');  

                      result = result.replaceAll('\'<\'br /\'>\'',' ');   

                      string HTML_TAG_PATTERN = '\'<\'.*?\'>\'';

                      pattern myPattern = pattern.compile(HTML_TAG_PATTERN);  

                      matcher myMatcher = myPattern.matcher(result);

                      result = myMatcher.replaceAll(' '); 

                      result = result.replaceAll('<br>',' ');

                      result = result.replaceAll('\'&lt;\'',' ');

                      result = result.replaceAll('\'&gt;\'',' ');

                      pro.Sears_com_Description__c = result;   

                     System.debug('pro.Sears_com_Description__c-----:'+pro.Sears_com_Description__c);  

       }

     }

 }

 

This trigger is working fine in SandBox but not working in prodution. ECS__Description__c is of Rich Text data type and Sears_com_Description__c is of long text area.

 

Thanks in advance.

 

Thanks,

Kiran

RadnipRadnip

Whats not working about it? it errors, what does the debug logs show?

Kent ManningKent Manning

Try putting some debug statements in the code to see what is / is not working.  For Example:

 

trigger UpdateSearsDescriptionFieldUpdate on ECS__Product__c (before insert, before update) {    

             for(ECS__Product__c pro : Trigger.new){  

                system.debug(' the variable pro is:' + pro);

                system.debug('ECS__Description is: ' + pro.ECS__Description__c);

                 if(pro.ECS__Description__c != null && pro.ECS__Description__c != ''){

                      system.debug (' The IF Statement is true");

                      string result = pro.ECS__Description__c.replaceAll('\'&lt;\'br/\'&gt;\'',' ');  

                      result = result.replaceAll('\'&lt;\'br /\'&gt;\'',' ');   

                      string HTML_TAG_PATTERN = '\'&lt;\'.*?\'&gt;\'';

                      pattern myPattern = pattern.compile(HTML_TAG_PATTERN);  

                      matcher myMatcher = myPattern.matcher(result);

                      result = myMatcher.replaceAll(' '); 

                      result = result.replaceAll('<br>',' ');

                      result = result.replaceAll('\'&lt;\'',' ');

                      result = result.replaceAll('\'&gt;\'',' ');

                      pro.Sears_com_Description__c = result;   

                     System.debug('pro.Sears_com_Description__c-----:'+pro.Sears_com_Description__c);  

       }

     }

 }

 

Also the line   if(pro.ECS__Description__c != null && pro.ECS__Description__c != '')   seems to be not quite right.  I'm wondering if your logic test is never returning TRUE and so nothing is being executed.  

 

Have you created a test class to test this trigger?