Find your content:

Search form

You are here

Save Records in Salesforce using setcontroller

 
Share

I am using salesforce standard set controller and displaying 4 records a page,

I have input fields where i entering values and i wanted to save records on save button clicked.

I want to create a child record for each record.i.e i want update the four field instead the complete list,can i know to get the id's of the four records.

can know how can records values page wise.


Attribution to: user6833

Possible Suggestion/Solution #1

Yes, you can get the ids of the records. In the constructor for your standardset extension, you can get the records using the following code:

public List<sObject> myRecords {get; private set;}

public MyClass(ApexPages.StandardSetController ctrl){
    myRecords = ctrl.getRecords();
    // - OR -
    myRecords = ctrl.getSelectedRecords();

    //To get the ids of those records, you could do something similar to:
    Set<Id> myRecordIds = (new Map<Id,sObject>(ctrl.getRecords())).keySet();
}

From there you can either make updates to myRecords, or use their Ids to generate children records based on those parents. Note, the getSelectedRecords is relevant if for instance you have a related list with checkboxes and a custom button (meaning the getSelectedRecords method will give you the records in that related list that are checked).

Hope that helps.


Attribution to: James Loghry
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30648

My Block Status

My Block Content