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
Shilpa SrikantacharShilpa Srikantachar 

Method does not exist or incorrect signature: error

Hi All,

I'm a beginner in Development and trying to execute few example programs 

public class Static_Example {
           public static Integer aval=0;    
        public Integer bval    =0;
        public void add(){
            aval=aval+10;
            bval=bval+10;
        }
    

}

public class Static_Example {
           public static Integer aval=0;    
        public Integer bval    =0;
        public void add(){
            aval=aval+10;
            bval=bval+10;
        }
    

}
Error :

Line: 3, Column: 6
Method does not exist or incorrect signature: void add() from the type Static_Example

Please let me know the mistake I have done.

Thanks
Shilpa
SarvaniSarvani
Hi Shilpa,

Your code looks good. If you are trying to directly execute Static_Example.add() you will get this error. Since you have non static method add() in your class you need to first istantiate your class and call your method.

Try Executing below in your Execute Anonymus window to run your class:
Static_Example Ex=new Static_Example();
Ex.add();
Please refer below link:
https://www.sfdc99.com/2015/01/22/introduction-to-the-static-keyword/

Hope this helps. Please mark as best answer if it does.

Thanks
Shilpa SrikantacharShilpa Srikantachar
This is what I am trying to execute . Even though I have instantiated , I still see the error . What could be the issue ?Pls let me know . Thank you Shilpa
SarvaniSarvani
Hi Shilpa,

Hope you have apex class named  Static_Example with method add() in your code as below 
User-added image

And trying to execute the below code in your anonymus window:
Static_Example Ex=new Static_Example();
Ex.add();
It should work fine with no errors I have tested in my org. Please paste your apex class code and lines your trying to execute in anonymus window if your still facing the problem. Because your error says line 3
Error :

Line: 3, Column: 6
Method does not exist or incorrect signature: void add() from the type Static_Example


Where you only have 2 lines in you anonymus window if your trying the same.

Hope this helps!

Thanks
Shilpa SrikantacharShilpa Srikantachar
Hi Sarvani ,

Thank you for taking the time and trying it out before answering .

However , this is the execution that  I am trying and getting an error .

Static_Example one =new Static_Example();
Static_Example two =new Static_Example();
one.add();
    System.debug('Aval:'+Static_Example.aval);
    System.debug('One :Bval:'+one.bval);
    System.debug('Two :BVal:'+two.bval);
two.add();
    System.debug('Aval:'+Static_Example.aval);
    System.debug('One :Bval:'+one.bval);
    System.debug('Two :BVal:'+two.bval);

Execute Anonymous Error :

Line: 3, Column: 5
Method does not exist or incorrect signature: void add() from the type Static_Example


Thanks
Shilpa
SarvaniSarvani
Can you please screenshot your apex class too ?
Shilpa SrikantacharShilpa Srikantachar
Static
Please find the APEX class .



Regards
Shilpa
 
SarvaniSarvani
Hi Shilpa,

Unfortunately. I am unable to replicate the issue with the codes above. Its  working fine for me. I understand you are trying to know the difference between using and not using static keywords for the method. I suggest you to try the same example in different new org and test. It might be because of existing classes some times. 

Hope this helps!

Thanks,
Sarvani