You need to sign in to do that
Don't have an account?
BroncoBoy
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;
}
}
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;
}
}
Check if your trigger is active and also make sure you will not write SOQL inside for loop.
All Answers
Check if your trigger is active and also make sure you will not write SOQL inside for loop.
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);
}
}
Thank you both!