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
sailaja majji 5sailaja majji 5 

Invalid field RecordTypeId for SObject Asset

Hi ,

Below is the code in test class .

 Account acc= new Account( Name= 'testName', Phone ='0987654321', Customer_ID__c='111111111111' );
        insert acc;     
 Id recId2 =[Select Id from RecordType where DeveloperName = 'Card' ].ID;
        system.debug('rec Id2----'+recId2);
            
        Asset assetRec = new Asset(Name='test' ,AccountId = acc.Id, Asset_Number__c='123456789012345',Status='Inactive',RecordTypeId=recId2);
        insert assetRec;
      Asset assetRec2 = new Asset(Name='test2',AccountId = acc1.Id,  Asset_Number__c='456789123852741',Status='Active' );       
        insert assetRec2 ; 

This is giving an error "Invalid field RecordTypeId for SObject Asset"

I am runnign this as System Admin and have all required permissions for record Types
Running on version 37.0

Please help me understand if i am missing anything .

Thanks,
Sailaja
Alain CabonAlain Cabon
Test this:  Id recId2 =[Select Id from RecordType where DeveloperName = 'Card' and sObjecttype = 'Asset'].ID;

A recordtype is associated with an object (sObjecttype). "Card" can exists as a recordtype yet but not for the SObject Asset.

Alain
sailaja majji 5sailaja majji 5
Thanks Alain ,

I tried by changing the query but it still didnt work .Giving the same error .
Invalid field RecordTypeId for SObject Asset
Alain CabonAlain Cabon
Hello,

1)  Verify if your recordtype is Active.

User-added image

2)  try this new syntax
with the Name of your record type (not the developer name)

Id recId2 = Schema.SObjectType.Asset.getRecordTypeInfosByName().get('Card').getRecordTypeId();

( for me with the example above: Id recId2 = Schema.SObjectType.Asset.getRecordTypeInfosByName().get('agency1').getRecordTypeId(); )

Alain
sailaja majji 5sailaja majji 5
Hi Alain ,

I think the problem is not with the record type .
Becuase i am getting valid record type id .

The issue is i am not able to save the code becuase of this compiler  error and this comes while creating Asset with field name as RecordTypeId .

Thanks,
Sailaja