You need to sign in to do that
Don't have an account?

help with trigger
Hi,
I'm new to triggers and am trying to create a trigger that will update a field on the custom Enrollment object (custom_campaign_member__c) every time a related Class Log is created.
I want the created date of the class log to update the Enrollments "last login date" every time a class log is created.
Here is what I tried:
trigger LatestClassLogCreated2 on Class_Log__c (before insert, before update) {
Class_Log__c newClassLog = trigger.new[0];
Custom_Campaign_Member__c = [SELECT ID, Last_login_date__c FROM Custom_Campaign_Member__c
WHERE ID=:newClass_Log__c.Custom_Campaign_Member__c];
if ( Custom_Campaign_Member__c.Last_login_date__c == null || Custom_Campaign_Member__c.Last_login_date__c <
newClass_Log__c.CreatedDate) {
Custom_Campaign_Member__c.Last_login_date__c = newClass_Log__c.CreatedDate;
update Custom_Campaign_Member__c;
}
Any help would be greatly appreciated!
You'll need to declare your custom campaign member as an object. Take a look at the following:
trigger LatestClassLogCreated2 on Class_Log__c (before insert, before update) {
Class_Log__c newClassLog = trigger.new[0];
Custom_Campaign_Member__c ccm = [SELECT ID, Last_login_date__c FROM Custom_Campaign_Member__c WHERE ID=:newClass_Log__c.Custom_Campaign_Member__c];
if ( Custom_Campaign_Member__c.Last_login_date__c == null || Custom_Campaign_Member__c.Last_login_date__c < newClass_Log__c.CreatedDate) {
ccm.Last_login_date__c = newClass_Log__c.CreatedDate;
update ccm;
}
}
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
Thanks for your help!
I am getting the following error message:
Save error: Comparison arguments must be compatible types: Schema.SObjectField, Datetime
Both fields are date/time fields. What is the issue?
Thanks!
Is it this comparison that is causing the error?
Custom_Campaign_Member__c.Last_login_date__c < newClass_Log__c.CreatedDate
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
If that is indeed the error for that expression and both fields are dates, then I would submit a case to Salesforce. Sounds like a bug but it's a simple date comparison... so you might want to poke around and see what else you can uncover. Sounds very strange.
Jeff DouglasAppirio, Inc.
http://blog.jeffdouglas.com