0

my last Asset issue was self inflicted. This time, I have made sure I use the hightest API version (v37). Following Code has been tested in a Dev Org and in a Sandbox.

    asset a = new Asset (
                  Name = 'Product Type C',
                  ProductFamily = 'Licence'
              );
    insert a;

I receive the error:

Invalid field ProductFamily for SObject Asset

I checked the Object Fields in the UI:

image of asset product family in ui

Then I went into the Workbench and was very surprised not to find ProductFamily on the Asset Object. It does not show up

assets in workbench

Nor does it show in the SOAP Api Documentation.

I can pull the field on the Asset Layout, but I did not manage to get it to show up. It is displayed readonly if I check layout properties. So I assumed that it might get pulled from Product2. It did not during my tests.

asset layout properties

It's not a big issue, I will use a custom picklist field instead - but I was wondering if somebody could illucidate me on how/when/why Asset.ProductFamily can be edited, shown on Page Layout, etc

Cheers, Sz

2

Product Family field on Asset works like a formula field. Its value is populated from Parent Product's Product Family field.

If you assign any product to the asset like

Product newProduct = new Product(Name = 'newProduct', ProductFamily = 'Licence');
insert newProduct;

asset a = new Asset (
                    Name = 'Product Type C',
                    AccountId = someAccount.Id,
                    Product2Id = newProduct.Id;
                    );
insert a;

Now you can see Product family populated.

  • 1
    A few things to note. The API names for the product object and product family field are Product2 and Family respectively. And it is necessary to specify AccountId when creating an asset as asset must have account and/or contact parent(s). – Vadim Rudkov Jul 5 '16 at 15:34
0

ProductFamily is actually not a real field on Sobject Asset. Instead for purposes of formulas, list views, etc. SFDC makes it available as a 'convenience' field as if it were a cross-object formula field.

Apex code that tries to manipulate someAssetVbl.ProductFamily will not compile. You will need to query someAssetVbl.Product2.Family after, of course, populating assets with a product2Id.

This is only one of many places where the list of fields in the OOB Force.com UI Object Fields page contains fields that are there for your convenience but don't really exist as concreate fields on the underlying SObject.

Note that the picklist for Product Family is shared by both Asset's "convenience" Product Family field and Product2.Family (the latter being a concrete SObject field).

Note also that Asset's Product Description and Product Code are also "convenience fields"; the real concrete field values are on Product2.

  • Thank you. crodpredy. This is what I assumed. The ProductFamily Field does not show on my layout, although there is a Product2 attached that has a Family and ProductCode. cf: layout picture above and this screenshot: drive.google.com/file/d/0B1MtGvdqXW1ZZjFmdHJNRVJIWkk/… – Christian Szandor Knapp Jul 5 '16 at 20:04
  • Product Family is available on the layout, you have to edit the layout and drag it into a section – cropredy Jul 5 '16 at 20:08
  • This is exactly what I did. – Christian Szandor Knapp Jul 5 '16 at 22:00
  • And if your assumptions are correct, @corpredy, why can I edit/add individual picklist values on Asset.ProductFamily in the Setup Area? – Christian Szandor Knapp Jul 6 '16 at 11:26
  • 1
    @ChristianSzandorKnapp - The Product Family picklist is shared (in setup) between Asset and Product. If you make any edits in either place, the results apply to both. This is another 'convenience' feature SFDC provides. – cropredy Jul 6 '16 at 14:12

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.