Activity Forums Salesforce® Discussions What other method we can apply to access id instead of giving direct id in Salesforce?

  • What other method we can apply to access id instead of giving direct id in Salesforce?

    Posted by Deepak on January 21, 2020 at 12:56 pm
    public class sample {
    public Boolean batchStatusBool {get;set;}
    public String batchStatus {get;set;}
    public integer batch1 {get;set;}
    public integer batch2 {get;set;}
    Id batchId;
    public Boolean pollerBool {get;set;}
    
    public sample() {
    batchStatusBool = false;
    pollerBool = false;
    }
    
    public void callAcctUpdateBatch() {
    batchStatusBool = true;
    updatecontact obj = new updatecontact();
    
    checkBatchStatus();
    }
    
    public void checkBatchStatus() {
    AsyncApexJob job = [SELECT Id,totaljobitems,Status,NumberOfErrors FROM AsyncApexJob WHERE Id ='7072w000002G7IP'];
    batchStatus = job.Status;
    batch1 = job.totaljobitems;
    batch2 = job.NumberOfErrors;
    if(batchStatus == 'Completed') {
    pollerBool = false;
    
    } else {
    pollerBool = true;
    }
    }
    }
    
    

    What other method we can apply to access id instead of giving direct id?

    • This discussion was modified 4 years, 3 months ago by  Deepak.
    krati replied 4 years, 3 months ago 2 Members · 1 Reply
  • 1 Reply
  • krati

    Member
    January 21, 2020 at 5:23 pm

    Here you can make a public String variable and where you are calling your batch class store the value of the batchJob. For Example:

    public class SomeClass{
        Id batchProcessId;
    
    public void callBatchPieChartClass(){
            
            Algoworks_BatchClassPieChart batchClass = new Algoworks_BatchClassPieChart();
            batchProcessId = Database.executeBatch(batchClass);
        }
    
    // In another method you can have the value of that JobId.
    
    public void getJobID() {
            
         AsyncApexJob  asyn = [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors
                           FROM AsyncApexJob WHERE ID =: batchProcessId ];
    }
    }

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos