You need to sign in to do that
Don't have an account?
Khalid Abdullah
Apex Class: How to manipulate a field from a List
Hello all,
my code is below:
When I try a "For" statement or an "If" statement, it won't let me perform the following:
String StartDateVF;
IF(events.IsAllDayEvent == true) {
StartDateVF = StartDateUTC__c
} else {
StartDateVF = StartDateTime;
}
The error that I'm getting is because the List "Events" can't grab the field "IsAllDayEvent" for some reason, even though a SOQL query has been run on the events list. I'm not sure why the list created in the first section of code won't let me grab the "IsAllDayEvent" field. Do I need to set this part up differently?
my code is below:
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];I want to create a String within the class which appends the appopriate date value based on the boolean "IsAllDayEvent" field.
When I try a "For" statement or an "If" statement, it won't let me perform the following:
String StartDateVF;
IF(events.IsAllDayEvent == true) {
StartDateVF = StartDateUTC__c
} else {
StartDateVF = StartDateTime;
}
The error that I'm getting is because the List "Events" can't grab the field "IsAllDayEvent" for some reason, even though a SOQL query has been run on the events list. I'm not sure why the list created in the first section of code won't let me grab the "IsAllDayEvent" field. Do I need to set this part up differently?
If you want to access those variables in VF page then define them as public. Use this code.
All Answers
Use the following code.
Let me know if you still need my help.
Thanks,
Naval
You can go through following link if you want to know more about iterating over SOQL results.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for_SOQL.htm
I have updated your code as per yopur requirement. Please use the below code :
If you still face any issue with the above code than please let us know the exact error message that you recieve.
Thanks,
Abhishek Bansal
I thought that I would be able to grab the new variables in my VisualForce page:
However, the error I'm getting now says "Unknown property 'ContactStandardController.evt'"
I know this means that I haven't assigned the variables to the contact relation (e), but I'm not sure how to do this. Thanks again for all your help!
If you want to access those variables in VF page then define them as public. Use this code.
So like this:
It did seem like it was working before but it just errored out. What else can I do here to get these variables available to the VisualForce page??