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
DevelopersDevelopers 

How to use javascript in apex triggers?

Hi,

 

In my project, i developed trigger on Task object. My requirement is:

 

1. Task has the field Description which is text-area long.

2. When we try to update the description with the new data, it should append to the existed value.

3. But, here on clicking edit button, the old value is appearing in the text area and the user adds the notes to that existed data.

4. Then, the existed data along with new data is appending with the existed value.

 

For example:

 

Task Object

 

1. Task description field old value: "Testing One"

2. Task description field new value: "Testing One Testing Two". (Because, here while clicking on edit, existed data is available. The user enters the new data along with old value).

 

Now, the updated task description field value is: "Testing One Testing One Testing Two". But, the user expect that it should be "Testing One Testing Two.".

 

I thought of using javascript here. When clicking on Edit button, it clears the old value of the description field. Then, the user enters the new data only. that will append to the existed one.

 

How could i use javascript while clicking on edit(Standard button) and how to implement the functionality for clearing the text area field?

 

Please suggest me in this how to fix this issue?

 

Thanks in advance.

 

Regards,

kumar

Puneet SardanaPuneet Sardana

Why do you require Javascript with Triggers? Triggers are for actions on saving on object to perform some calculations. What you need is a custom button which redirect to a visualforce page where user can enter description and then u can update the task in controller of that visualforce page.

Avidev9Avidev9
Well first of all Triggers are at DB level, and they cant contain any client side code.

To append the data to long text area, I guess you can do this by using TWO fields. One exclusively for entering the data and other one to show them.

Once user enters the data in the first field append the data to the other field. You can also do this(copying) using a workflow.
DevelopersDevelopers

Hi Puneet,

 

 Can you please tell me how to write the trigger for a specific user? The developed one will execute for that particular user only.

 

Please support me in this.

 

Thanks in advance.....

 

Regards,

kumar

Sandeep001Sandeep001
Use methods of UserInfo class to run the trigger for a specific user:

if(Userinfo.getUserId == '<USERID>')

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_userinfo.htm