+ Start a Discussion
Philip BonthaPhilip Bontha 

Hi All,I Have a requirement to provide the batch size through the custom label in the schedule job

I need to create custom label and value as batch size and the created custom field needs to invoke in schedule job.

Can someone help me on this.

Thanks in advance
PriyaPriya (Salesforce Developers) 
Hi Philip,

You can call a custom label likes below in your code
String test = Label.<custom label name>;



for example:
 
String test = Label.ok;
 

Please mark it as the Best Answer so that it can help others in the future.

Regards,

Priya Ranjan


 
mukesh guptamukesh gupta
Hi Philip,

Please follow below code:
 
public class UpdateContactAddresses implements
    Database.Batchable<sObject>, Database.Stateful {
    // instance member to retain state across transactions
    public Integer recordsProcessed = 0;
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT ID, BillingStreet, BillingCity, BillingState, ' +
            'BillingPostalCode, (SELECT ID, MailingStreet, MailingCity, ' +
            'MailingState, MailingPostalCode FROM Contacts) FROM Account ' +
            'Where BillingCountry = \'USA\''
        );
    }
    public void execute(Database.BatchableContext bc, List<Account> scope){
        // process each batch of records
        List<Contact> contacts = new List<Contact>();
        for (Account account : scope) {
            for (Contact contact : account.contacts) {
                contact.MailingStreet = account.BillingStreet;
                contact.MailingCity = account.BillingCity;
                contact.MailingState = account.BillingState;
                contact.MailingPostalCode = account.BillingPostalCode;
                // add contact to list to be updated
                contacts.add(contact);
                // increment the instance member counter
                recordsProcessed = recordsProcessed + 1;
            }
        }
        update contacts;
    }
    public void finish(Database.BatchableContext bc){
       
    }
}

Anoynumous window:-
String bacthSize= System.Label.DemoLabel;
UpdateContactAddresses myBatchObject = new UpdateContactAddresses();
Id batchId = Database.executeBatch(myBatchObject,bacthSize);

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh