You need to sign in to do that
Don't have an account?
Khalid Abdullah
VisualForce: Why won't VF grab my variable?
Hello all!
I have the following sets of code intended to display any upcoming meetings directly on a contact's page:
Apex Class
The error message I'm getting is "Unknown Property 'ContactStandardController.StartDateVF1".
I know this means I haven't assigned the StartDateVF1 and StartDateVF2 variables to the contact relationship yet, but I'm not sure how to do this. Would anyone be able to help me?
I have the following sets of code intended to display any upcoming meetings directly on a contact's page:
Apex Class
public with sharing class UpcomingMeetings { public List<Event> events { get; private set; } public List<Event> evt {get; private set;} public String StartDateVF1 {get; private set; } public String StartDateVF2 {get; private set; } public String summary { get; private set; } public String riaAdvisor { get; private set; } public UpcomingMeetings(ApexPages.StandardController controller) { Id contactId = controller.getRecord().Id; system.debug('Contact id ---'+ contactId); Contact c = [SELECT id,Is_RIA_Advisor__c,RIA_Wholesaler_Name__c from Contact where Id=:contactId]; riaAdvisor=''; if (c.Is_RIA_Advisor__c) { riaAdvisor = 'This is a RIA contact. Please direct all calls to '+c.RIA_Wholesaler_Name__c+'<br/>'; } events = new List<Event>(); try { Set<Id> eventIds = new Set<Id>(); for (EventRelation e : [SELECT EventId FROM EventRelation WHERE RelationId =:contactId AND Status NOT IN ('Declined','Uninvited')]) { eventIds.add(e.EventId); } events = [SELECT Id, Subject, StartDateTime, StartDateUTC__c, EndDateTime, IsAllDayEvent FROM Event WHERE (WhoId=:contactId OR Id IN :eventIds) AND Event.Cancelled__c <> TRUE AND ActivityDate>=TODAY ORDER BY ActivityDate ASC]; for(Event evt : events) { DateTime dt = DateTime.now(); String StartDateVF1 = dt.format('MM/DD/YYYY'); String StartDateVF2 = dt.format('MM/DD/YYYY HH:MM'); if(evt.IsAllDayEvent == true) { StartDateVF1 = evt.StartDateUTC__c; } else { StartDateVF2 = evt.StartDateUTC__c; } }VisualForce page:
<apex:page standardController="Contact" extensions="UpcomingMeetings" sidebar="false" showHeader="false"> <style type="text/css"> .meetingToday { // font-weight:bold; font-style:italic } </style> <apex:pageMessage severity="INFO" strength="1" summary="{!summary}" escape="false"> <apex:dataTable value="{!events}" var="e" width="100%" cellpadding="1" cellspacing="1" rows="3"> <apex:column > <li/> </apex:column> <apex:column > <apex:outputLink value="/{!e.Id}" target="_blank" styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}"><apex:outputField value="{!e.Subject}"/></apex:outputLink> </apex:column> <apex:column styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}"> <apex:outputText value="from"/> </apex:column> <apex:column styleClass="{!IF(DATEVALUE(e.StartDateTime)<TODAY(),'meetingToday','')}"> <apex:outputText value="{!IF(e.IsAllDayEvent == true, StartDateVF1, StartDateVF2)}"/> </apex:column>
The error message I'm getting is "Unknown Property 'ContactStandardController.StartDateVF1".
I know this means I haven't assigned the StartDateVF1 and StartDateVF2 variables to the contact relationship yet, but I'm not sure how to do this. Would anyone be able to help me?
You will need to create a Wrapper class for Events that relates both StarDateVF1 and StartDateVF2
And in your VisualForce Page:
Let me know if you need help with the complete code.
Thanks
Before:
After:
Please update your setter as public like below code.
public List<Event> events { get; set; }
public List<Event> evt {get; set;}
public String StartDateVF1 {get; set; }
public String StartDateVF2 {get; set; }
public String summary { get; set; }
public String riaAdvisor { get; set; }
Let us know if this will help you
Ran into a problem on the visualforce page.
The apex class you created for me works well, but I had to eliminate the following piece of code you created:
Otherwise, I kept getting an error.
When I make the changes to the Apex Class (updated entire code below), I keep getting this error:
"Unknown property 'UpcomingMeetings.EventWrapper.StartDateTime' "
If I change all the StartDateTime fields to StartDateVF1/StartDateVF2 fields, the error changes to:
"Unknown property 'UpcomingMeetings.EventWrapper.Id'"
you need to access the startDateTime through the wrapper first then the Event: