• shuchi_dhall
  • 0 Points
  • Member since 2012

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3

Hello all,


I have a requirement for a visualforce page which would repeat tables of account related information. Now i can do this easily if its just an object with one single related object. However if i have for example an Account, then a related object, then an object related to that related object i find that it becomes a little more challenging because soql can only return 1 inner object. 


So, i know a wrapper class is the suggested resolution to this problem. However they are very poorly documented and i cannot 'wrapper' my head around them. lol terrible i know. For instance i don't know how i can build a list with all of these related objects to use in the visual force page.


So if someone could please walk me (and i'm sure countless others) through this process that would be greatly greatly appreciated. 


Here is what i'm trying to do:


Relating multiple=


I'm using a standard set controller to update multiple records displayed in a grid. I'm passing the IDs for the records to the VF page in the URL in one parameter, comma separated. in the setController property, I'm pulling out those IDs, querying the database, then returning the related records.


The problem is that when I try to save the records, they're not changing. 


I can see what's happening -- when my save() method gets the records to update from the setController, it's going through the same routine to pull the records from the database. Of course, that's not what I want.


I tested, and if (after the page is rendered), I comment out the database logic in the setController, the setController only has the updated records and the save performs correctly.


For now, I've written a clugy work-around that checks to see if the number of records in the setController are the same as the number of IDs I've passed to the page. If there's more, I know that I'm rendering the visualforce page -- if they're the same, I *assume* that I'm trying to save the records - and I bypass the database logic. But this is prone to bugs...


Here's the code. Any hints on a better approach would be appreciated.



public ApexPages.StandardSetController setController { get { String[] shipmentIds = EncodingUtil.urlDecode(ApexPages.currentPage().getParameters().get('Ids'), 'UTF-8').split(','); if (setController.getRecords().size() > shipmentIds.size()) { String query = 'Select Id, Name, Status__c, SalesOrder__c From Shipment__c Where '; for (String id : shipmentIds) { query += 'Id = \'' + id + '\' Or '; } query = query.substring(0, query.length()-4); List<Shipment__c> shipments = new List<Shipment__c>(); try { shipments = Database.query(query); } catch (System.Queryexception e) {} setController = new ApexPages.StandardSetController(shipments); } return setController; } set; }