1

Below in eventDates method I tried to fetch the Event.eventDates__c but it didn't work. It isn't assigning the Event__c type to String[]. Anyhow I only need the dates from this field in the form of an array which I have to pass to a JS array. Any help please.

public with sharing class EventsPageController {

    public String datesFromCalendar {get; set;}
    public List<String> eachDt = new List<String>();

    public void EventsPageController() {
        Event = [SELECT Id, EventDates__c,Event_Description__c,Event_Type__c,Maximum_Attendees__c,Occurrence__c,Program_Name__c FROM Event__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

    }

    public Event__c getEvent(){
        return Event;
    }

    public String[] eventDates(){
        //String[] EventDates = [SELECT Id, EventDates__c FROM Event__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        return string[] = Event.EventDates__c;
    }

1 Answer 1

1

In this line,

String[] EventDates = [SELECT Id, EventDates__c FROM Event__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

You are trying to assign a list of custom objects, Event__c, to a list of Strings. This is likely why you are getting the error. Normally, I would say you would want to try instead retrieving a list of Event__c objects, and looping through and assigning the EventDates__c field (assuming the field type is in fact, a string) to your list of strings. It looks like though this is a controller for a page where you pass the ID of the specific event object you want to work with, so you don't really have to worry about a list. I would change the whole class a bit so you are retrieving and assigning the Event object in the constructor and then you can access it in your method. Something like below

public with sharing class EventsPageController {

    Event__c e                          {get; set;}
    public String datesFromCalendar     {get; set;}
    public List<String> eachDt = new List<String>();

    public void EventsPageController() {
        e = [SELECT Id, EventDates__c,Event_Description__c,Event_Type__c,Maximum_Attendees__c,Occurrence__c,Program_Name__c FROM Event__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Event__c getEvent(){
        return Event;
    }

    public String eventDates(){
        String EventDates = e.EvenDates__c;
        return EventDates;
    }
}

If the EventDates__c field contains more than one date in the string and you are trying to seperate them and return them in a list of strings, this can be done using the join function, but this requires that you are using a separator in the field. Let's assume you are using a ';' as a separator. Then you could use something like this

public list<string> eventDates(){

     list<String> EventDates = new list<String>();
     EventDates = e.EventDates__c.split(';');
     return EventDates;

}

You can obviously adjust this if you want to use a different seperator like a space or a comma.

Hope this helps.

4
  • Sorry to add something more that wasn't been asked in the original question. Actually in the next step I want these dates to be pushed in a JS array. I'm not getting the use of <apex:repeat> to push this array to JS array. It will be great if you can explain it too. I'll change my question accordingly so that it can be helpful for other. Thanks.
    – Superman
    Commented Jan 18, 2015 at 13:51
  • I can help with that but I really would add that as a second question. When you start combining multiple and complex questions, it becomes harder for people to find help when they have a similar issue. Commented Jan 18, 2015 at 14:27
  • Ok let me create another question and do I post the link to question in comments here? If you don't mind.
    – Superman
    Commented Jan 18, 2015 at 14:41
  • Question
    – Superman
    Commented Jan 18, 2015 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .