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
Olivia CannonOlivia Cannon 

Unknown DatetimeMethod line in debug log

Hi,

I've written a trigger to create an Event when a Campaign Member is created but it's not actually working and I don't understand what the debug log is telling me.

This is the trigger:

trigger CreateEventforCampaignMember on CampaignMember (after insert) {

    // 1. create a list of events
    List <Event> eventsToInsert = new List <Event>();
    
    User usr = [SELECT Id FROM User WHERE FirstName =: 'Mark' AND LastName =: 'Alger' AND IsActive = TRUE LIMIT 1];
    // This is to ensure that all events belong to Mark.
    
    try {
        // 2. for every campaign member being inserted, add to the list of events (this is so that the trigger can handle bulk inserts)
        for (CampaignMember cm : trigger.new) {
                system.debug('*** cm.Id ' + cm.Id);
                system.debug('*** cm.Date_of_Event__c.Date() = ' + cm.Date_of_Event__c.Date());    
                system.debug('*** cm.Date_of_Event__c = ' + cm.Date_of_Event__c);
            eventsToInsert.add(
                                new Event    (
                                                DurationInMinutes = 1440,
                                                IsAllDayEvent = true,
                                                IsPrivate = false,
                                                IsRecurrence = false,
                                                IsReminderSet = false,
                                                OwnerID = usr.Id,
                                                ActivityDate = cm.Date_of_Event__c.Date(),
                                                StartDateTime = cm.Date_of_Event__c,
                                                Subject = cm.Subject__c,
                                                //WhatId = cm.CampaignId,
                                                WhoID = cm.LeadId
                                            )
            );
        }
    } catch (NullPointerException e) {
        system.debug('*** CreateEventforCampaignMember failed');
    }
        
    // 3. insert the list of events
    insert eventsToInsert;
}

And this is the relevant part of the debug log:

19:41:52.434 (434744296)|EXECUTION_STARTED
19:41:52.434 (434791731)|CODE_UNIT_STARTED|[EXTERNAL]|01qb0000000N42N|CreateEventforCampaignMember on CampaignMember trigger event AfterInsert for [00vb0000007Zq7h]
19:41:52.435 (435824204)|SYSTEM_CONSTRUCTOR_ENTRY|[4]|<init>()
19:41:52.435 (435872133)|SYSTEM_CONSTRUCTOR_EXIT|[4]|<init>()
19:41:52.436 (436283008)|SOQL_EXECUTE_BEGIN|[6]|Aggregations:0|select Id from User where (FirstName = :tmpVar1 and LastName = :tmpVar2 and IsActive = true) limit 1
19:41:52.446 (446302734)|SOQL_EXECUTE_END|[6]|Rows:1
19:41:52.446 (446522638)|SYSTEM_METHOD_ENTRY|[11]|LIST<CampaignMember>.iterator()
19:41:52.446 (446698513)|SYSTEM_METHOD_EXIT|[11]|LIST<CampaignMember>.iterator()
19:41:52.446 (446729142)|SYSTEM_METHOD_ENTRY|[11]|system.ListIterator.hasNext()
19:41:52.446 (446762026)|SYSTEM_METHOD_EXIT|[11]|system.ListIterator.hasNext()
19:41:52.446 (446858980)|SYSTEM_METHOD_ENTRY|[12]|String.valueOf(Object)
19:41:52.446 (446904223)|SYSTEM_METHOD_EXIT|[12]|String.valueOf(Object)
19:41:52.446 (446934115)|SYSTEM_METHOD_ENTRY|[12]|System.debug(ANY)
19:41:52.446 (446949030)|USER_DEBUG|[12]|DEBUG|*** cm.Id 00vb0000007Zq7hAAC
19:41:52.446 (446956406)|SYSTEM_METHOD_EXIT|[12]|System.debug(ANY)
19:41:52.447 (447002590)|SYSTEM_METHOD_ENTRY|[13]|com.salesforce.api.interop.apex.bcl.DatetimeMethods.date()
19:41:52.447 (447092751)|SYSTEM_METHOD_EXIT|[13]|com.salesforce.api.interop.apex.bcl.DatetimeMethods.date()
19:41:52.447 (447136684)|SYSTEM_METHOD_ENTRY|[33]|System.debug(ANY)
19:41:52.447 (447165602)|USER_DEBUG|[33]|DEBUG|*** CreateEventforCampaignMember failed
19:41:52.447 (447173944)|SYSTEM_METHOD_EXIT|[33]|System.debug(ANY)

I don't understand what 'com.salesforce.api.interop.apex.bcl.DatetimeMethods.date()' means - why is it failing?!

Any help would be gratefully received, thanks!

Best Answer chosen by Olivia Cannon
Olivia CannonOlivia Cannon
Well, if anyone is interested, it turns out that it was a DateTime field and that the actual problem was earlier in the process as the field was blank.

It's all sorted now.

Thanks anyway, Boris!

All Answers

Boris BachovskiBoris Bachovski
I think your field on the campaign member object called "Date_of_Event__c" is of type Date and not DateTime and you're trying to call the Date() method on a date field, which is not going to work. The Date() method returns the Date from a DateTime field. Double check the field type please.
Olivia CannonOlivia Cannon
Well, if anyone is interested, it turns out that it was a DateTime field and that the actual problem was earlier in the process as the field was blank.

It's all sorted now.

Thanks anyway, Boris!
This was selected as the best answer