You need to sign in to do that
Don't have an account?
Tristan Jones
opportunity__r.Name coming up blank in task from Apex trigger
Hi,
I'm trying to have the subject field of a task that is triggered in a custom object using an Apex trigger populate with the the name of the opportunity the object is related to. I can get the unique ID to show when i reference the lookup field in the custom object ('opportunity__c') but when I use 'object__r.name' it comes up blank. Does anyone know what could be causing this? My trigger code is:
trigger TaskAllocation on Action__c (after insert) {
List<Task> taskList = new List <Task>();
for (Action__c a:Trigger.New)
{
{
Task t = new Task();
t.OwnerID = a.Action_owner__c;
t.WhatId = a.Id;
t.Subject = a.opportunity__r.Name;
t.description = a.action__c;
t.Status = 'Not Started';
t.ActivityDate = a.deadline__c;
t.priority = 'Normal';
taskList.add(t);
}
}
if(taskList.size()>0)
insert taskList;
}
Cheers,
Tristan
I'm trying to have the subject field of a task that is triggered in a custom object using an Apex trigger populate with the the name of the opportunity the object is related to. I can get the unique ID to show when i reference the lookup field in the custom object ('opportunity__c') but when I use 'object__r.name' it comes up blank. Does anyone know what could be causing this? My trigger code is:
trigger TaskAllocation on Action__c (after insert) {
List<Task> taskList = new List <Task>();
for (Action__c a:Trigger.New)
{
{
Task t = new Task();
t.OwnerID = a.Action_owner__c;
t.WhatId = a.Id;
t.Subject = a.opportunity__r.Name;
t.description = a.action__c;
t.Status = 'Not Started';
t.ActivityDate = a.deadline__c;
t.priority = 'Normal';
taskList.add(t);
}
}
if(taskList.size()>0)
insert taskList;
}
Cheers,
Tristan
You have to query opportunity__r.Name using SOQL.Trigger.new list doesn't contain opportunity__r.Name(Action object nested related information) information.It contains only Action object information.Please use below code.
Regards,
Dilip.
All Answers
You have to query opportunity__r.Name using SOQL.Trigger.new list doesn't contain opportunity__r.Name(Action object nested related information) information.It contains only Action object information.Please use below code.
Regards,
Dilip.