1

Just started with Apex last week so very new. Building a @RestResource to pick up webhooks sent from an external DB. Code has been tested and working as expected in Sandbox. Can not get the unit test to run to move to production.

Error - classes/RobinRestResourceTest.cls: Method does not exist or incorrect signature: void doPost(String, String, String, String, String, String, String, String) from the type RobinRestResourceOrg

@RestResource(urlMapping='/Prod/Org/*')
   global without sharing class RobinRestResourceOrg {

@HttpPost
 //Pass in webhook payload  
 global static String doPost(Integer id, String org_name, String org_id, 
 String owner_email, String owner_domain, Integer owner_id, Integer is_trial,
 String org_slug) {

//Look for any matching SFDC records to continue (custom ID then account 
domain)
List<Robin_Organization__c> orgs = [SELECT Id FROM Robin_Organization__c WHERE Name =: org_id];
    if(orgs.isEmpty()) { List<Account> accounts = [SELECT Id FROM Account WHERE Company_Domain__c =: owner_domain];
    if(accounts.isEmpty()) { return 'No matching SFDC Account Record';}
                        }

//Update or create records ......

Test class

@isTest
private class RobinRestResourceTest{

static testMethod void webhookTest(){

//Test objects
Account Testacct = new Account();
Testacct.name = 'Dylan';
insert Testacct;

RestRequest request = new RestRequest();
request.requestUri ='/services/apexrest/Prod/Org';
request.httpMethod = 'POST';
RestContext.request = request;
Test.startTest();
RobinRestResourceOrg.doPost('1','Dylan Inc','43','dylan@dylan.com','dylan.com','1','0','DylanWil');
Test.stopTest();

Error - Result: [OPERATION FAILED]: classes/RobinRestResourceTest.cls: Method does not exist or incorrect signature: void doPost(String, String, String, String, String, String, String, String) from the type RobinRestResourceOrg (Line: 16, Column: 26)

Already looked around by error seems generic and could not pin point a solution.

1
RobinRestResourceOrg.doPost('1','Dylan Inc','43','dylan@dylan.com','dylan.com','1','0','DylanWil');

You need to match the data types. The REST API does this for you automatically, but you need to respect the data types when calling the method directly:

RobinRestResourceOrg.doPost(1,'Dylan Inc','43','dylan@dylan.com','dylan.com',1,0,'DylanWil');
  • Wow, and like that you saved me countless time. Thanks a ton!! – Dylan W Mar 9 '18 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.