Loading

Revenue Cloud AssetStatePeriodAttribute Query Returns 0 Rows

Date de publication: Oct 22, 2026
Description

Symptom: SOQL Query Returns 0 Rows After insertImmediate

In Revenue Cloud (Revenue Lifecycle Management, abbreviated RLM), a SOQL query against AssetStatePeriodAttribute returns 0 rows immediately after a record is created with Database.insertImmediate() in Apex. This commonly happens inside an @isTest method after Test.stopTest(). No DML exception is thrown during the insert, so the record appears to be created successfully.

The behavior is consistent across approaches, including the CreateOrUpdateAssetFromOrder pattern and Test.startTest()/Test.stopTest() patterns.

Example: Insert Followed by an Immediate Query

The following Apex pattern reproduces the issue. It builds an AssetStatePeriodAttribute record with an asset state period ID, an attribute definition ID, and a text value of "TestValue". It then calls Database.insertImmediate() between Test.startTest() and Test.stopTest(), and runs a SOQL query that selects one AssetStatePeriodAttribute record.

AssetStatePeriodAttribute aspa = new AssetStatePeriodAttribute(
    AssetStatePeriodId = asp.Id,
    AttributeDefinitionId = attrDef.Id,
    AttributeValue = 'TestValue'
);

Test.startTest();
Database.insertImmediate(aspa);
Test.stopTest();

// Returns 0 rows:
List<AssetStatePeriodAttribute> result = [SELECT Id FROM AssetStatePeriodAttribute LIMIT 1];

The final query returns an empty list even though the insert completed without error.

Cause: AssetStatePeriodAttribute Is a Virtual Entity

AssetStatePeriodAttribute in Revenue Cloud RLM is a virtual entity. Virtual entities use an asynchronous write pipeline. After Database.insertImmediate() completes, a replication delay occurs before the record becomes accessible through SOQL. The length of the delay is not fixed or documented, and it cannot be configured. This is Working as Designed (WAD) platform behavior.

Résolution

Resolution: Verify the Insert with Database.SaveResult

The following steps confirm that an AssetStatePeriodAttribute record was created successfully without depending on SOQL availability. No supported method exists to query the record immediately after creation, because virtual entity writes are asynchronous.

  1. Capture the return value of Database.insertImmediate() in a Database.SaveResult variable. This provides the outcome of the insert operation.
  2. Assert that result.isSuccess() returns true. A passing assertion confirms the platform accepted the record.
  3. Include the first error message in the assertion text. A failed insert then reports the exact cause in the test output.
Database.SaveResult result = Database.insertImmediate(aspa);

System.assert(
    result.isSuccess(),
    'AssetStatePeriodAttribute insert failed: ' + result.getErrors()[0].getMessage()
);

The code stores the insert outcome in a SaveResult object and asserts that the insert succeeded. If the insert fails, the assertion fails and displays the first error message returned by the platform.

Notes on Test Design

  • SOQL queries against AssetStatePeriodAttribute should not be used in test assertions immediately after insertImmediate(), because the replication delay causes the query to return no rows even when the insert succeeded.
  • Test logic that depends on the stored attribute value should be restructured to assert on the SaveResult outcome or on data from non-virtual entities.
Numéro d’article de la base de connaissances

005462556

 
Chargement
Salesforce Help | Article