I'm trying to expose user related events using REST API but I get the error at line 33. Why?

Error Line:

EventData eveData = new EventData(eve.Id,eve.StartDateTime,eve.EndDateTime,eve.subject);

Error Message:

Save error: Constructor not defined: [Sample11.EventData].(Id, Datetime, Datetime, String)

Complete Code

global with sharing class Sample11 {
    global static void getCalendarDetails(){
    Set<ID> userIDS = new Set<ID>();
    RestRequest req = RestContext.request;
    String OwnerId = ((String)req.requestURI.substring(req.requestURI.lastIndexOf('/')+1)).trim();

    RestResponse response = RestContext.response;
    if (response == null) {
    response = new RestResponse();
    RestContext.response = response;
    try {
        EventData eventData = retrieveEvent(OwnerId);
        response.responseBody = Blob.valueOf(JSON.serialize(eventData));
        response.statusCode = 200;
    } else {
        response.statusCode = 404;

    } catch (Exception e) {
    response.responseBody = Blob.valueOf(e.getStackTraceString());
    response.statusCode = 500;

 static EventData retrieveEvent(String OwnerId){
        List<Event> eveList = [Select Id,startdatetime,enddatetime, Subject from Event where OwnerId = :UserInfo.getUserId()];
             Event eve = eveList.get(0);
             //ERROR ON BELOW LINE
             EventData eveData = new EventData(eve.Id,eve.StartDateTime,eve.EndDateTime,eve.subject);
             return eveData;
        return null;


    static boolean validUserID(String OwnerId){
        boolean valid = true; 
        String userId = UserInfo.getUserId(); 
        Pattern myPattern = Pattern.compile(userId);
        Matcher myMatcher = myPattern.matcher(OwnerId);

        if (!myMatcher.matches()){ 
            valid = false;
        return valid; 
    public class EventData{

        public Map<String, String> even = new Map<String,String>();     
        public EventData(String Id, String startdatetime, String enddatetime,String Subject){

            even.put('id', Id);
            even.put('startdatetime', startdatetime);
            even.put('enddatetime', enddatetime);
            even.put('Subject', Subject);

  • You should edit your post with any additional information you wish to add, rather than burying it in the comments on one of the posted answers. Also, please include any error messages verbatim. – Adrian Larson Nov 3 '16 at 17:43

Your constructor accepts startDatetime and endDatetime as String parameters, but you are trying to pass in Datetime values. You have two options:

  1. Change the parameter types to Datetime.
  2. Pass in the values as String data.

I would prefer option 1. You can still put them into the map as strings in a variety of ways, the simplest of which is to call Datetime.format(). Or you can just change even to be a Map<String, Object>, depending on how you are consuming this data.

public MyClass
    public Map<String, String> data { get; private set; }
    public MyClass(String Id, Datetime startDt, Datetime endDt, String subject)
        String startDatetime = startDt.format();
        String endDatetime = endDt.format();
        data = new Map<String, String>
            'id' => id, 'subject' => subject,
            'startdatetime' => startDatetime,
            'enddatetime' => endDatetime,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.