0

I am quite new to salesforce/coding and got myself stuck on a stumbling block when developing object for our internal use.

I have and object called Inventory_Skid_c this object has a field called Skid Location that is a lookupfield to another object called WH_Bin. So my issue is the following I want to display another object that is related to WH_Bin as a related list in this page this is object is named Stock_Levels__c

Under the WH_Bin I can see as a related list all the stock levels records and I want this information pertaining only this Bin to be show on the Inventory Skid object.

I tried to google and solve using only visual force but it seems impossible so I tried to do on the sandbox using a controller and visualforce but im pretty much stuck

Here is the code I have for the controller:

public class WarehouseBinChildController{
  list<WH_Warehouse_Bins__c> cons = [
    Select Id,
    Name,
    (SELECT Id FROM Stock_Levels__c)
    FROM WH_Warehouse_Bins__c

  ];
}

for the visual force I'm completely lost how to write the apex for it. Stock level reference image

Below is the schema, sorry it took me some time to figure out how to get this view: enter image description here

EDIT Error I am getting with the code: enter image description here

2
  • 2
    Is there a reason you are not considering LWC instead of VF? Also, please use edit and show a diagram of the schema w/ sample records to explain what you want to show
    – cropredy
    Commented May 5, 2022 at 19:21
  • I have no idea what is LWC, in summary I want to display only the stock level records related to the bin that the user selected on the field called skid location
    – Jon
    Commented May 5, 2022 at 21:07

1 Answer 1

0

You can do this without any Apex controller just by exploiting the standardController for Inventory_Skid__c

<apex:page standardController="Inventory_Skid__c">

  <apex:relatedList 
     list="Stock_Levels__r"
     subject="{!Inventory_Skid__c.Skid_Location__c}"  
   />
</apex:page>

where

  • list is the API name of the related list from parent to child
  • subject evaluates to an ID field that is the parent of the related list

References

8
  • Oh really? cool, gonna try and reply back asap. Thanks for the support
    – Jon
    Commented May 6, 2022 at 14:21
  • Humm, gives me an error when I put the code below: Error: Formula expression is required for attribute subject in <apex:relatedList> in InventorySkidVF2 at line 3 column 91 <apex:page standardController="Inventory_Skid__c"> <apex:relatedList subject="Inventory_Skid__c.Skid_Location__c" list="Stock_Levels__r" /> </apex:page>
    – Jon
    Commented May 6, 2022 at 15:00
  • Fixed. Forgot the merge field expression
    – cropredy
    Commented May 6, 2022 at 15:38
  • even with the ! still complains about Error: Formula expression is required for attribute subject in <apex:relatedList> in InventorySkidVF2 at line 3 column 91.
    – Jon
    Commented May 6, 2022 at 16:07
  • I removed the comments which were causing some parsing issues; I tested the exact example for the above in my org and it compiles and works fine
    – cropredy
    Commented May 6, 2022 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .