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
BroncoBoyBroncoBoy 

Task Trigger Not Updating Activity Custom Field

Upon executing a task before insert trigger, I am trying to update an activity custom field  "Assigned_Region__c" by concatenating two text field values derived from the user.
Looking @ the code below, when I create a task, then look @ the debug logs, strConcatenate appears concatenated correctly- I get the values I'm expecting.  However, on the next line of code, when I try to  assign strConcatenate value to the Assigned_Region__c field (Type:  Text Area(255)), nothing happens - the field never populates with the value from strConcatenate once the record is inserted, nor do I get any errors.  I have checked that the field level security is set to be visible to all profiles including mine.  Any thoughts as to the cause?  Thanks in advance for your help - Bronco.

CODE:

trigger UpdateAssigned on Task (before insert) {
    String tskAssigned;
    for (Task tt : Trigger.new)
    {      
     tskAssigned = tt.Owner.Id;
        String uProf =  [SELECT Profile.Name FROM User WHERE id =: tskAssigned LIMIT 1].Profile.Name;//uProf stores user Profile Name
        String uRegion =  [SELECT Region__c FROM User WHERE id =: tskAssigned LIMIT 1].Region__c;//uRegion stores user Region 
        String strConcatenate = uProf + ' ' + uRegion;
        system.debug('strConcatenate= ' + strConcatenate);//debug log shows "SADMIN East" which is what I expect
        tt.Assigned_Region__c = strConcatenate;
    }
}


Best Answer chosen by BroncoBoy
Pradeep Kumar L.GPradeep Kumar L.G
Hi, 

Check if your trigger is active and also make sure you will not write SOQL inside for loop.

All Answers

Pradeep Kumar L.GPradeep Kumar L.G
Hi, 

Check if your trigger is active and also make sure you will not write SOQL inside for loop.
This was selected as the best answer
NishBNishB
Hi Bronco,
                   I tried executing  your trigger code and it worked .Below is the code and also there is no dot after Owner it should be OwnerId

trigger bfreInsert on Task (before Insert) {

     String tskAssigned;
     for (Task tt : Trigger.new)
    {
      tskAssigned = tt.OwnerId;
       String uProf =   [SELECT Profile.Name FROM User WHERE id =: tskAssigned LIMIT 1].Profile.Name;
       String uRegion =  [SELECT Region__c FROM User WHERE id =: tskAssigned LIMIT 1].Region__c;
       String strConcatenate = uProf + ' ' + uRegion;
       // system.debug('strConcatenate= ' + strConcatenate);//debug log shows "SADMIN East" which is what I expect
        tt.Concatenated_Field__c  = strConcatenate; // Concatenated_Field__c is a Text Area field
       system.debug('strConcatenate= '+tt.Concatenated_Field__c);
     
    }
}
BroncoBoyBroncoBoy
Well you both helped me solve, of course the trigger was not active (ugh!), but it worked after I activated and removed the dot after Owner making it OwnerId.

Thank you both!