+ Start a Discussion
anjaanja 

retrieve current page ID

I am trying to figure out how to get my controller to retrieve the current record ID from the page (it is a sales order, the code below is to create an array out of its line items. Thanks if you can help!!

 

Here is the code (bold is where I have the problem):

 

 

public with sharing class SOL { 
    
    public SOL(ApexPages.StandardController controller) {
                        
    }
    
    Public List<PBSI__PBSI_Sales_Order_Line__c> getCustomObjs() {
        list<PBSI__PBSI_Sales_Order_Line__c> Arr_custom_obj=[select id, Name, PBSI__Quantity__c from PBSI__PBSI_Sales_Order_Line__c where PBSI__Sales_Order__c = 'a0aT0000004C1Em' ];
        return Arr_custom_obj;
    }

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

 

public with sharing class SOL { 
    Id currentRecordId;
    public SOL(ApexPages.StandardController controller) {
        currentRecordId = controller.getId();
    }
    
    Public List<PBSI__PBSI_Sales_Order_Line__c> getCustomObjs() {
        list<PBSI__PBSI_Sales_Order_Line__c> Arr_custom_obj=[select id, Name, PBSI__Quantity__c from PBSI__PBSI_Sales_Order_Line__c where PBSI__Sales_Order__c = :currentRecordId and PBSI__Sales_Order__c <> null];
        return Arr_custom_obj;
    }

Bold parts are the pieces you're looking for. 

 

All Answers

sfdcfoxsfdcfox

 

public with sharing class SOL { 
    Id currentRecordId;
    public SOL(ApexPages.StandardController controller) {
        currentRecordId = controller.getId();
    }
    
    Public List<PBSI__PBSI_Sales_Order_Line__c> getCustomObjs() {
        list<PBSI__PBSI_Sales_Order_Line__c> Arr_custom_obj=[select id, Name, PBSI__Quantity__c from PBSI__PBSI_Sales_Order_Line__c where PBSI__Sales_Order__c = :currentRecordId and PBSI__Sales_Order__c <> null];
        return Arr_custom_obj;
    }

Bold parts are the pieces you're looking for. 

 

This was selected as the best answer
anjaanja

Yeah!!! That did it. Thank you!