0

There are similar questions but they hold no answers and are not specific.

Error Message / Test Failed during deployment of unrelated code:

Test_Method_Test    ThisTest    System.ListException: List index out of bounds: 0
Stack Trace: Class.Test_Method_Test.thisTest: line 101, column 1

Code that Passes when run during independent test, but fails during deployment. (last line below is line 101):

@isTest (SeeAllData=true)
private class Test_Method_Test {
    static testMethod void thisTest() {
        list<recordType> RTs = [SELECT id FROM RecordType WHERE SObjectType = 'Asset' AND Name = 'Machine Asset'];
        Asset a = new Asset();
        a.recordtypeId = RTs[0].id;

Asset exists and query returns 1 result.

Why would this fail during unrelated deployment? Seems like Salesforce Bug??? I will escalate to Partner Support, and provide back any updates.

0

Salesforce may come back later.

But solved the deployment issue by adjusting our test method. removing the RecordType Query, replacing it with Schema class capability.

Commented code was removed:

//list<recordType> RTs = [SELECT id FROM RecordType WHERE SObjectType = 'Asset' AND Name = 'Machine Asset'];
Schema.DescribeSObjectResult cfrSchema = Schema.SObjectType.Asset; 
Map<String,Schema.RecordTypeInfo> AssetRecordTypeInfo = cfrSchema.getRecordTypeInfosByName(); 
Id rtId = AssetRecordTypeInfo.get('Machine Asset').getRecordTypeId();

Asset a = new Asset();
//a.recordtypeId = RTs[0].id;
a.recordtypeId = rtId;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.