Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Account> accounts = [SELECT Id, Account_Number__c FROM Account ORDER BY CreatedDate ASC];
- List<Account> accountsUpdate = new List<Account>();
- Integer HOW_MANY_OBJECTS_AT_ONCE = 1100;
- Integer counter, endCounter;
- String templateOfField = '';
- Integer indexOfNOTFilledAccountNumberField = 0;
- for (Account account : accounts) {
- if (String.isBlank(account.Account_Number__c)) {
- indexOfNOTFilledAccountNumberField = accounts.indexOf(account);
- break;
- }
- }
- counter = indexOfNOTFilledAccountNumberField;
- endCounter = indexOfNOTFilledAccountNumberField + HOW_MANY_OBJECTS_AT_ONCE - 1;
- for (; counter < accounts.size(); counter++) {
- templateOfField = 'A-';
- if(counter < 1000) {
- if (counter < 10) {
- templateOfField += '000';
- } else if (counter < 100) {
- templateOfField += '00';
- } else {
- templateOfField += '0';
- }
- }
- if (String.isBlank(accounts.get(counter).Account_Number__c)) {
- accounts.get(counter).Account_Number__c = templateOfField + String.valueOf(counter);
- accountsUpdate.add(accounts.get(counter));
- }
- if (accountsUpdate.size() == endCounter) {
- break;
- }
- }
- System.debug('accounts.size() = ' + accounts.size());
- if (accountsUpdate.size() > 0) {
- System.debug('indexOfNOTFilledAccountNumberField = ' + indexOfNOTFilledAccountNumberField);
- System.debug('accountsUpdate.size() = ' + accountsUpdate.size());
- update accountsUpdate;
- } else {
- System.debug('*****UPDATE FINISHED*****');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement