I am Giving the Request body in Postman like:






For that I am Writing the Apex class

@RestResource(urlMapping='/create Event1/')
 global  with sharing class  createevent1
  public List<eventitems> eventitems2 = new list<eventitems>();
    global static list<event> Eventhelper()
        savepoint sp = database.setsavepoint();
        list<event> returnlst = new list<event>();
         RestRequest req = RestContext.request;
         RestResponse res = RestContext.response;
         Blob body = req.requestBody;
         string body1=body.tostring();
         createevent1 obj = createevent1.parse(body1);
        catch(Exception e)
return null;
 public Class  eventitems{
      public id whatid;
      public id whoid;
      public id OwnerId;
      public boolean IsAllDayEvent;
      public string Subject;
      public DateTime StartDate;
      public DateTime EndDate;
      public boolean Recurrence;
      public datetime Recurrencestdate;
      public date Recurrenceenddate;
      public String RecType;
      public Integer Recintrvl;
      public Integer RDayofWeekMask;
      public Integer RDayofMonth;
      public string ReccurenceInstance;
      public string RecurrenceMonthYear;
      public id RecurrenceActivityId;
      public list<string> Invitees;
  public static createevent1 parse(String json) {

        return (createevent1)System.json.deserialize(json, createevent1.class);


In the Above the Value is Which is Given in Postman it is Not Parsing the value is not getting in obj after Parsing in Parse Function and then why here we using Database Savepoint and Rollback,Anyone Share the Answer

  • There's a great tool for generating Apex wrapper classes from JSON - JSON2Apex
    – smukov
    Commented Jul 8, 2016 at 10:41

1 Answer 1


You are absolutely right. We are not doing any DML before or after parsing and hence we don't need Savepoint/Rollback here. BTW Transaction data automatically get rollback when an exception occurred. If you wanna log the raw log of request you can do DML of request at start of your method and now if you want that request to stay even if below operations fail,then you can use the savepoint.

You can read more about it here

Your class eventitems and method to parse are not proper.

Create a new class for Event wrapper and parsing.

public class EventWrapper{
    public eventitem [] eventitems;
    class eventitem {
        public String whatid;   //0012800000i92pd
        public String whoid;    //0032800000TirUN
        public String OwnerId;  //005280000010olH
        public boolean IsAllDayEvent;
        public String Subject;  //call
        public String StartDate;    //2016-07-08T14:00:00.000+0000
        public String EndDate;  //2016-07-08T15:00:00.000+0000
        public boolean Recurrence;
    public static EventWrapper parse(String json){
        return (EventWrapper) System.JSON.deserialize(json, EventWrapper.class);

And instead of calling your parse method use this code.

createevent1 obj = EventWrapper.parse(body1);

  • After Parsing the Obj Value is Not Getting why?Share the Answer
    – user31717
    Commented Jul 8, 2016 at 10:31
  • return (createevent1)System.json.deserialize(json, createevent1.class); This Line is Not Working Why
    – user31717
    Commented Jul 8, 2016 at 10:33
  • updated code.Please check Commented Jul 8, 2016 at 10:42
  • ok, Why above my code is Not Working,can you suggest any Changes in My Code for Correct Answer
    – user31717
    Commented Jul 8, 2016 at 10:54
  • Your parsing logic is not correct. I have suggested my changes..like replacing a line in your code and Creating a new class for Parsing the json. Commented Jul 8, 2016 at 10:57

You must log in to answer this question.