You need to sign in to do that
Don't have an account?
Help with an update using Apex Trigger.
I have created a trigger on our object LGA__c that will create and insert a new Event. I also want this trigger to update the created Event whenever the LGA__c is updated. To update the correct Event, I created a field called Event_ID__c in both the LGA__c and Event objects. When an LGA is created it auto creates an Event ID and passes that information to the created event. The problem I am having is using a Query to pull up the right event using the Event_ID__c. I have highlighted the exact line of code that is not working in red. I get the following error.
Error: Compile Error: unexpected token: 'lga.Event_ID__c' at line 34 column 81
Any help on how I can write that query to pull up the correct Event based off the Event_ID__c would be great. Thanks in advance.
trigger CreateLGAEvent on LGA__c (after insert, after update){
Map<String, LGA__c> lgaMap = new Map<String, LGA__c>();
List<Event> lgaEvents = new List<Event>();
if(trigger.isinsert)
for (LGA__c lga : System.Trigger.new){
Event event = new Event(
StartDateTime = lga.LGA_Start_DateTime__c ,
EndDateTime = lga.LGA_End_Date_Time__c,
Subject = 'LGA Scheduled',
IsRecurrence = FALSE,
Description = lga.Event_Description__c,
Location = lga.Event_Subjects__c,
Event_ID__c = lga.Event_ID__c,
IsAllDayEvent = False);
lgaEvents.add(event);
insert lgaEvents;
}
else
for (LGA__c lga : System.Trigger.New) {
String eventID = lga.Event_ID__c;
Event event = [Select id, Event_ID__c from Event where Event_ID__c = lga.Event_ID__c];
event.StartDateTime = lga.LGA_Start_DateTime__c;
event.EndDateTime = lga.LGA_End_Date_Time__c;
event.Subject = 'LGA Scheduled';
event.Description = lga.Event_Description__c;
event.Location = lga.Event_Subjects__c;
lgaEvents.add(event);
update lgaEvents;
}
}
When you refere a variable in the class from your query scope ([ ]), you need to put ":"(colon) before the variable, so it will be
Event event = [Select id, Event_ID__c from Event where Event_ID__c = :lga.Event_ID__c];
Your post is very easy to understand and to answer. I like it. I'll try to anser your posts every time!
ThomasTT
All Answers
When you refere a variable in the class from your query scope ([ ]), you need to put ":"(colon) before the variable, so it will be
Event event = [Select id, Event_ID__c from Event where Event_ID__c = :lga.Event_ID__c];
Your post is very easy to understand and to answer. I like it. I'll try to anser your posts every time!
ThomasTT
Awesome. It always seems to be the little things I am missing. Thanks a ton for the help and I will try and make my posts like this in the future. I know sometimes it can be confusing to figure out what people are trying to say. Thanks again.
- JVH