• Fiona Burniston
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hi team,

I'm trying to capture the last completed event date on the contact object but I'm struggling with the trigger.

Here is the Apex Class - no errors

public class LastCompletedEventDate{
    //Grab list of contacts
    protected final Contact[] contactNewList = new Contact[] {};
        protected final Contact[] contactOldList = new Contact[] {};
            
            public LastCompletedEventDate(Contact[] contactOldList, Contact[] contactNewList) {
                this.contactNewList.addAll(contactNewList == null ? new Contact[] {} : contactNewList);
                this.contactOldList.addAll(contactOldList == null ? new Contact[] {} : contactOldList);
            }
    
    public void execute() {
        //find all events associated to contacts
        Event[] eventList = [select ActivityDate, WhoId, EndDateTime, Subject, ActivityDateTime from Event where WhoId in :contactNewList];
        
        Map<Id, Contact> contactMap = new Map<Id, Contact>(contactNewList);
        for(Contact contact : contactNewList) {
            contact.Last_Completed_Event__c = null;
        }
        
        //create if else statement to display most current completed event date
        for(Event event : eventList) {
            Contact contact = contactMap.get(event.WhoId);
            
            if(Event.EndDateTime < Date.Today())
                Contact.Last_Completed_Event__c = Event.EndDateTime;
        }
    }
}

Here is the trigger with the error 

trigger LastCompletedEventDate on Contact (before update) {
    if(EventID= true) {
        Set<ID> sID = new Set<ID>(trigger.newMap.keySet());
        new LastCompletedEventDate(trigger.old, trigger.new).execute();
    }
}

Any ideas on what I'm doing wrong?
Hi,

I'm looking to create a custom field on the contact object which will store the last completed event date logged against the record.

I've tried to create this through the use of formula fields and the 'last activity date' but unfortunatly this brings through the date of previous tasks and any future events scheduled. Can someone recommend a solution? Appreciate this may only be accomplished through APEX.
 
Hi guys,

​I'm new to using visualforce as a way to customize Salesforce so I’ve started to use the visualforce workbook to help learn the limits, however, I seem to be getting stuck in tutorial #5 (using standard user interface components).
 
Below is what I’ve written (copied from pg18 in the workbook) but I get the error message - Unknown property 'account.contacts' referenced in Tutorial5
 
<apex:page>
<apex:pageBlock title="My Accounts Contacts">
<apex:pageBlockTable value="{!account.contacts}"var="item">
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
 
Has anyone else received the above error message or know why the above it incorrect?
 
Any help is greatly appreciated.
 
Kind regards,
Fiona 
Hi team,

I'm trying to capture the last completed event date on the contact object but I'm struggling with the trigger.

Here is the Apex Class - no errors

public class LastCompletedEventDate{
    //Grab list of contacts
    protected final Contact[] contactNewList = new Contact[] {};
        protected final Contact[] contactOldList = new Contact[] {};
            
            public LastCompletedEventDate(Contact[] contactOldList, Contact[] contactNewList) {
                this.contactNewList.addAll(contactNewList == null ? new Contact[] {} : contactNewList);
                this.contactOldList.addAll(contactOldList == null ? new Contact[] {} : contactOldList);
            }
    
    public void execute() {
        //find all events associated to contacts
        Event[] eventList = [select ActivityDate, WhoId, EndDateTime, Subject, ActivityDateTime from Event where WhoId in :contactNewList];
        
        Map<Id, Contact> contactMap = new Map<Id, Contact>(contactNewList);
        for(Contact contact : contactNewList) {
            contact.Last_Completed_Event__c = null;
        }
        
        //create if else statement to display most current completed event date
        for(Event event : eventList) {
            Contact contact = contactMap.get(event.WhoId);
            
            if(Event.EndDateTime < Date.Today())
                Contact.Last_Completed_Event__c = Event.EndDateTime;
        }
    }
}

Here is the trigger with the error 

trigger LastCompletedEventDate on Contact (before update) {
    if(EventID= true) {
        Set<ID> sID = new Set<ID>(trigger.newMap.keySet());
        new LastCompletedEventDate(trigger.old, trigger.new).execute();
    }
}

Any ideas on what I'm doing wrong?
Hi,

I'm looking to create a custom field on the contact object which will store the last completed event date logged against the record.

I've tried to create this through the use of formula fields and the 'last activity date' but unfortunatly this brings through the date of previous tasks and any future events scheduled. Can someone recommend a solution? Appreciate this may only be accomplished through APEX.
 
Hi guys,

​I'm new to using visualforce as a way to customize Salesforce so I’ve started to use the visualforce workbook to help learn the limits, however, I seem to be getting stuck in tutorial #5 (using standard user interface components).
 
Below is what I’ve written (copied from pg18 in the workbook) but I get the error message - Unknown property 'account.contacts' referenced in Tutorial5
 
<apex:page>
<apex:pageBlock title="My Accounts Contacts">
<apex:pageBlockTable value="{!account.contacts}"var="item">
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
 
Has anyone else received the above error message or know why the above it incorrect?
 
Any help is greatly appreciated.
 
Kind regards,
Fiona