function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Carissa CrittendenCarissa Crittenden 

Apex Test Class Error - Method does not exist or incorrect signature

I am super new to Apex and consequently struggling through. I created an Apex class with the intent that I will trigger it with Process Builder. I built a test class for it and I'm getting the error "Method does not exist or incorrect signature: void updateCustomer(Id) from the type CustomerAccountingUpdate.

Here's my Apex Class:
public class CustomerAccountingUpdate {
        
    public static string updateCustomer(Account aAccount) {
    	aAccount.c2g__CODAAccountsReceivableControl__c = System.Label.GeneralLedgerAcctsRec;
        aAccount.c2g__CODASalesTaxStatus__c = 'Taxable';
        aAccount.c2g__CODATaxCode1__c = 'AvaTax';
        aAccount.c2g__CODADaysOffset1__c = 0;
        aAccount.c2g__CODADescription1__c = 'Due Upon Receipt';
       
        update aAccount;
        
        return 'success';
    }
}


And my test Class:
@isTest(SeeAllData=true)
public class CustomerAccountingUpdateTest {
	static private Account setUpTestEnvironment() {          
         Account a =  new Account(
                               Name = 'Test Accounting Test'
                               ,Type = 'Prospect'            				   
                           );
         insert a;
        return a;
    }
    static testMethod void AccountingUpdateTest() {
         Account a = setUpTestEnvironment();
   
         Test.startTest();
         
         CustomerAccountingUpdate.updateCustomer(a.id);
         
         Test.stopTest();
    }
}


Thanks so much - this is the first time I've written a class & test totally from scratch rather than modifying something that was already there so I have no idea where I'm going wrong.
 
Best Answer chosen by Carissa Crittenden
Marcelo CostaMarcelo Costa
Hi Clarissa!!
A few things to note:
Your method is expecting an Account, and you are passing an Id.
Try to change: CustomerAccountingUpdate.updateCustomer(a.id); to CustomerAccountingUpdate.updateCustomer(a);
That said, avoid using SeeAllData=true on testclasses. (not good practice :))

Good luck!!!

 

All Answers

Marcelo CostaMarcelo Costa
Hi Clarissa!!
A few things to note:
Your method is expecting an Account, and you are passing an Id.
Try to change: CustomerAccountingUpdate.updateCustomer(a.id); to CustomerAccountingUpdate.updateCustomer(a);
That said, avoid using SeeAllData=true on testclasses. (not good practice :))

Good luck!!!

 
This was selected as the best answer
sfdcMonkey.comsfdcMonkey.com
Hey Carissa Crittenden,
you got this error because in your apex class method you are using the account as a method parameter, and in your test class you are passing the account id,

use below test class :
 
@isTest(SeeAllData=true)
public class CustomerAccountingUpdateTest {
	static private Account setUpTestEnvironment() {          
         Account a =  new Account(
            Name = 'Test Accounting Test'
            ,Type = 'Prospect'            				   
            );
         insert a;
        return a;
    }
    static testMethod void AccountingUpdateTest() {
         Account a = setUpTestEnvironment();
   
         Test.startTest();
         
         CustomerAccountingUpdate.updateCustomer(a);
         
         Test.stopTest();
    }
}

Please follow below salesforce Best Practice for Test Classes :-

1. Test class must start with @isTest annotation if class class version is more than 25
2. Test environment support @testVisible , @testSetUp as well
3. Unit test is to test particular piece of code working properly or not .
4. Unit test method takes no argument ,commit no data to database ,send no email ,flagged with testMethod keyword .
5. To deploy to production at-least 75% code coverage is required
6. System.debug statement are not counted as a part of apex code limit.
7. Test method and test classes are not counted as a part of code limit
9. We should not focus on the  percentage of code coverage ,we should make sure that every use case should covered including positive, negative,bulk and single record .
Single Action -To verify that the the single record produces the correct an expected result .
Bulk action -Any apex record trigger ,class or extension must be invoked for 1-200 records .
Positive behavior : Test every expected behavior occurs through every expected permutation , i,e user filled out every correctly data and not go past the limit .
Negative Testcase :-Not to add future date , Not to specify negative amount.
Restricted User :-Test whether a user with restricted access used in your code .
10. Test class should be annotated with @isTest .
11 . @isTest annotation with test method  is equivalent to testMethod keyword .
12. Test method should static and no void return type .
13. Test class and method default access is private ,no matter to add access specifier .
14. classes with @isTest annotation can't be a interface or enum .
15. Test method code can't be invoked by non test request .
16. Stating with salesforce API 28.0 test method can not reside inside non test classes .
17. @Testvisible annotation to make visible private methods inside test classes.
18. Test method can not be used to test web-service call out . Please use call out mock .
19. You can't  send email from test method.
20.User, profile, organization, AsyncApexjob, Corntrigger, RecordType, ApexClass, ApexComponent ,ApexPage we can access without (seeAllData=true) .
21. SeeAllData=true will not work for API 23 version eailer .
22. Accessing static resource test records in test class e,g List<Account> accList=Test.loadData(Account,SobjectType,'ResourceName').
23. Create TestFactory class with @isTest annotation to exclude from organization code size limit .
24. @testSetup to create test records once in a method  and use in every test method in the test class .
25. We can run unit test by using Salesforce Standard UI,Force.com IDE ,Console ,API.
26. Maximum number of test classes run per 24 hour of period is  not grater of 500 or 10 multiplication of test classes of your organization.
27. As apex runs in system mode so the permission and record sharing are not taken into account . So we need to use system.runAs to enforce record sharing .
28. System.runAs will not enforce user permission or field level permission .
29. Every test to runAs count against the total number of DML issued in the process .
 
happy learning,
  Let us know it it helps you, and kindly close your query by choosing best answer if you got your answer
Thanks
http://sfdcmonkey.com
Carissa CrittendenCarissa Crittenden
Thanks so much for the help! That fixed it. I learn by doing and making mistakes so I'll remember this in the future. Thanks all!
palash paunikar 6palash paunikar 6
<apex:page controller="setterGetterapex_classss" >
    <apex:form>
        <apex:pageBlock title="My Calculations">
            <apex:pageBlockButtons>
                <apex:commandButton value="ADD" action="{!add}"/>
                <apex:commandButton value="SUB" action="{!sub}"/>
            </apex:pageBlockButtons>
        <apex:pageBlockSection title="Simple Operations">
            <apex:pageBlockSectionItem>
                <apex:outputLabel>Enter x value</apex:outputLabel>
                <apex:inputText value="{!xvalue}"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem>
                <apex:outputLabel>Enter y value</apex:outputLabel>
                <apex:inputText value="{!yvalue}"/>                
            </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
         </apex:pageBlock>
    </apex:form>
</apex:page>


Error:Apex class 'setterGetterapex_classss' does not exist
Sudheekar Reddy 6Sudheekar Reddy 6

Hello Techies,

I hope every one stay Safe & Good,
In this Pndemic situation, have been struggling with the below scenario.

Step1: Using Process Builder retrieving values of Two Obejcts (Case & Model__C)
Step2: Passing those values to REST Service and Receiving response back from the service
Step3: Now I need to Update the Intent field of Case Object with Received response.
Note: I am able to updating the Intent field without Class function by executing at Anonymous Window. But facing with issue with Apex Class function. I would really appreaciate you in advance if you make me come out from this problem.

The complete Apex code for above scenario
public class callingRESTapiDemo {
  @InvocableMethod
  public static void caseObjectData(List<Id> caseIdList)
   {
    List<List<sObject>> caseModelList = [FIND '00001* OR M-00*' IN ALL FIELDS RETURNING Case(Subject),
    Model__c(Project_Name__c, Model_Name__c, ServiceURL__c where Project_Name__c='vijay' AND Type__c ='IN' AND SF_Object__c ='Case')];
    System.debug('Total results=====>' + caseModelList);
    Case[] caseList=(Case[])caseModelList[0];
    Model__c[] modelList=(Model__c[])caseModelList[1];
    System.debug('Case List VAlues ==> '+ caseList);
    System.debug('Model List VAlues ==> '+ modelList);
    String projectName = modelList[0].Project_Name__c;
    String modelName = modelList[0].Model_Name__c;
    String serviceURL = modelList[0].ServiceURL__c;
    String subject = caseList[caseModelList.size()-1].Subject;
    System.debug('Project Name ==>'+projectName);
    System.debug('Model Name ==>'+modelName);
    System.debug('Service URL ==>'+serviceURL);
    System.debug('Subject ==>'+subject);

//Callout REST Service
    doCallOutAndUpdate(projectName, modelName, subject, serviceURL, caseIdList);
   }
  @future(callout=true)
  public static void doCallOutAndUpdate(String projectName, String modelName, String subject, String serviceURL, List<Id> caseIdList)
  {
    JSONGenerator gen = JSON.createGenerator(true);
    gen.writeStartObject();
    gen.writeStringField('project_name', projectName);
    gen.writeStringField('file_name',modelName);
    gen.writeStringField('INPUT',subject);
    gen.writeEndObject();
    String jsonS = gen.getAsString();
    system.debug('jsonMaterials'+jsonS);
    http h = new http();
    HttpRequest req = new HttpRequest();
    req.setMethod('POST');
    req.setEndpoint(serviceURL);
    req.setHeader('Content-Type', 'application/json;charset=UTF-8');
    req.setBody(jsonS);
    HttpResponse response = h.send(req);
    List<Object> results = (List<Object>) JSON.deserializeUntyped(response.getBody());
    System.debug('Response received from REST API ==>'+results[0]);
    Map<String, Object> resp = (Map<String, Object>)results[0];
    String intent = String.valueOf(resp.get('Label'));
    System.debug('Subject Field to be updated with Label ==>'+intent);
    List<Case> caseList = [SELECT Intent__c FROM Case WHERE Id in: caseIdList];
    caseList[caseList.size()-1].Intent__c=intent;
    update caseList;
  }
}
Calling the above Class (callingRESTapiDemo) and method (caseObjectData) to execute at Anonymous Window.
User-added image
Getting below error as shown below
Error Part