0

Can you help me with this test class.

Issue1: Method does not exist or incorrect signature: void getOpportunity(Id) from the type classController

Issue2: Method does not exist or incorrect signature: void createTask(Id, String, String, String, Date, Id) from the type classController

CLASS:

public with sharing class classController {

@AuraEnabled
public static Opportunity getOpportunity(String recordId, String grpComponent) {
    
    Opportunity opp = [SELECT Id, Name, AccountId, Account.Name, Opportunity_Auto_Number__c 
                       FROM Opportunity 
                       Where id=:recordId];
    return opp;
    
}

 @AuraEnabled
public static Group getGroup() {
    
    Group groupName = [SELECT Name, Id FROM Group WHERE Type = 'Queue' AND Name = 'Sales Support' LIMIT 1];
    
    return groupName;
    
}

@AuraEnabled
public static Id createTask(Id oppId, String accName, Id grpID, String oppNumber, String taskDescription, String taskInstruction, Date dueDate){
    system.debug('newTask: '+accName);
    
    //Create a new Task
    Task newTask = new Task();
    system.debug('newTask: '+accName);
    
    //Assigning Data for the New Task
    newTask.Subject = 'Please Mark as Closed Won';
    newTask.OwnerId = grpID;
    newTask.WhatId = oppId;
    newTask.Status = 'Open';
    newTask.ActivityDate = dueDate;
    newTask.Opportunity_Number__c = oppNumber; 
    newTask.Account_Name__c = accName;
    newTask.RecordTypeId = '01222000000hOAV';
    newTask.Task_Instructions__c = taskInstruction;
    newTask.Description = taskDescription; 

    //Inserting the New Task to the Opportunity Object
    try {
         insert newTask;
        
    } catch (Exception e) {
        
        System.debug(e.getMessage());
        EntLog_Logger.logException (e, 'Creat Task','getOpportunity', 'createTask'); 
    }
    

    return newTask.Id;

}
        
}

TEST CLASS

@isTest
public class classControllerTest {

 @testSetup 
static void testData() {
    
    //Create Opportunity Test Record Closed Won       
     Opportunity opp = new Opportunity(Name='NameTest',
                      Type = 'Repeat Business',
                      PD_FS_Product_Line__c = 'LMS',
                      CloseDate = date.parse('4/17/2026'),
                      StageName='Proposal',
                      ForecastCategoryName = 'Commit',
                      LeadSource = 'Email',
                      Lead_Sub_Source__c='Journey');
    
    insert opp;

   
    //Create a Group Queue for Sales Support
    Group g = new Group(Type='Queue', Name='Sales Support');
    insert g;
    
    //Insert the Queue to an SObject
    System.runAs(new User(Id=UserInfo.getUserId()))
    {
        QueuesObject testQueue = new QueueSObject(QueueID = g.id, SObjectType = 'Opportunity');
        insert testQueue;
    }
}
/**
* Method Name: getOpportunity
* Description: Test Method for getOpportunity
* */
@isTest
static void getOpportunity(){
    Id oppId = [SELECT Id FROM Opportunity WHERE Name = 'NameTest' LIMIT 1].Id;
    System.debug(oppId);
    Test.startTest();
    classController.getOpportunity(oppId);
    Test.stopTest();
    
    Opportunity oppProdAssert = [SELECT Id, Name FROM Opportunity WHERE Id = :oppId];
    system.assert(oppProdAssert != NULL);
} 
/**
 * Method Name: createTask
 * Description: Test Method for createTask
 * */
@isTest
static String createTask(){
    Id oppId = [SELECT Id FROM Opportunity WHERE Name = 'NameTest' LIMIT 1].Id;
    Date dueDate = date.today()+1;
    String taskDescription = 'Sample Description';
    String taskInstruction = 'Sample Instruction';
    Id accId = [SELECT AccountId FROM Opportunity WHERE Name =: 'NameTest' LIMIT 1].AccountId;
    String salesRep = [SELECT Owner.Name FROM Opportunity WHERE Name = 'NameTest' LIMIT 1].Owner.Name;
    String oppNumber = [SELECT Opportunity_Auto_Number__c FROM Opportunity WHERE Name = 'NameTest' LIMIT 1].Opportunity_Auto_Number__c;
    
    Test.startTest();
    classController.createTask(oppId, oppNumber, taskDescription, taskInstruction, dueDate, accId);
    Test.stopTest();
    
    Id queue = [SELECT Id FROM Group WHERE Type = 'Queue' AND Name = 'Sales Support' LIMIT 1].Id;
    System.assert(queue != null);
    
    //Create a Case
    Id classRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Default').getRecordTypeId();
    
    
    Task t = new Task(
                      Subject = 'Close it',
                      ActivityDate = System.today(),
                      Task_Instructions__c = 'Test Instruction',
                      Description= 'Test Description');
    
    insert t;
    
    System.assert(t != null);
    return t.Id;
}


}

1 Answer 1

0

The errors are very simple (and remarkably clear, at least for Salesforce).

A method signature consists of:

  • The return type
  • The name of the method
  • The number of arguments the method expects, along with their types, in order (left to right)

So the signature for your getOpportunity() method is Opportunity getOpportunity(String, String)

  • Return type = Opportunity
  • Method name = getOpportunity
  • 2 arguments of type String

In your test class, you're only passing a single string to getOpportunity(). Since getOpportunity()'s signature dictates that you pass it 2 strings, passing only one results in an error. All method arguments are required, you can't just leave out data. At the very least, you'll need to pass null (or an empty string) in for the second argument.

For your second error, you are both missing an argument (the method you're calling requires 7, your test is trying to call it with 6) and your arguments are not in the correct order. In your controller class, you defined the order to be createTask(Id, String, Id, String, String, String, Date){. You must stick to that exact order when calling createTask().

1
  • Thanks a lot!!!
    – Lhanz_404
    Jul 27, 2022 at 3:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .