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
suji srinivasansuji srinivasan 

Hi, I am getting error as Missing '<EOF>' at '@' in rest Apex

global class LeadInfoParser {
    global String LastName{get;set;}
    global String FirstName{get;set;}
    global String Company{get;set;}
    global String email{get;set;}
    global String Phone{get;set;}
    global String LeadStatus{get;set;}    

}
 @RestResource(urlMapping='/LeadService/*')
global without sharing class LeadService {
    @HttpPost
    global static String createLead(LeadInfoParser leadrec){
        Lead leadObj = new Lead();
        leadObj.FirstName =leadrec.FirstName;
        leadObj.LastName=leadrec.LastName; 
        leadObj.Phone=leadrec.Phone;
        leadObj.email=leadrec.email; 
        leadObj.Company = leadrec.Company;
        leadObj.Status = leadrec.LeadStatus;             
      
        Database.saveResult saveResult = database.insert(leadObj,false);
        if(saveResult.isSuccess()){
            System.debug('Record Id:'+saveResult.getId());
        }
        else{
            System.debug('saveResult:'+saveResult.getErrors());
        }
        //Response
        JSONGenerator gen=JSON.createGenerator(true);     
        gen.writeStartObject();
        gen.writeStringField('message','Lead record is created Successfully');
        gen.writeEndObject();     
        String responseString= gen.getAsString();
        return responseString;
    }


Thanks in Advance
Best Answer chosen by suji srinivasan
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

Can you use the below Url in the POST call while calling from workbench.

/services/apexrest/LeadService

I got the record created succesfully with same code and URL as above.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

Can you try the class by saving as below.
 
@RestResource(urlMapping='/LeadService/*')
global without sharing class LeadService {
    @HttpPost
    global static String createLead(LeadInfoParser leadrec){
        Lead leadObj = new Lead();
        leadObj.FirstName =leadrec.FirstName;
        leadObj.LastName=leadrec.LastName; 
        leadObj.Phone=leadrec.Phone;
        leadObj.email=leadrec.email; 
        leadObj.Company = leadrec.Company;
        leadObj.Status = leadrec.LeadStatus;             
      
        Database.saveResult saveResult = database.insert(leadObj,false);
        if(saveResult.isSuccess()){
            System.debug('Record Id:'+saveResult.getId());
        }
        else{
            System.debug('saveResult:'+saveResult.getErrors());
        }
        //Response
        JSONGenerator gen=JSON.createGenerator(true);     
        gen.writeStartObject();
        gen.writeStringField('message','Lead record is created Successfully');
        gen.writeEndObject();     
        String responseString= gen.getAsString();
        return responseString;
    }
    global class LeadInfoParser {
    global String LastName{get;set;}
    global String FirstName{get;set;}
    global String Company{get;set;}
    global String email{get;set;}
    global String Phone{get;set;}
    global String LeadStatus{get;set;}
}
    }

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
mukesh guptamukesh gupta
Hi Suji,

Reason behind ,your code may be out side of class, that's why this error occured, 
 
@RestResource(urlMapping='/LeadService/*')
global without sharing class LeadService {
    @HttpPost
    global static String createLead(LeadInfoParser leadrec){
        Lead leadObj = new Lead();
        leadObj.FirstName =leadrec.FirstName;
        leadObj.LastName=leadrec.LastName; 
        leadObj.Phone=leadrec.Phone;
        leadObj.email=leadrec.email; 
        leadObj.Company = leadrec.Company;
        leadObj.Status = leadrec.LeadStatus;             
      
        Database.saveResult saveResult = database.insert(leadObj,false);
        if(saveResult.isSuccess()){
            System.debug('Record Id:'+saveResult.getId());
        }
        else{
            System.debug('saveResult:'+saveResult.getErrors());
        }
        //Response
        JSONGenerator gen=JSON.createGenerator(true);     
        gen.writeStartObject();
        gen.writeStringField('message','Lead record is created Successfully');
        gen.writeEndObject();     
        String responseString= gen.getAsString();
        return responseString;
    }
    global class LeadInfoParser {   // this wrappr class should be part of this class
        global String LastName{get;set;}
        global String FirstName{get;set;}
        global String Company{get;set;}
        global String email{get;set;}
        global String Phone{get;set;}
        global String LeadStatus{get;set;}
     }
  }


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh


 
suji srinivasansuji srinivasan
Hi ,
I am able to save the code as you suggested .but i am not getting response from workbench.

this is my request

{"leadrec":{
   "FirstName":"John",
   "LastName":"Williams",
   "Company":"Google",
   "LeadStatus":"Open",
   "email":"johnwilliams@gmail.com",
   "Phone":"+1123456"

 }

URL:/services/data/LeadService
Thanks in advance
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

Can you use the below Url in the POST call while calling from workbench.

/services/apexrest/LeadService

I got the record created succesfully with same code and URL as above.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
suji srinivasansuji srinivasan
Hi sai,

I changed the URL observed the following error
message: Unexpected end-of-input: expected close marker for OBJECT (from [line:9, column:183]
errorCode: JSON_PARSER_ERROR
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

There should be other flower Braces } at the end. Can you check it.

Thanks,
 
suji srinivasansuji srinivasan
yes,got it .Thankyou for your Response sai.
Alexander lopez 8Alexander lopez 8
The error "Missing '<EOF>' at '@'" indicates that there is a missing closing parenthesis in the code. To troubleshoot the issue further, you can consider reaching out to a local development community in Dublin (https://rip-notices.com/cork/), as they may be able to provide additional resources and support to help you resolve the problem. If the problem persists, consider reaching out to the support team for further assistance.