You need to sign in to do that
Don't have an account?
Harry Smith 5
Need urgent help with an error
We are making an order into Salesforce Staging and getting the following error, and the error issue blocking for an order to be submitted:
[[Error extendedErrorDetails='{[0]}'
fields='{[0]}'
message='Opportunity: execution of BeforeInsert
caused by: System.ListException: List index out of bounds: 0
Class.Util_CustomMetadata.query: line 71, column 1
Class.Util_CustomMetadata.getSwitch: line 47, column 1
Class.Util_CustomMetadata.isSwitchActive: line 56, column 1
Trigger.Opportunity: line 3, column 1'
statusCode='CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY'
]
]
[[Error extendedErrorDetails='{[0]}'
fields='{[0]}'
message='Opportunity: execution of BeforeInsert
caused by: System.ListException: List index out of bounds: 0
Class.Util_CustomMetadata.query: line 71, column 1
Class.Util_CustomMetadata.getSwitch: line 47, column 1
Class.Util_CustomMetadata.isSwitchActive: line 56, column 1
Trigger.Opportunity: line 3, column 1'
statusCode='CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY'
]
]
Greetings to you!
If you then attempt to access an element at row 0, it'll throw an error as that row doesn't exist. It's good practice to check there are records first in order to make sure that the list is not empty before accessing it.
Check if list is empty:
Before referring to the 0th index of list you must perform a check on whether the list is empty or not. Whenever you try to access records from list first check if its empty or not.
Considerations for empty list:
Reference: https://help.salesforce.com/articleView?id=000181121&type=1
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas