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
Vegaln1Vegaln1 

Standard Controller extentions and using getSelected()

Hello... In a StandardController extention I would like to guery fields from records selected in a related list view. So, if the user selects 3 records in the custom object I would like to retrieve their Ids and then perfrom a query based on that List. The List command in red fails with :  ' Illegal assignment from LIST:SObject to LIST:SOBJECT:' I've tried different variations of the List with ctl.getSelected but have quite got it right.

 

How do I structure the List so I can retrieve the selected Ids? Perhaps using List isn't the best way to hold the Ids so I am certainly open for suggestions on how to use 'getSelected'

 

Regards,

 

The Extension controller looks like this:

 

 

Public class ConAE {
      private final Asset_Entitlement__c ae;
      ApexPages.StandardSetController ctl = null;
      public ConAE(ApexPages.StandardSetController controller) {
           if ( ctl == null )
            {
               ctl = controller;
              
               List<Asset_Entitlement__c> aeId = ctl.getSelected();  //ERROR HERE
               System.debug('aeId is: ' +aeId);
              List<Asset_Entitlement__c> ae = [select id, Name, Parent_Opty_Aggregate__c, Opty_Aggregate__c from Asset_Entitlement__c where id = :ctl.getSelected()];// This is probably incorrect too
               System.debug('*******************m ae is:' + ae);
            }
           
           
          
      }
 

Best Answer chosen by Admin (Salesforce Developers) 
Vegaln1Vegaln1

For the benefit of others, here's the correct syntax:

 

List<Asset_Entitlement__c> aeId = (List<Asset_Entitlement__c>) controller.getSelected();

List<Asset_Entitlement__c> aei = [select id, Name, Parent_Opty_Aggregate__c, Opty_Aggregate__c from Asset_Entitlement__c where id IN :aeId];

All Answers

hisrinuhisrinu

You can do like this, no need to use extra variable

 

public ConAE(ApexPages.StandardSetController controller)

{
               List<Asset_Entitlement__c> aeId = controller.getSelected(); 
              List<Asset_Entitlement__c> ae = [select id, Name, Parent_Opty_Aggregate__c, Opty_Aggregate__c from Asset_Entitlement__c where id in aeid];

}

Vegaln1Vegaln1

Thank you . However, I still get unexpected token ( aeId )  on this line:

 

List<Asset_Entitlement__c> ae = [select id, Name, Parent_Opty_Aggregate__c, Opty_Aggregate__c from Asset_Entitlement__c where id in aeId];

 

 I've tried:

 

 IN :aeId];

= aeId];

=:aeId];

 

Thanks for being patient.

 

Regards,

Vegaln1Vegaln1

For the benefit of others, here's the correct syntax:

 

List<Asset_Entitlement__c> aeId = (List<Asset_Entitlement__c>) controller.getSelected();

List<Asset_Entitlement__c> aei = [select id, Name, Parent_Opty_Aggregate__c, Opty_Aggregate__c from Asset_Entitlement__c where id IN :aeId];

This was selected as the best answer
Ken_KoellnerKen_Koellner

Can I ask a follow-up question on this thread ...

 

Just what does "getSelected()" do?  All the doc says is "Returns the list of sObjects that have been selected.".

 

Does that meant there's a way to display the data such that certain records are selectable?  If so, is that documented anywhere?

 

I'm trying to use an extention to a standardSetController to allow action to be performed on a  selected sub-set of the records on the screen.

 

 

Vegaln1Vegaln1
Hello Ken..All I know is that it will return the ID of the record(s) that the user has selected when the 'Action' box is clicked. I haven't found much, if any, documentation on how to really use the function. This extension is supposed to return to the Apex page only those records that were selected by the user.
Ken_KoellnerKen_Koellner

What I need to know is how does the user "select" records?  there's no check-box next to them or anything.  DO they hightlight them?

 

What is this "action box"?  Is there some element I need to put on the page.  Right now I'm just displaying one field in a pageblocktable--

            <apex:pageBlockTable value="{!opportunities}" var="opp" id="opp_table">
                <apex:column headerValue="Name" value="{!opp.name}"/>
            </apex:pageBlockTable>

Message Edited by Ken_Koellner on 05-20-2009 11:32 AM
Vegaln1Vegaln1
In our case, we have defined a 'Mass Update' field that uses a 'Action' checkbox. This is how they select the records. Normally they would select the records in this fashion and press the 'Mass Update' button but in this case the use presses another button. You might try defining a checkbox in your view.
Ken_KoellnerKen_Koellner

How do you define a checkbox in your view?  Does there have to be a checkbox on the SObject?

 

Vegaln1Vegaln1

Hello Ken... The 'Action' was created under Custom Button and links. In our case this checkbox was created as part of a Mass Update button for this custom object. In the button definition, under 'Display Type' you can choose :

 

Display Checkboxes (for Multi-Record Selection)
 
Ken_KoellnerKen_Koellner

Then what do you put in your VG page to reference that button?  Any chance you could page a few lines?

 

Are you displaying the list in the pageblocktable?  

Vegaln1Vegaln1
Hello Ken.. I don't reference the button. The user checks the Box for the records wanted, presses the button and the VF page is fired. The custom button is defined to use a VF page. The getSelected() collects the Ids of the records that were checked. All the code is above..... but remember, it's not working according to plan ;(
YappyYappy

It can be just like 

 

List<Asset_Entitlement__c> aei = [select id, Name, Parent_Opty_Aggregate__c, Opty_Aggregate__c from Asset_Entitlement__c where id IN : (List<Asset_Entitlement__c>) controller.getSelected();];

AthiAthi
Can this be happened for all records in view instead of selected records?