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
AnonTestQuestAnonTestQuest 

How to write a trigger and everything I need to run it in Sublime with SalesForce

I need to write a trigger to copy a custom rich text field to another custom rich text field on a custom object when they submit the form(the object). How should I write this trigger and do I need a class? And how do I test it? I am new to this stuff but can't find anything that works.

Thanks!
viruSviruS
Hi Anon,

It's simples as to copy the value of normal field. Just provide some details about custom object name from source and target fields. I will provide you sample trigger code.
AnonTestQuestAnonTestQuest
I got it to work. I am now running into the problem that the original field is a rich text field and when it is copied to another field which is a long text field, it includes the HTML markup. How can I strip the HTML markup from a custom rich text field?
viruSviruS
Try 
String.replaceAll('\\<.*?\\>', '');
AnonTestQuestAnonTestQuest
Here is my line:

v.VanaHCM__Job_Posting_Summary__c = v.VanaHCM__Internal_Position_Description__c;

where would I insert that?

thank you!
AnonTestQuestAnonTestQuest
The left side is the long text area that i dont want the mark up on.
viruSviruS
String newValue = v.VanaHCM__Internal_Position_Description__c;

v.VanaHCM__Job_Posting_Summary__c = newValue.VanaHCM__Internal_Position_Description__c;
viruSviruS
Your attempted message:
String newValue = v.VanaHCM__Internal_Position_Description__c;

v.VanaHCM__Job_Posting_Summary__c = newValue.replaceAll('\\<.*?\\>', '');
AnonTestQuestAnonTestQuest
That works but it does not preserve the formatting that I need to keep. I understand that's what the HTML markup does, however I want the formatting, I just don't want to see the markup because it is visible in the field. I also cannot covert the fields to different types.