You need to sign in to do that
Don't have an account?
gjblajian
create task from field in parent object in a trigger
I have the below code which is attempting to create a task based on the Id set in the EWM_Contact__c lookup field in the parent object of the trigger's object but I keep getting the following error
Assigned To: Assigned To ID: owner cannot be blank
The problem is that when I run the SOQL [select name, Household_Name__r.EWM_Contact__r.Id from Investment_Profile__c where name = 'Test Original Contact Entry'] I can retrieve the id for this field so I know it is not blank. Can anyone tell me what I am doing wrong?
... if((ipOld != null && ipNew.Account_Status__c == 'Client Onboarded' && ipOld.Account_Status__c != ipNew.Account_Status__c)){ Id id = ipNew.Household_Name__r.EWM_Contact__r.Id; if(al.StringUtils.isNotBlank(''+ id)){ Task t = new Task(); t.OwnerId = id; t.Subject = 'EWM Client Welcome Call'; t.ActivityDate = date.today().addDays(7); t.Priority = 'Normal'; t.Status = 'Not Started'; t.WhatId = ipNew.Household_Name__r.Id; insert t; } } ...
Anup, thankyou. Your solution wasn't exactly what I needed but it definitely put me on the right track. The solution was as follows:
Again, thank you for your help.
All Answers
Try changing the SOQL to:
and set the t.OwnerId to:
This should work!
- Anup
Hmm, try this soql instead, it checks for nullability and blank values:
Regards,
Anup
Anup, thankyou. Your solution wasn't exactly what I needed but it definitely put me on the right track. The solution was as follows:
Again, thank you for your help.
No problem at all! Glad I could be of service to you! :)
Have a nice day!
- Anup