+ Start a Discussion
David HickmanDavid Hickman 

Setting parent asset on child asset via Apex

Is it possible to set the parent id on an asset other than using the constructor method?  I need to set the parent id for an asset in a trigger method.  This code does not work:

a.parentId = parentAsset.id;

Results in:  Save error: Invalid field parentId for SObject Asset

My user does have access to the object and the parent field.  I can set the parent id using the constructor method:

Asset a = new Asset(name='test component with parent',
                    hin__c = 'CRC10890L516',
                    recordtype =bc,
                    dealer_key__c = '43536.001',
                    dealer_brand_key__c = '43536.001CL',
                    parentId = '02i54000000hS4aAAE') 

Unfortunately that will not work for my use case.

Ideas?
 

Best Answer chosen by David Hickman
pconpcon
What version of the API is your trigger using?  Are you able to run the same code in the developer console?  I just tried it in the developer console using API v37.0 and it worked as expected.

All Answers

pconpcon
What version of the API is your trigger using?  Are you able to run the same code in the developer console?  I just tried it in the developer console using API v37.0 and it worked as expected.
This was selected as the best answer
David HickmanDavid Hickman
Uggh,  I did not even think about the API version.  That was it.  Thank you