2

We have created several RecordTypes for Assets.

I am building a class to insert them.

First I tried my usual approach:

Asset myAsset = new Asset( Name = 'Test', 
                              RecordType = new Recordtype (Name = 'myRecordType'),
                              Status = 'active'
                              );

Which gave me:

Error: Invalid Field RecordType for sObject Asset

Darn, I thought, so let's use an Id.

Asset myAsset = new Asset( Name = 'Test', 
                                  RecordTypeId = '012 ...'),
                                  Status = 'active'
                                  );

Error:

Invalid Field RecordTypeId for sObject Asset

I am at loss now. How do I insert an Asset with a RecordType when I can neither use RecordType nor RecordTypeId on this object?

Is this a known issue? Assets didn't have RecordTypes from the beginning, so maybe I am missing something?

  • 2
    Please include which API Version(s) you have tested this functionality with. – Adrian Larson Jul 4 '16 at 19:05
  • Excellent point! I have tested the code in my dev org with execute anonymous, so we should have used 37. It didnt work there. After updating api version on my mentioned class, though, it compiles fine on v37 – Christian Szandor Knapp Jul 4 '16 at 19:12
  • Can you check if your profile has access to the RecordType you are trying to set? I believe an Apex Class would run in system mode, whereas Execute Anonymous runs in user mode. So this might highlight a permissions issue. – Adrian Larson Jul 4 '16 at 19:14
  • All good now. My error in the Dev Org was not to have checked if there were recordtypes on Asset. After creating one, all worked well. Thank you so much, Adrian. – Christian Szandor Knapp Jul 4 '16 at 19:17
  • 1
    I will also take careful note on how u edited my post and adapt stylings for my next :) – Christian Szandor Knapp Jul 4 '16 at 19:22
2

As Adrian Larson pointed out, the issue was self-inflicted.

I used a dated API version in the class where I wrote the insert code.

For all who might experience the same:

RecordTypes on Assets are supported on API Version 33 or higher.

Salesforce Spring 15 Release Notes on Asset RecordTypes

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.