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
plapla 

Invalid constructor name

Hello,

 

I wrote a simple class to return a value but got the error message "Invalid constructor name". I'm not sure what caused the error. Below is my simple class. Please help. Thanks

 

public getCaseClient(Case aCase)

{

Account accName = [select id, parentId, name, Type fromAccountwhereId =: aCase.AccountId];

 

return accName.Type;

 

}

 

 

 

}

 

Paul

 

GunnarGunnar

(1) The constructor is inside the class, not a part of it.

(2) Constructors don't return values. If you want to return a value, use a method.

 

Try this ...

 

public class myClass
{
    myClass(string myParameter)
    {
    // my code
    }    
}
plapla

Thanks for your reply.

I want to return a value. How do you do that? Basically I have case ID, I want to pass a case ID to another method and it will query an associated account to return an account type value. Please advise.

 

Paul

 

CheyneCheyne

To do that, you could write a new method. To build on the example given above, something like

 

public class myClass
{
    myClass(string myParameter)
    {
    // my code
    }
    
    public String getValue(String caseId) {
        Case c = [SELECT Account.TextField FROM Case WHERE Id = :caseId];
        return c.Account.TextField;
    }
}

 

plapla

Hello,

I got an error message from a calling trigger that says "Method does not exist or incorrect signature: CaseClientAction.CaseClient(SOBJECT:Case)". Below is my trigger and the bottom is my class CaseClientAction. Please advise. Thanks

 

trigger

CaseClientUpdate onCase (beforeinsert, beforeupdate) {

String Clients;

String GroupNo;

String accName;

 

  accName = CaseClientAction.CaseClient(CaseUpdated);

 

}

 

 

public with sharing class CaseClientAction {

 

publicstatic String getCaseClient(String aCase){

 

Account accName = [select id, parentId, name, Type fromAccountwhereId =: aCase.AccountId];

 

returnaccName.Type;

 

 

}

 

 

}

 

Satish_SFDCSatish_SFDC
Well from the CaseClientAction, i understand that the name of the method is getCaseClient(...).

So instead of this,
accName = CaseClientAction.CaseClient(CaseUpdated);

use this
accName = CaseClientAction.getCaseClient(CaseUpdated);

Also what is CaseUpdated, is it something you have declared previously?

Regards,
Satish Kumar
plapla

Hello,

I modified to getCaseClient and still get the same error message. CaseUpdated is from the below statement. Thanks

 

Case CaseUpdated:trigger.new

 

CheyneCheyne

The way your code is designed, getCaseClient needs to accept a Case as the parameter, but it is currently accepting a String. Try changing 

 

publicstatic String getCaseClient(String aCase){

 

to 

 

publicstatic String getCaseClient(Case aCase){

plapla

Here's my complete trigger and class. Basically from a trigger I want to call the class and pass in the accountID as a parameter and then I want the class returns an account type value. Regardless of what I do I always get the error message "Method does not exist or incorrect signature: CaseClientActive.getCaseClient(String). I have changed the parameter from string to case to Id and now back to string but still get this error. Any help will be appreciated. Thanks

 

trigger CaseClientUpdate on Case (before insert, before update) {
    String Clients;
    String GroupNo;
    String accName;
    String accId;
   
 list<Case> CaseNullClient = new list<Case>();
 list<Case> CaseGroup = new list<Case>();
 list<Case> CaseCarrier = new list<Case>();
 list<Case> CaseAccount = new list<Case>();
 list<Case> CaseClient = new list<Case>();
        
     for(Case CaseUpdated:trigger.new){
       
       if (CaseUpdated.AccountId != null){         
       GroupNo = CaseUpdated.Group__c;
       accId = CaseUpdated.AccountId;
      
        if ((Trigger.ISINSERT) || (Trigger.ISUPDATE)){   
           
            accName = CaseClientAction.getCaseClient(accId);
         
     }  // Trigger insert/update 
 
    } // if accountId
      
   } // for structure
 

}

 


public with sharing class CaseClientAction {
  static string Clients;
 
   
    
    public String getCaseClient(String AId){
          
           Account accName = [select id, parentId, name, Type from Account where Id =: AId];       
       
           return accName.Type;
       
      
    }


}

CheyneCheyne

I believe the problem is that the CaseClientAction class has not been instantiated in the trigger. In the CaseClientUpdate trigger, you need to write the following line, somewhere before the for loop:

 

CaseClientAction action = new CaseClientAction()

 Then, the line where you actually get the account name will say 

 

accName = action.getCaseClient(accId);

 

plapla

Thanks. It works now. it also works if you put a static in the constructor method.

 

CHETNA YENNAWARCHETNA YENNAWAR
Hi,
this code showing me Error: 1.) Static isnot allowed on Contructor
2.) Invalid contructor name:myMethod

Can anyone explain Why?


public class listC {
    public static myMethod()
        {
            List<Integer> Num = new List<Integer>();
            Num.add(123);
            Num.add(456);
         
        }

}