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
Courtney M BrownCourtney M Brown 

Apex Trigger on Standard Object - help

Hello,

I am using a standard object (Campaign) to track attendence at events.  Working with the "Total Contacts" field (automatically updated when a contact is added to campaign) and a custom "No of Attendees" field, I'm trying to create an Apex Trigger that updates the Campaign record with the current number of attendees whenever that number changes.  

Goal:  Anytime "Total Contacts" changes, I want to pass that value to the "No of Attendees" field.  

Here's what I've tried so far:
trigger AttendeeUpdate on Campaign (before update) {
    for (Campaign obj: trigger.new){
        No_of_Attendees__c = TotalContacts;
    }
}

Error Message:Compile Error: Variable does not exist: No_of_Attendees__c at line 3 column 9

Any help with this is greatly appreciated!
Best Answer chosen by Courtney M Brown
souvik9086souvik9086
trigger AttendeeUpdate on Campaign (before update) {
    for (Campaign obj: trigger.new){
        obj.No_of_Attendees__c = obj.TotalContacts;
    }
}

All Answers

souvik9086souvik9086
trigger AttendeeUpdate on Campaign (before update) {
    for (Campaign obj: trigger.new){
        obj.No_of_Attendees__c = obj.TotalContacts;
    }
}
This was selected as the best answer
Courtney M BrownCourtney M Brown
Thank you!