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
Krishnam76Krishnam76 

Trying to update Task custom field when a new task is created or updated.

Hi there,

 

This is my code, and I am only trying to make a Trigger that will update/insert the value TSK in the Type_Task field each time a new task is created or updated.

 

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
trigger UpdateTaskType on Task (before insert, before update) {

for (Task ta:trigger.new)
{
    if(ta.Type_Task1__c != 'TSK'){
       ta.Type_Task1__c == 'TSK');
      
}

}
}

 

//////////////////////////////////////

 

 

I have created this using Eclipse but it show red cross, which means there is an error with the code. Can some one advice how to get this working?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Joseph FerraroJoseph Ferraro

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

for (Task ta:trigger.new) {

if(ta.Type_Task1__c != 'TSK') {

ta.Type_Task1__c = 'TSK';

}

}

 

Message Edited by joe ferraro on 04-15-2009 08:45 PM
Message Edited by joe ferraro on 04-15-2009 08:45 PM

All Answers

werewolfwerewolf

Well, you have an extra, unneeded parenthesis in your code:

 

ta.Type_Task1__c == 'TSK');

 

You know, Eclipse has a view called Problems which will point you to the precise spot that is generating the error.

Krishnam76Krishnam76

hi,

 

I tried this...still no luck. The eclipse still shows the little red cross on the left and is not saving the trigger on the DEV box.

 

\\\\\\\\\\\\\\\\\\\\\\

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

for (Task ta:trigger.new)
{
    if(ta.Type_Task1__c != 'TSK')
    {
       ta.Type_Task1__c == 'TSK';
    }// this is for the IF loop

}// this is the FOR loop

}// Ends the trigger

//////////////////////////

 

 

Any more ideas???

Joseph FerraroJoseph Ferraro

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

for (Task ta:trigger.new) {

if(ta.Type_Task1__c != 'TSK') {

ta.Type_Task1__c = 'TSK';

}

}

 

Message Edited by joe ferraro on 04-15-2009 08:45 PM
Message Edited by joe ferraro on 04-15-2009 08:45 PM
This was selected as the best answer
werewolfwerewolf

Oh yeah, as Joe points out, you're also using an == where you should be using an =.

 

ta.Type_Task1__c = 'TSK';