+ Start a Discussion
Sunil Kumar 545Sunil Kumar 545 

how to create contact using URL parameter (id,name,email),if contact id is empty it must throw exception erorr using JSON method in HttpPost method apex class

SandhyaSandhya (Salesforce Developers) 
Hi,

In Post method to throw error you can use response.Status = 'Success';
response.ErrorCode, response.Message.

Refer below link which has sample code for the same.

http://www.oyecode.com/2014/08/start-building-your-own-rest-api-in.html
 
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya
 
Shubham NandwanaShubham Nandwana
Hi Sunil,
You can retrieve URL parameters in salesforce using 
String paramValue=ApexPages.currentPage().getParameters().get('myParamName')
You can check https://salesforce.stackexchange.com/questions/161429/rest-error-handling-design for exception handling in rest.
You can also use custom exceptions to show error, refer to https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_custom.htm.
Hope it helps, mark it as solved if it does.

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts