You need to sign in to do that
Don't have an account?
Aaron Hill
Trigger to Update checkbox based on new activity type
The title says it all. We have an activity type on leads called "First Time Meeting (Phone or In-Person)". So when someone in the org logs a call on a lead with this status we want to have a checkbox called "Had First Time Meeting" Update to "true". This is what I have so far:
This produces an error: Error: Compile Error: line 3:23 no viable alternative at character '"' at line 3 column 23
I'm a JS programmer, fairly new to Apex. I originally planned for it to look like this:
But I have no idea if this is the correct syntax. I'm having a hard time finding resources for apex that talk about activities. I'm not sure how a lead should relate to a task within the code. And first I need to solve the error anyway. Can anyone offer some help on this? Thanks!
trigger hadFirstMeeting on Task (before update) { for (task t : Trigger.new) { if (t.Type === "First Time Meeting (Phone or In-Person)") { } } }
This produces an error: Error: Compile Error: line 3:23 no viable alternative at character '"' at line 3 column 23
I'm a JS programmer, fairly new to Apex. I originally planned for it to look like this:
trigger hadFirstMeeting on Task on Lead (before update) { for (task t, Lead L : Trigger.new) { if (t.Type === "First Time Meeting (Phone or In-Person)") { L.Had_First_Time_Meeting__c = true; } } }
But I have no idea if this is the correct syntax. I'm having a hard time finding resources for apex that talk about activities. I'm not sure how a lead should relate to a task within the code. And first I need to solve the error anyway. Can anyone offer some help on this? Thanks!
But I don't think I'm referencing the correct object. Because even though task and and lead are linked, my custom field "Had_First_Time_Meeting__c" is a child of the lead specifically. I get the following error: Error: Compile Error: Invalid field Had_First_Time_Meeting__c for SObject Task at line 4 column 13
So I tried it referencing the lead instead of task t. Like so:
And I got the error: Error: Compile Error: Expression cannot be assigned at line -1 column -1
Apologies if this is really basic. Appreciate your help. How do I reference the linked lead within the code?
By going through the problem statement and above comments, it seems the checkbox field on lead should be checked if a task record is created with subject "First Time Meeting (Phone or In-Person)". In this case, we will have to create a trigger on Task object with After insert event and then update the related Lead record.
Thanks!