You need to sign in to do that
Don't have an account?
Alex Waddell 18
Pass Record Id into Visual Force page
I am learning Apex and am trying to get my controller to query for Resource_List__c records where the Survey_Form__c field = :RecordId (the current Survery_Form__c record I am viewing)
VF Page
Class
VF Page Output when on the Lightning page
but when I put the query into the query editor and hard code the record Id there are values in this table
Is there any way to pass the record id into the VF page without invoking aura or LWC? I just want to learn the fundamentals before I step into those new languages
VF Page
<apex:page Controller="ResourceListController"> <apex:form> <apex:pageBlock> <apex:pageBlockTable value="{! ResourceList }" var="RL"> <apex:column value="{! RL.Id }"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Class
public class ResourceListController { public Id RecordId {get;set;} public List<Resource_List__c> getResourceList() { List<Resource_List__c> results = Database.query( 'SELECT Id, Account__c, Distance__c, type__c ' + 'FROM Resource_List__c ' + 'Where Survey_Form__c = :RecordId ' ); return results; } }
VF Page Output when on the Lightning page
but when I put the query into the query editor and hard code the record Id there are values in this table
Is there any way to pass the record id into the VF page without invoking aura or LWC? I just want to learn the fundamentals before I step into those new languages
You did a great job as newbie learning apex, the list is not filling because you need to get recordId and set into "Recordid" variable.
ApexPages.currentPage().getParameters().get('id');
The above line will get id URL parameter from browser URL and set into your declared variable 'RecordId'.
Hope this helps. Keep learning!
All Answers
I found the below article url's which I think might be useful, please have a look at them:
>> https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_System_ApexPages_currentPage.htm
>> http://www.sfdcpoint.com/salesforce/get-current-record-id-salesforce/
>> http://www.infallibletechie.com/2013/05/visualforce-email-template-with-custom.html
Hope this is useful for you to implement your need. Please close the thread by marking a best answer so that it can be useful for others in the future and can help in keeping the community clean.
Regards,
Anutej
You did a great job as newbie learning apex, the list is not filling because you need to get recordId and set into "Recordid" variable.
ApexPages.currentPage().getParameters().get('id');
The above line will get id URL parameter from browser URL and set into your declared variable 'RecordId'.
Hope this helps. Keep learning!
Thank you for your help and positivity! The code worked and I'm on to the next challenge