You need to sign in to do that
Don't have an account?

Help writing a trigger that creates a task from a custom object
Hi and Thank you in advance for your help.
I have written a few triggers, but cannot figure this one out. Here is my code:
trigger Insert_ISR onRegistration__c (afterinsert) {
Task[] tasks = newTask[0];
for(Registration__c ca: Trigger.new){
if(ca.Inside_Sales_Rep__c != '') {
tasks.add(
new task(
subject='New Registration In Progress',
ownerid=ca.Inside_Sales_Rep__c, --- here is the problem. This field is a picklist which holds strings and the ownerid is an ID field. How would you accomplish this?
activitydate=system.today().adddays(1),
whatid=ca.Id));
}
}
insert tasks;
}
Hi Eric,
Ok so I'm assuming that Salesforce has stored the name of your user in it's database, not the Id.
When you are trying to map accross the "STRING" which is the name of your user, it's saying that It wants the Id.
So you would do something like:
Please note that this is not "Batch Complient" so you will need to batchify this trigger. Also it's not best practice to put your logic directly into a trigger, but make a handler class to reference in your trigger.
All Answers
Hi Eric,
Try the code below.
Your suggestion did not work " Id.ValueOf(ca.Inside_Sales_Rep__c)".
It is still being treated as a string.
expecting a right parentheses, found 'INCLUDES'
- Save error: expecting a right parentheses, found
'INCLUDES'
Thanks
Hi Eric,
Would you please give me an example value of this string ca.Inside_Sales_Rep__c
EG... A sample value is a0790000008k1B7
Hi Eric,
Ok so I'm assuming that Salesforce has stored the name of your user in it's database, not the Id.
When you are trying to map accross the "STRING" which is the name of your user, it's saying that It wants the Id.
So you would do something like:
Please note that this is not "Batch Complient" so you will need to batchify this trigger. Also it's not best practice to put your logic directly into a trigger, but make a handler class to reference in your trigger.