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
ranendu banerjeeranendu banerjee 

Parameterized method

I want to call a method which has a id as parameter. i want to call that method in constructor. how to do it ?
NagaNaga (Salesforce Developers) 
Hi Ranendu,

You can pass information via the database, the basic steps are this... 

Use the Id returned from the System.schedule method 
After scheduling the job insert a record into a Custom Object (e.g. Schedule Info) that contains the information you want the job to read when it executes. Being sure to also store the job Id on the record. 
Then in the execute method use the SchedulableContext.getTriggerId (confusing name i know) method to obtain the job Id and query the record previously written for the information needed. 
You should consider putting in a try/finally some cleanup code to delete the record once the execute completes.

Apologies for not giving a code sample here, let me know if you need one and I can work one up.

NOTE: You may also want to consider using a List type protected Custom Setting, which has the benifit of saving DML, SOQL and is hidden from the end users.

Please let me know if this helps

Best Regards
Naga Kiran
Nayana PawarNayana Pawar
Hi ,

Please check below code:

public TestController {
   

    public TestController() {
        testMethod(ApexPages.getCurrentPage().getParameters());
    }

    public TestController(Id fromTestId) {
        testMethod(fromTestId);
    }

    private void testMethod(Id inputId) {
        
    }
}
softmain dotinsoftmain dotin
Please check below code:
public class testing2 {
    public integer a;
    public integer b;
    public integer c;
    
    Public testing2(){
        
    }
    Public void abc4(integer k,integer p){
        integer g=0;
        g=k+p;
        system.debug('new result='+g);
    }
}
detail knowledge class,constructor,method and parametrize method check below link 
http://www.softmain.in/2017/08/apexclass.html