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
sudha76sudha76 

Trigger to copy values from Description field to the custom field.

I am looking for an example to create a Trigger that will copy the first n character (255 characters) from the TASK standard field called - Description to the custom field under TASKS called - "Extract Task Heading".

 

Any examples on how to copy values within same object and different fields would also help?

 

thanks.

Best Answer chosen by Admin (Salesforce Developers) 
clouddev@surashriclouddev@surashri

Instead you can achieve this by using workflow rules -> field update facility.

 

Below link will explain in short.

 

https://www.youtube.com/watch?v=eG78LF2qa1I

 

Thanks,

All Answers

clouddev@surashriclouddev@surashri

Instead you can achieve this by using workflow rules -> field update facility.

 

Below link will explain in short.

 

https://www.youtube.com/watch?v=eG78LF2qa1I

 

Thanks,

This was selected as the best answer
Vinit_KumarVinit_Kumar

Sudha,

 

Try below :

 

trigger copyDescFieldonTask on Task (before insert, before update) {

if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){

for(Task tsk: Trigger.new){

if(tsk.Description != null)
if(tsk.Description.length() > 255)
tsk.Extract_Task_Heading__c= tsk.Description.substring(0,255);
else
tsk.Extract_Task_Heading__c= tsk.Description;
}
}
}

sudha76sudha76

Thanks everyone for their thoughts on this subject.

I resolved this issue by using a WF Rule. Some of the things I noticed was, Sales force does not allow to access some of the standard TASK fields including Description through custom formula field created under Activity Custom Fields.

Whereas, if I create a WF Rule on TASKS and update the Activity Custom Field, using a field update through Formula, I can easily access "Description" Field.

Not sure, why but that is what I saw so I am sharing with everyone.

So, I did a WF Rule on TASKS which is doing the field update on the custom field called "Comments_Heading__c" that is copying the first statement of the content entered in the "Description" field, through this formula.


LEFT (Description, FIND('. ', Description))


thanks.

 

 

sudha76sudha76

* Long text area, encrypted, and Description fields are not available for use in formulas.

http://login.salesforce.com/help/doc/en/tips_on_building_formulas.htm#formula_display_1300