function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Rest Resource


 I have created Rest resource class to accept json(POST Method) from php.

global class AttorneyAdapter{    
    global static void  doPost()    {        
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        string strJSON = req.requestBody.toString();          
        JSONparser parser = JSON.createParser(strJSON);           
        Type reqObj = Type.forName('MyClass');         
        MyClass myClassObj =(MyClass)parser.readValueAs(reqObj);  
             lead l=new lead();
             insert l;  }  }

getting  error:
message: "System.JSONException: No content to map to Object due to end of input (System Code) Class.AttorneyAdapter.doPost: line 15, column 1

Help me....





Srirama10 - There is no need to make use of the parser here. Just build the doPost method with parameters that match the json attributes. For e.g.


global static void  doPost(String last_name, String first_name, String userid, String state, String firm_name){        

    lead l=new lead();
    l.lastname = last_name;
    l.firstname = first_name;
    l.title = userid;
    l.state = state; = firm_name;
    insert l;  

 The mapping should be handled by SFDC and no explicit serialization is required. HTH

Nikhil DevNikhil Dev

try changing "Content-Type" to application/json


User-added image