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
Aishwarya P 4Aishwarya P 4 

The 'updateOlderAccounts' method did not update account records as expected

public class OlderAccountsUtility
{
    public static void updateOlderAccounts()
    {
        List<Account> lstacc = [SELECT ID,Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
        
        for(Account acc : lstacc)
        {
            acc.Description = 'Heritage Account';
        }
        
        try
        {
        update lstacc;
        }
        catch(exception e)
        {
        }
    }
}


when i execute this code it is giving an error:
"Challenge Not yet complete... here's what's wrong: 
The 'updateOlderAccounts' method did not update account records as expected "

PLease help me with this
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000DCoXIAW
2) https://developer.salesforce.com/forums/?id=906F0000000BaFQIA0
 
public class OlderAccountsUtility {
	public static void updateOlderAccounts() {
		// Get the 5 oldest accounts
		Account[] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
		// loop through them and update the Description field
		for (Account acct : oldAccounts) {
			acct.Description = 'Heritage Account';
	   }
	   // save the change you made
	   update oldAccounts;
	}
}
Let us know if this will help you
 
Trailhead StrangerTrailhead Stranger
Thanks for the code Amit Chaudhary 8, It worked for me. 
Apeksha AdoorApeksha Adoor
Thank you this helped me 
Greg Morancey 16Greg Morancey 16
I receive this error:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Update failed. First exception on row 3 with id 0018Y00002x6iJ4QAI; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Account number must be 8 characters long.: []
Any ideas why? Do I have t ocreate a custom object first? I am just following instructions? Seems simple but?
 
Greg Morancey 16Greg Morancey 16
Launched another playground and it verified it properly in that one. Strange enough. Moving on.