function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KatherineCKatherineC 

Cross Object Trigger

Hi All,
We created a custom Object CalendarEV, we want a new record for CalendarEV is created automatically  when a new event is created in Public Calendar. We created below trigger but got error message, please help.

Error: Compile Error: Expression cannot be assigned at line -1 column -1

trigger CalendarEV on Event (after insert) {
    List<Event> Events = new List<Event>();
   for (Event e : Trigger.new) {
           if (Event.Subject != null ) {
               CalendarEV__c C = new CalendarEV__c();
               CalendarEV__c.Name = Event.Subject; 
               CalendarEV__c.Location__c = Event.Location;
               CalendarEV__c.Description__c = Event.Description;
                       
              insert C;
        }
    }
   }
Best Answer chosen by KatherineC
Jim JamJim Jam
in your loop you also have to change CalendarEV__c.Name to .. C.Name ... etc.

All Answers

Jim JamJim Jam
in your for loop, try changing Event.subject != null to ... e.subject != null
KatherineCKatherineC
Thanks for the reply. I just tried, got the same error msg.
Jim JamJim Jam
you need to change the rest of the loop as well....so event.subject is e.subject..etc.
KatherineCKatherineC
Ok, I did it again, still same error msg

trigger CalendarEV on Event (after insert) {
    List<Event> Events = new List<Event>();
   for (Event e : Trigger.new) {
           if (e.Subject != null ) {
               CalendarEV__c C = new CalendarEV__c();
               CalendarEV__c.Name = e.Subject;
               CalendarEV__c.Location__c = e.Location;
               CalendarEV__c.Description__c = e.Description;
                      
              insert C;
        }
    }
   }
Jim JamJim Jam
in your loop you also have to change CalendarEV__c.Name to .. C.Name ... etc.
This was selected as the best answer
KatherineCKatherineC
It works now! Thank you so much Jim :)