You need to sign in to do that
Don't have an account?
How to reference current Contact record to update custom field.
I want to set a checkbox on the current contact record.
My trigger queries a related Interaction object to perform a record count.
After counting records,I set the check box either True or False.
I can't figure how to properly reference the current Contact record to update the checkbox field,
I'm getting this error:
Compile Error: Invalid field contact for SObject Contact at line 19 column 31
On this line:
contacts.put(record.contact, new contact(id = record.id, Attended_Event_Within_Past_Year__c = TRUE));
The problem reference: "record.contact"
Thanks for any help.
Kevin
The entire trigger.
trigger ContactsAttendedEventPastYear on Contact (after update) { try { // Your code here date todaysDate = date.today(); date CutoffDate = todaysDate.addDays(-365); // Store Contact record ID map< id, contact > contacts = new map< id, contact >(); //look through the data For (Contact record : trigger.new) { Integer recordcount = [select count() from Interaction__c where Contact__c = :record.id AND Start_Date_Time__c > :CutoffDate and Selected_Sub_type__c = 'Attend Event' AND (Interaction_Type__c = 'Alumni Interaction' OR Interaction_Type__c = 'Advancement Interaction' )]; if(recordcount >= 1) contacts.put(record.contact, new contact(id = record.id, Attended_Event_Within_Past_Year__c = TRUE)); Else { //contacts.put(record.contact__c, new contact(id=record.contact__c, Attended_Event_Within_Past_Year__c = FALSE)); } //update contacts.values(); } } catch (Exception e) { // Generic exception handling code here } }
you need to use Record.ID not record.contact
Hi Kevin
Here is the code for you requoirement.
Kevin,
Replace soql query like this
Compile Error: Invalid field Attended_Event_Within_Past_Year__c for SObject Contact
That's coming from this line:
contacts.get(contId).Attended_Event_Within_Past_Year__c = true;
yOU CAN CHECK THE API NAME OF THE FIELD ON CONTACT OBJECT.