function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aaron LaymanAaron Layman 

In Visualforce page, how can I bring in a field from a different, and not related, class?

Hey everyone,

I'm trying to build a page that will need to be able to bring in a field from a class that isn't directly related to the class I'm attempting to ultimately edit. The scenario is I am trying to check out a book in the library and need to create an instance of "CheckOut" which is a child to both LibraryCustomer and Book. However, on the page the user should first choose the library from a dropdown, then the LibrarySection from a dropdown (that is updated dynamically by what Library is chosen), then the Book they want to check out and their LibraryCustomer ID. Upon doing this and clicking a button called "Check Out", it will create an instance of "CheckOut" with the "LibraryCustomer ID" and "Book ID". The picture is of the schema I created.

User-added image

 

Thank you!!

Sathish balajiSathish balaji
Hi Aaron,

In the custom controller capture the 'LibraryCustomer ID' from VF page and the book(which will be a selectOption) what the user had selected by using Apex properties. Then use something like below.

 
Checkout c = new Checkout(book = [select ID from book__c where book_name__c = <selectedbook from VF page>].id,  librarycutomer__c =  <librarycutomerID from VF page>);
insert c;

Let me know if it helps.

Best regards,
Sathish Balaji