Here in this blog we’ll discussed about how we can create Task and case record without authentication
first let’s create site

after creating site make sure login section is not Allowed now we’ll create API class
I have named TaskNCaseController so when you will create site a profile auto created with same name as site name now we need to add this apex class into TaskNCase profile

TaskNCaseController
@RestResource(urlMapping='/taskNcase/*')
global class TaskNCaseController {
@HttpGet
global static String createTaskNCase() {
RestRequest req = RestContext.request;
String endPoint = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
if(endPoint == 'Task'){
Map parms = req.params;
Task tsk = new Task();
tsk.Subject = (String)parms.get('Subject');
tsk.Status = (String)parms.get('Status');
insert tsk;
return 'Task created with Id : '+tsk.Id;
}
if(endpoint == 'Case'){
Map parms = req.params;
Case cse = new Case();
cse.Status = (String)parms.get('Status');
cse.Priority = (String)parms.get('Status');
cse.Origin = (String)parms.get('Status');
insert cse;
return 'Case created with Id : '+cse.Id;
}
return 'Invalid endpoint';
}
}
Now let’s test with postman we have created GET method into Apex class and we are collecting parameter data to create task and case
for URL just copy the site URL with : “/services/apexrest/taskNcase/Task” added this too
example :
SITEURL+ /services/apexrest/taskNcase/Task
Output :
