3

Given a list of Account ID's, I want to get all assets associated with them.

So far, I worked out I can get the account by calling :

/services/data/v32.0/sobjects/Account/{accountId}

Seems simply enough. However this object does not contain assets (Or even Asset ID's) in the response.

I then called

services/data/v32.0/sobjects/

In the hope that this would give me more info on how to get the assets associated with an account. It does infact return some documentation on possible ways to get individual assets.

/services/data/v32.0/sobjects/Asset/{ID}

But the {ID} is infact the AssetID, not the AccountID.

Is there any way, given an accountID, to get all assets associated with them via REST (Not SOAP, SOQL etc).

4

You can execute SOQL via the REST API:

/services/data/v36.0/query/?q=SELECT+Name+FROM+Asset+WHERE+AccountId+=+'001000000000AAA'


Just for fun completeness, it is nigh trivial to use Apex REST and be truly RESTful. Better to avoid Apex though, as you indicate is your intention.

@RestResource(urlMapping='/AssetsByAccount/*')
global class AccountAsset
{
    @HttpGet
    global static List<Asset> getChildren()
    {
        return [
            SELECT Name FROM Asset WHERE AccountId = 
            :RestContext.request.requestUri.substringAfterLast('/')
        ];
    }
}

/services/apexrest/AssetsByAccount/001000000000AAA

  • Not reeaalllyyy RESTful though is it :). But it works! Thanks! – MindingData Jun 2 '16 at 23:28
  • Ha good point. Well, you could make it truly RESTful by writing a @RestResource via Apex, but not worth the trouble unless you're really a purist. – Adrian Larson Jun 2 '16 at 23:30
  • @Mind technically one-line-able: @RestResource(urlMapping='/AssetsByAccount/*') global class AccountAsset{@HttpGet global static List<Asset> getChildren(){return [SELECT Name FROM Asset WHERE AccountId =:RestContext.request.requestUri.substringAfterLast('/')];}} – Adrian Larson Jun 3 '16 at 0:14

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.