You need to sign in to do that
Don't have an account?
Henrique Rodrigues
How to develop a test class for Rest webservice
Hello everyone, i'm developing a webservice in rest and i have no ideia about how write a test class in this case and this is my code
how can I make a test class with 100% of code coverage?
@RestResource(urlMapping='/upsertaccount') global with sharing class WSCustomerEdit { @HttpPost global static Account doPost(){ String accountJSON = RestContext.request.requestBody.toString(); JsonAccount serializedAcc = (JsonAccount)(JSON.deserialize(accountJSON, JsonAccount.class)); Account acc = [SELECT Id FROM Account WHERE id =: serializedAcc.Id]; acc.Name = serializedAcc.name; acc.Phone = serializedAcc.phone; upsert acc; return acc; } global class JsonAccount{ public String id {get;set;} public String name {get;set;} public String phone {get;set;} public String address {get;set;} } }and my test class
@isTest public class CustomerEditTest { @isTest static void teste(){ WSCustomerEdit.JsonAccount acc = new WSCustomerEdit.JsonAccount(); acc.id = 'test'; acc.name = 'NameTest'; acc.phone = '1198785496'; acc.address = 'Rua x'; String myJSON = JSON.serialize(acc); } }
how can I make a test class with 100% of code coverage?
Let us know if this will help you
All Answers
Let us know if this will help you
https://newstechnologystuff.com/2020/05/27/test-salesforce-rest-api-using-postman/
If this answer helps you, please mark it as accepted.
Regards,
Tushar Sharma
https://newstechnologystuff.com/