You need to sign in to do that
Don't have an account?
suji 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
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
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
Can you try the class by saving as below.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Reason behind ,your code may be out side of class, that's why this error occured,
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
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
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,
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
There should be other flower Braces } at the end. Can you check it.
Thanks,