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
Shephali SwarnkarShephali Swarnkar 

Solution for copying Description(Long text Area datatype) field contents to Custom field

Hi All,
     I had gone through some problems working withDescription field so now I got a solution to work with "Long Text Area DataType", if you want to count() the records or other filtering things with Description.
   I made a custom field "Notes__c"(Text Area) in contact object and using Trigger i copied the contents of Description field to Notes__c.
here is the code:
trigger CopydescToNotes on Contact (before insert,before update) {
for(Contact c : Trigger.new)
if(c.Description!=null)
c.Notes__c=c.Description;
}


Thanks 
Shephali
Best Answer chosen by Shephali Swarnkar
David Holland 6David Holland 6
You realise that if that is a text area and Decription is a long text area, you will get errors if you try and input too much text into the notes section...

You should do something like: c.Notes__c=c.Description.left(2000);

Or however long your text field is?

You could also do this in a workflow rule, or process builder so am confused why you would develop a programmatic approach?

All Answers

David Holland 6David Holland 6
You realise that if that is a text area and Decription is a long text area, you will get errors if you try and input too much text into the notes section...

You should do something like: c.Notes__c=c.Description.left(2000);

Or however long your text field is?

You could also do this in a workflow rule, or process builder so am confused why you would develop a programmatic approach?
This was selected as the best answer
Shephali SwarnkarShephali Swarnkar
@David Holland 6
        Yes David absolutly correct that it will throw error when one tries to copy more than 255(text area limit) words.
Yes i tried it with field update in this way : LEFT (Description, FIND(' ', Description)). but it dint work so i tried to resolve my problem using trigger and now i corrected it as per your suggestion.

trigger CopydescToNotes on Contact (before insert,before update) {
for(Contact c : Trigger.new)
if(c.Description!=null)
c.Notes__c=c.Description.left(255);(or <=255)
}


Thanks
Shephali
David Holland 6David Holland 6

Shephali


Excellent, please feel free to mark my response as the accepted solution if you found it helped :)

Many thanks
Shephali SwarnkarShephali Swarnkar
Thanks David
Alva ChristeenAlva Christeen
Excellent work