You need to sign in to do that
Don't have an account?
dai tran 12
How can define multi function get or post in a class of webservice?
This my webservice:
Error: Only one method per type can be defined with: HttpPost
How can define multi function get or post in a class of webservice?
@RestResource(urlMapping='/Cases/*') global with sharing class CaseManager { global static Map<String,List<Case>> getCaseById() { RestRequest request = RestContext.request; String caseId = request.requestURI.substring( request.requestURI.lastIndexOf('/')+1); List<Case> result; result = [SELECT CaseNumber,Subject,Status,Origin,Priority FROM Case Where Id=:caseId]; Map<String,List<Case>> res=new Map<String,List<Case>>(); res.put('Cases', result); return res; } @HttpPost global static ID createCase(String subject, String status, String origin, String priority) { Case thisCase = new Case( Subject=subject, Status=status, Origin=origin, Priority=priority); insert thisCase; return thisCase.Id; } @HttpPost global static Map<String,List<Case>> getDataGroupOfUser(String userid, String group) { List<Case> result; result = [SELECT CaseNumber,Subject,Status,Origin,Priority FROM Case Where userId__c=:userid and group__c=:group]; Map<String,List<Case>> res=new Map<String,List<Case>>(); res.put('Cases', result); return res; } }
Error: Only one method per type can be defined with: HttpPost
How can define multi function get or post in a class of webservice?
If you want to do this .. workaroung will
Define a one POST method whihc will accept the flag .. based on the flag return the result ..
The idea here is to use the same @HttpPost method to perform two actions by distinguishing your inputs.
In here we are sending a parameter called "action" which defines if we need to do a Retrieve/Fetch or a Creation.
In the example below, I am using the same POST method to retrieve details of "John Doe" in one case while in the other we are trying to create a new Contact with the name - "Mary". POST
/apexrest/contacts/process?action=receive&data=john.doe@example.com
--Gives you back details of John Doe
POST
/apexrest/contacts/process?action=send&data=Mary
--Creates a new Contact named Mary
But it occur error: HttpPost methods do not support return type of Object