I am a newbie to Apex and trying to debug the code written by previous developers. Some of the triggers are giving index out of bound error and I am trying to troubleshoot. I am unable to recreate the scenario that causes the error so wondering what the best approach would be.
When does it throw the 'out of bounds' error? During an API transaction (data load, integration, ect)? Or do end-users report it when they are in the UI?
An out of bounds error usually refers to the code accessing an item in a collection (array, list, set, map) that doesn't exist.
Also, make sure the code has sufficient System.debug() statements to help you read the Debug Logs.
Getting the out of bound error when doing an insert in the account object and I checked the recordids and they both exist.
system.debug(searchnames); if(!SearchNames.isempty()) { for(Account b:[select id, name, OwnerId, Affiliation__c, Master_Account__c from Account where name in :SearchNames and (recordtypeid = '01240000000M1ugAAC' or recordtypeid = '01240000000M1uWAAS')]) { HierarchyAccounts.put(b.Name, b); } } system.debug(hierarchyaccounts);
Here is the documentation on debugging apex.
Albert,
I am not able find the link .Can you post m,e the right link.
Thanks
Gopi
Where writing code please put possible System.debug () statements in the code.
2.Try to print the exception in the log do't leave it.It will helpful upto some extent.
Sorry about the link not working. Go to the Apex Developer Guide here: http://www.salesforce.com/us/developer/docs/apexcode/index.htm. Then click on the sub section titled "Debugging Apex".
Thanks Gopi and Albert,
I am a newbie to Apex and trying to debug the code written by previous developers. Some of the triggers are giving index out of bound error and I am trying to troubleshoot. I am unable to recreate the scenario that causes the error so wondering what the best approach would be.
Chitra
When does it throw the 'out of bounds' error? During an API transaction (data load, integration, ect)? Or do end-users report it when they are in the UI?
An out of bounds error usually refers to the code accessing an item in a collection (array, list, set, map) that doesn't exist.
Also, make sure the code has sufficient System.debug() statements to help you read the Debug Logs.
Getting the out of bound error when doing an insert in the account object and I checked the recordids and they both exist.
system.debug(searchnames);
if(!SearchNames.isempty())
{
for(Account b:[select id, name, OwnerId, Affiliation__c, Master_Account__c from Account where name in :SearchNames and (recordtypeid = '01240000000M1ugAAC' or recordtypeid = '01240000000M1uWAAS')])
{
HierarchyAccounts.put(b.Name, b);
}
}
system.debug(hierarchyaccounts);
How many records are returned in the soql query? How many records are in the HierarchyAccounts collection? Are you inserting a null object?
I recommend adding more System.debug statements to see more details of the code execution.