You need to sign in to do that
Don't have an account?
Kunal Purohit 4
Hi I am new to integration i need to write the Mock Test class for my webservice test class, i am stuck , please help me to create the mock call out in the APEX
@RestResource(urlMapping='/Projects/*') global class GetProjectsFromTeamWork { @HttpPost global static void doPost() { RestRequest req = RestContext.request; String jsonresponse = req.requestBody.toString(); system.debug('jsonresponse=='+jsonresponse); wrapperOfProject proj = (wrapperOfProject)JSON.deserialize(jsonresponse, wrapperOfProject.class); Contact contactRefference = new Contact(UserId__c = proj.Project.ownerId); List<Account> accList = [Select id From Account Where CompanyId__c = :proj.Project.companyId]; system.debug('accList==='+accList); List<Opportunity> oppList = [Select id from Opportunity Where AccountId = :accList[0].id]; System.debug('oppList==='+oppList); TW_Project__c projectObj = new TW_Project__c(); projectObj.Name = proj.Project.name; projectObj.TW_Description__c = proj.Project.description; projectObj.TW_Opportunity__c = oppList[0].id; projectObj.ProjectId__c = proj.Project.id; projectObj.TW_Project_Manager__c = contactRefference.id; insert projectObj; } public class wrapperOfProject{ public eventCreator eventCreator; public Project project; } public class EventCreator { public Integer id; public String firstName; public String lastName; public String avatar; } public class Project { public String id; public String name; public String description; public String status; public Object startDate; public Object endDate; public List<Tags> tags; public String ownerId; public String companyId; public String categoryId; public String dateCreated; } public class Tags { } }
Greetings!
Please refer the below thread for the sample code for Mock test class where you need to create the dummy endpoint to test the callout.
https://salesforce.stackexchange.com/questions/279400/mock-test-class-for-post-web-service-test-class
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri