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
Ashh.cloudAshh.cloud 

To display set of records from a custom object on a Visualforce page and save them to a different custom object.

Hi there,

I have a requirement in which I have to display a set of records of a custom object on a visualforce page. Detailed explanation below.
  1. I have two custom objects OBJECT1 and OBJECT2, 
  2. I need a visualforce page for Object2 which should give me a set of records of Object1 based upon some filtering condition (which is dynamic).
  3. I should be able to select a few records from the results displayed and I should save some of them into Object2
Can any one help me in getting started with the code?
Any help is appreciated.

Thank you
Best Answer chosen by Ashh.cloud
Ramu_SFDCRamu_SFDC
Hi Mike, to do this you need to follow the below approach

1. Create a visualforce for Object 2 using custom controller.
2. Create a datatable in this visualforce to display the records that belong to object 1. You need to have the value of datatable call a wrapper class method where you will be querying for object 1 records and assign a checkbox to each and every record. http://wiki.developerforce.com/page/Wrapper_Class
3. Get the selected records of object 1 into a list object in the controller and create new object 2 records based on the data of object 1 records.

The following articles help you to understand about wrapper classes with example codes that you can leverage as per your need

http://blog.jeffdouglas.com/2009/01/13/apex-search-with-checkbox-results/
http://mycloudexperience.blogspot.in/2011/03/adding-checkbox-on-pageblocktable.html

Hope this helps you to start up.

All Answers

Ramakrishnan AyyanarRamakrishnan Ayyanar
Any relationShip here between two objects.
Ashh.cloudAshh.cloud
@Ramakrishna: No Direct relationship, but they contain few same colums.
Ramu_SFDCRamu_SFDC
Hi Mike, to do this you need to follow the below approach

1. Create a visualforce for Object 2 using custom controller.
2. Create a datatable in this visualforce to display the records that belong to object 1. You need to have the value of datatable call a wrapper class method where you will be querying for object 1 records and assign a checkbox to each and every record. http://wiki.developerforce.com/page/Wrapper_Class
3. Get the selected records of object 1 into a list object in the controller and create new object 2 records based on the data of object 1 records.

The following articles help you to understand about wrapper classes with example codes that you can leverage as per your need

http://blog.jeffdouglas.com/2009/01/13/apex-search-with-checkbox-results/
http://mycloudexperience.blogspot.in/2011/03/adding-checkbox-on-pageblocktable.html

Hope this helps you to start up.
This was selected as the best answer
Ashh.cloudAshh.cloud
Thank you Ramu, I almost got there.