I have a Location object with a related list called Product Items on the Location. I would like to display the same Product Items on the Service Territory Member object.
Service Territory Member has a master-detail to Service Territory.
Service Territory Member has a lookup to Product Item and Location.
Service Territory Location has master-detail to Service Territory.
Service territory Location has a lookup to Location.
My first choice was to create a Product Item related list on the Service Territory Member, but it doesn't show up in the page layout related list section. So I'm trying and do it from code. The SOQL query is not returning any data. Is there a better way to write it?
public with sharing class ProductItemController {
@AuraEnabled(cacheable=true)
public static List<sObject> getProductItems(Id recordId){
ServiceTerritoryMember stm = [SELECT Id, ServiceTerritoryId FROM ServiceTerritoryMember WHERE Id = :recordId];
ServiceTerritoryLocation stl = [SELECT Id, LocationId FROM ServiceTerritoryLocation WHERE Id = :stm.ServiceTerritoryId];
List<ProductItem> products = [SELECT Id, Quantity_Reserved__c, Quantity_Remaining__c, ProductName
FROM ProductItem
WHERE LocationId = :stl.LocationId];
return products;
}
}
ProductItem
onServiceTerritoryMember
then you should be able to add the related list. Are you unable to add it as an option when editing your page layout forServiceTerritoryMember
?stm.Product_Items__r
? The query would be something likeServiceTerritoryMember stm = [SELECT Product_Items__r FROM ServiceTerritoryMember WHERE Id = :recordId]
developer.salesforce.com/forums/?id=906F0000000BNe7IAG