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
Angela SchloederAngela Schloeder 

IsChild = False

A freelance developer left me hanging by not finishing the job. I really need to have this page not include all of the IsChild Events. Most every Event created in our org has invitees, but this makes it very difficult to know which is the parent on this vf page.
This is what I have so far. really hoping someone can help.

<apex:page controller="MeetingBacklogController" tabStyle="Event">
    <apex:sectionHeader title="Event" subtitle="Meeting Backlog" />
    <apex:form id="form">
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton rendered="{!events.size>0}" value="Save" action="{!save}" reRender="form" status="status" />
                <apex:commandButton value="Refresh" action="{!refresh}" reRender="form" status="status" />
                <apex:actionStatus startText="Updating..." id="status" />
            </apex:pageBlockButtons>

            <apex:pageMessages />
            <apex:pageMessage severity="info" rendered="{!events.size=0}">
                No records found
            </apex:pageMessage>
            <apex:pageBlockTable rendered="{!events.size>0}" value="{!events}" var="event">
                <apex:column headerValue="{!$ObjectType.Event.fields.Set_By__c.Label}" value="{!event.Set_By__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Attendee__c.Label}" value="{!event.Attendee__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Meeting_Progression__c.Label}" value="{!event.Meeting_Progression__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Client_Invite__c.Label}">
                    <apex:inputField value="{!event.Client_Invite__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Invite__c.Label}">
                    <apex:inputField value="{!event.Exec_Invite__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Accepted__c.Label}">
                    <apex:inputField value="{!event.Exec_Accepted__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Tentative__c.Label}">
                    <apex:inputField value="{!event.Exec_Tentative__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Meeting_Status__c.Label}">
                    <apex:inputField value="{!event.Meeting_Status__c}" />
                </apex:column>
                                <apex:column headerValue="{!$ObjectType.Event.fields.Location.Label}" value="{!event.Location}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.StartDateTime.Label}" value="{!event.StartDateTime}" />
                <apex:column headerValue="{!$ObjectType.Account.fields.Name.Label}" value="{!event.AccountId}" />
                <apex:column headerValue="{!$ObjectType.Contact.fields.Name.Label}" value="{!event.WhoId}" />
                <apex:column headerValue="{!$ObjectType.Contact.fields.Title.Label}" value="{!relatedRecords[event.WhoId]['Title']}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Best Answer chosen by Angela Schloeder
Anirudh SinghAnirudh Singh
Hello Angela,

There were some mistakes in the code, I have corrected them and updated the class and the Visualforce Page, as needed by you.
I have handled duplicate Events and now the Child Events are not shown on the Page.


Please find below the Class and the Visualforce Page:

Apex Class:
public with sharing class MeetingBacklogController
{
    public List<Event> eventsList{get; set;}
    public Map<Id, sObject> relatedRecords{get; set;}
    
    private Map<Id, Event> originalEventsMap;
    
    public MeetingBacklogController()
    {
        init(true);
    }
    
    private void init(Boolean updateUI)
    {
        Set<String> meetingProgressionValues=new Set<String>();
        for(PicklistEntry entry: Event.Meeting_Progression__c.getDescribe().getPicklistValues())
        {
            if(entry.getValue().startsWithIgnoreCase('M') || entry.getValue().startsWithIgnoreCase('Conf'))
            {
                meetingProgressionValues.add(entry.getValue());
            }
        }
        
        originalEventsMap=new Map<Id, Event>([
            SELECT Id, Set_By__c, Attendee__c, Meeting_Progression__c, Client_Invite__c,
            Exec_Invite__c, Exec_Accepted__c, Exec_Tentative__c, Meeting_Status__c,
            ActivityDate, StartDateTime, AccountId, Account.Name, WhoId, Who.Name, Who.Title,
            Location, IsChild
            FROM Event
            WHERE StartDateTime=NEXT_N_DAYS:90 
            AND Meeting_Progression__c IN :meetingProgressionValues 
            AND Meeting_Status__c NOT IN ('CP','CC','MP','MC','AM')
            AND IsChild=false
        ]);
        
        relatedRecords=new Map<Id, SObject>();
        for(Event record: originalEventsMap.values())
        {
            relatedRecords.put(record.WhoId, Null);
        }
        relatedRecords.putAll([SELECT Title FROM Lead WHERE Id IN :relatedRecords.keySet()]);
        relatedRecords.putAll([SELECT Title FROM Contact WHERE Id IN :relatedRecords.keySet()]);
        relatedRecords.put(Null, new Contact());
        
        eventsList=new List<Event>();
        if(updateUI)
        {
            eventsList=originalEventsMap.values().deepClone(true, true, true);
            eventsList.sort();
        }
    }
    
    public void refresh()
    {
        init(true);
    }
    
    public void save()
    {
        List<Event> eventsToBeUpdateList=new List<Event>();
        
        for(Integer i=0; i<originalEventsMap.values().size(); i++)
        {
            for(Integer j=0; j<eventsList.size(); j++)
            {
                if(originalEventsMap.values()[i].Id==eventsList[j].Id && originalEventsMap.values()[i]!=eventsList[j])
                {
                    eventsToBeUpdateList.add(eventsList[j]);
                    system.debug('eventsList[j]---->'+eventsList[j]);
                    break;
                }
            }
        }
        Boolean updateUI=true;
        
        try
        {
            Integer numberOfRecordsUpdated=0;
            for(Database.SaveResult result: Database.update(eventsToBeUpdateList, false))
            {
                updateUI&=result.isSuccess();
                if(result.isSuccess())
                {
                    numberOfRecordsUpdated=numberOfRecordsUpdated+1;
                }
            }
            
            init(updateUI);
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, numberOfRecordsUpdated+' record'+(numberOfRecordsUpdated==1?'':'s')+' saved.'));
        }
        catch(Exception e)
        {
            ApexPages.addMessages(e);
        }
    }
}

Visualforce Page:
<apex:page controller="MeetingBacklogController" tabStyle="Event">
    <apex:sectionHeader title="Event" subtitle="Meeting Backlog" />
    <apex:form id="form">
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton rendered="{!eventsList.size>0}" value="Save" action="{!save}" reRender="form" status="status" />
                <apex:commandButton value="Refresh" action="{!refresh}" reRender="form" status="status" />
                <apex:actionStatus startText="Updating..." id="status" />
            </apex:pageBlockButtons>
            
            <apex:pageMessages />
            <apex:pageMessage severity="info" rendered="{!eventsList.size=0}">
                No records found
            </apex:pageMessage>
            <apex:pageBlockTable rendered="{!eventsList.size>0}" value="{!eventsList}" var="event">
                <apex:column headerValue="{!$ObjectType.Event.fields.Set_By__c.Label}" value="{!event.Set_By__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Attendee__c.Label}" value="{!event.Attendee__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Meeting_Progression__c.Label}" value="{!event.Meeting_Progression__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Client_Invite__c.Label}">
                    <apex:inputField value="{!event.Client_Invite__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Invite__c.Label}">
                    <apex:inputField value="{!event.Exec_Invite__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Accepted__c.Label}">
                    <apex:inputField value="{!event.Exec_Accepted__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Tentative__c.Label}">
                    <apex:inputField value="{!event.Exec_Tentative__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Meeting_Status__c.Label}">
                    <apex:inputField value="{!event.Meeting_Status__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Location.Label}" value="{!event.Location}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.StartDateTime.Label}" value="{!event.StartDateTime}" />
                <apex:column headerValue="{!$ObjectType.Account.fields.Name.Label}" value="{!event.AccountId}" />
                <apex:column headerValue="{!$ObjectType.Contact.fields.Name.Label}" value="{!event.WhoId}" />
                <apex:column headerValue="{!$ObjectType.Contact.fields.Title.Label}" value="{!relatedRecords[event.WhoId]['Title']}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Please let me know if this helps.
If yes, please mark the Question as Solved.


Thanks and Regards,
Anirudh Singh

All Answers

Anirudh SinghAnirudh Singh
Hello Angela,

To help you, I will need the below answers:

Please can you let me know what is the actual requirement along with the details and which functionality is this Visualforce Page developed to achieve?
Also, where is it used like on clicking a button on some Record page this Visualforce Page gets opened. 
Please provide the controller MeetingBacklogController for this Visualforce Page.

Thanks and Regards,
Anirudh Singh
Angela SchloederAngela Schloeder
Aniruth,

Thank you again for looking at this.

A link in the sidebar opens the vf page with a list of open meetings that can be updated from the page. See below:

User-added image

Problem is the duplicate, (Child) meetings. We have no way of knowing which is the Parent and that is the only one that can actually be updated and saved. And the boss does not want to have to see all child events and figure out which is which. Would like to filter out all Child Events.

Apex Class
MeetingBacklogController

public with sharing class MeetingBacklogController {
    public Event[] events { get; set; }
    public Map<Id, SObject> relatedRecords { get; set; }

    Event[] origEvents;
   
    public void refresh() {
        init(true);
    }
   
    void init(Boolean updateUI) {
        Set<String> meetingProgressionValues = new Set<String>();
        for(PicklistEntry entry: Event.Meeting_Progression__c.getDescribe().getPicklistValues()) {
            if(entry.getValue().startsWithIgnoreCase('M') || entry.getValue().startsWithIgnoreCase('Conf')) {
                meetingProgressionValues.add(entry.getValue());
            }
        }
        relatedRecords = new Map<Id, SObject>();
        origEvents = [SELECT Set_By__c, Attendee__c, Meeting_Progression__c, Client_Invite__c,
                            Exec_Invite__c, Exec_Accepted__c, Exec_Tentative__c, Meeting_Status__c,
                            ActivityDate, StartDateTime, AccountId, Account.Name, WhoId, Who.Name, Who.Title,
                            Location
                      FROM Event
                      WHERE StartDateTime = NEXT_N_DAYS:90 AND
                            Meeting_Progression__c IN :meetingProgressionValues AND
                            Meeting_Status__c NOT IN ('CP','CC','MP','MC','AM')
                      ];
        for(Event record: origEvents) {
            relatedRecords.put(record.WhoId, null);
        }
        relatedRecords.putAll([SELECT Title FROM Lead WHERE Id IN :relatedRecords.keySet()]);
        relatedRecords.putAll([SELECT Title FROM Contact WHERE Id IN :relatedRecords.keySet()]);
        relatedRecords.put(null, new Contact());
        if(updateUI) {
            events = origEvents.deepClone(true, true, true);
        }
    }
   
    public MeetingBacklogController() {
        init(true);
    }
   
    public void save() {
        Event[] updates = new Event[0];
        for(Integer index = 0; index < origEvents.size(); index++) {
            if(origEvents[index] != events[index]) {
                updates.add(events[index]);
            }
        }
        Boolean updateUI = true;
        try {
            for(Database.SaveResult result: Database.update(events, false)) {
                updateUI &= result.isSuccess();
            }
            init(updateUI);
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, updates.size().format()+' record'+(updates.size()==1?'':'s')+' saved.'));
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
    }
}
Anirudh SinghAnirudh Singh
Hello Angela,

There were some mistakes in the code, I have corrected them and updated the class and the Visualforce Page, as needed by you.
I have handled duplicate Events and now the Child Events are not shown on the Page.


Please find below the Class and the Visualforce Page:

Apex Class:
public with sharing class MeetingBacklogController
{
    public List<Event> eventsList{get; set;}
    public Map<Id, sObject> relatedRecords{get; set;}
    
    private Map<Id, Event> originalEventsMap;
    
    public MeetingBacklogController()
    {
        init(true);
    }
    
    private void init(Boolean updateUI)
    {
        Set<String> meetingProgressionValues=new Set<String>();
        for(PicklistEntry entry: Event.Meeting_Progression__c.getDescribe().getPicklistValues())
        {
            if(entry.getValue().startsWithIgnoreCase('M') || entry.getValue().startsWithIgnoreCase('Conf'))
            {
                meetingProgressionValues.add(entry.getValue());
            }
        }
        
        originalEventsMap=new Map<Id, Event>([
            SELECT Id, Set_By__c, Attendee__c, Meeting_Progression__c, Client_Invite__c,
            Exec_Invite__c, Exec_Accepted__c, Exec_Tentative__c, Meeting_Status__c,
            ActivityDate, StartDateTime, AccountId, Account.Name, WhoId, Who.Name, Who.Title,
            Location, IsChild
            FROM Event
            WHERE StartDateTime=NEXT_N_DAYS:90 
            AND Meeting_Progression__c IN :meetingProgressionValues 
            AND Meeting_Status__c NOT IN ('CP','CC','MP','MC','AM')
            AND IsChild=false
        ]);
        
        relatedRecords=new Map<Id, SObject>();
        for(Event record: originalEventsMap.values())
        {
            relatedRecords.put(record.WhoId, Null);
        }
        relatedRecords.putAll([SELECT Title FROM Lead WHERE Id IN :relatedRecords.keySet()]);
        relatedRecords.putAll([SELECT Title FROM Contact WHERE Id IN :relatedRecords.keySet()]);
        relatedRecords.put(Null, new Contact());
        
        eventsList=new List<Event>();
        if(updateUI)
        {
            eventsList=originalEventsMap.values().deepClone(true, true, true);
            eventsList.sort();
        }
    }
    
    public void refresh()
    {
        init(true);
    }
    
    public void save()
    {
        List<Event> eventsToBeUpdateList=new List<Event>();
        
        for(Integer i=0; i<originalEventsMap.values().size(); i++)
        {
            for(Integer j=0; j<eventsList.size(); j++)
            {
                if(originalEventsMap.values()[i].Id==eventsList[j].Id && originalEventsMap.values()[i]!=eventsList[j])
                {
                    eventsToBeUpdateList.add(eventsList[j]);
                    system.debug('eventsList[j]---->'+eventsList[j]);
                    break;
                }
            }
        }
        Boolean updateUI=true;
        
        try
        {
            Integer numberOfRecordsUpdated=0;
            for(Database.SaveResult result: Database.update(eventsToBeUpdateList, false))
            {
                updateUI&=result.isSuccess();
                if(result.isSuccess())
                {
                    numberOfRecordsUpdated=numberOfRecordsUpdated+1;
                }
            }
            
            init(updateUI);
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, numberOfRecordsUpdated+' record'+(numberOfRecordsUpdated==1?'':'s')+' saved.'));
        }
        catch(Exception e)
        {
            ApexPages.addMessages(e);
        }
    }
}

Visualforce Page:
<apex:page controller="MeetingBacklogController" tabStyle="Event">
    <apex:sectionHeader title="Event" subtitle="Meeting Backlog" />
    <apex:form id="form">
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton rendered="{!eventsList.size>0}" value="Save" action="{!save}" reRender="form" status="status" />
                <apex:commandButton value="Refresh" action="{!refresh}" reRender="form" status="status" />
                <apex:actionStatus startText="Updating..." id="status" />
            </apex:pageBlockButtons>
            
            <apex:pageMessages />
            <apex:pageMessage severity="info" rendered="{!eventsList.size=0}">
                No records found
            </apex:pageMessage>
            <apex:pageBlockTable rendered="{!eventsList.size>0}" value="{!eventsList}" var="event">
                <apex:column headerValue="{!$ObjectType.Event.fields.Set_By__c.Label}" value="{!event.Set_By__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Attendee__c.Label}" value="{!event.Attendee__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Meeting_Progression__c.Label}" value="{!event.Meeting_Progression__c}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.Client_Invite__c.Label}">
                    <apex:inputField value="{!event.Client_Invite__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Invite__c.Label}">
                    <apex:inputField value="{!event.Exec_Invite__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Accepted__c.Label}">
                    <apex:inputField value="{!event.Exec_Accepted__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Exec_Tentative__c.Label}">
                    <apex:inputField value="{!event.Exec_Tentative__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Meeting_Status__c.Label}">
                    <apex:inputField value="{!event.Meeting_Status__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Event.fields.Location.Label}" value="{!event.Location}" />
                <apex:column headerValue="{!$ObjectType.Event.fields.StartDateTime.Label}" value="{!event.StartDateTime}" />
                <apex:column headerValue="{!$ObjectType.Account.fields.Name.Label}" value="{!event.AccountId}" />
                <apex:column headerValue="{!$ObjectType.Contact.fields.Name.Label}" value="{!event.WhoId}" />
                <apex:column headerValue="{!$ObjectType.Contact.fields.Title.Label}" value="{!relatedRecords[event.WhoId]['Title']}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Please let me know if this helps.
If yes, please mark the Question as Solved.


Thanks and Regards,
Anirudh Singh
This was selected as the best answer
Angela SchloederAngela Schloeder
Anirudh,

Thank you for all of what you have done here.

Everything is working except when I try to change the 'Meeting Status' to CC,MC,CP,MP OR AM; 0 records saved. No records found.

Any ideas?

Thanks and Regards,
Angela
Anirudh SinghAnirudh Singh
Hi Angela,

Sorry I saw this today, I will see what is wrong and reply you back. If the issue is already solved do let me know.

Thanks and Regards,
Anirudh Singh
Anirudh SinghAnirudh Singh
Hello Angela,

I have found the reason, why you are not able to see any records for 'Meeting Status' to CC,MC,CP,MP OR AM.

This is because, the events that are fetched using SOQL Query are only with Meeting_Status__c NOT IN ('CP','CC','MP','MC','AM').
So, when you update the meeting status, the updated records are not fetched as they do not meet the criteria i.e. Meeting_Status__c NOT IN ('CP','CC','MP','MC','AM').

Please see the below query that has been used in the code(I have marked it in bold):
originalEventsMap=new Map<Id, Event>([
            SELECT Id, Set_By__c, Attendee__c, Meeting_Progression__c, Client_Invite__c,
            Exec_Invite__c, Exec_Accepted__c, Exec_Tentative__c, Meeting_Status__c,
            ActivityDate, StartDateTime, AccountId, Account.Name, WhoId, Who.Name, Who.Title,
            Location, IsChild
            FROM Event
            WHERE StartDateTime=NEXT_N_DAYS:90 
            AND Meeting_Progression__c IN :meetingProgressionValues 
            AND Meeting_Status__c NOT IN ('CP','CC','MP','MC','AM')
            AND IsChild=false
        ]);
This condition is restricting the meetings to be displayed only for Meeting Status not equal to 'CP' or 'CC' or 'MP' or 'MC' or 'AM'.
If you want to see all the meeting irrespective of the status and update them on the page, please remove the condition.
Like this:
originalEventsMap=new Map<Id, Event>([
            SELECT Id, Set_By__c, Attendee__c, Meeting_Progression__c, Client_Invite__c,
            Exec_Invite__c, Exec_Accepted__c, Exec_Tentative__c, Meeting_Status__c,
            ActivityDate, StartDateTime, AccountId, Account.Name, WhoId, Who.Name, Who.Title,
            Location, IsChild
            FROM Event
            WHERE StartDateTime=NEXT_N_DAYS:90 
            AND Meeting_Progression__c IN :meetingProgressionValues 
            AND IsChild=false
        ]);

Please let me know if this helps.

Thanks and Regards,
Anirudh Singh
Angela SchloederAngela Schloeder
Thank you for your reply. I understand that I will not see records with the 'Meeting Status' of 'CP','CC','MP','MC' or 'AM'. The issue is it will not allow to Save the Meeting Status to one of these options. I did as you said and removed these, but it still will not allow to save with the 'Meeting Status' of 'CP','CC','MP','MC' or 'AM'. Also, the inline edit is acting strange. When I change the field value, I have to click outside the field so the new field value changes to the color orange and then it will save. Thanks and Regards, Angela
Anirudh SinghAnirudh Singh
Hello Angela,

Are you using the same code which I gave or some modifications have been made on top of that?

Regarding the Saving of the records with the 'Meeting Status' of 'CP','CC','MP','MC' or 'AM', I am sure that in the Save method, there is no condition that prevents the records from getting saved with these meeting statuses. 

Regarding the inline edit, I am not sure which inline edit you are referring here, as here we have used input fields.

Please can you provide the latest code being used for Visualforce Page and Apex Class, so that I can see if there is anything different.

Thanks and Regards,
Anirudh Singh