[SalesForce] Can we get the existing records of a related list,by clicking on a ListButton

I have an custom object named Competitors and it has a look up relationship to Quote . Created a custom button as "Edit All" and displayed it on related list..The functionality of the button should be as ,once the user clicks on the Edit all button the related records should get displayed.(Similar like QuoteLineItem – EditAll button functionality).

I have created a custom button ,on the custom object

  1. label & Name as "EDIT ALL"
  2. Type :ListButton
  3. behaviour as :Execute JavaScript
  4. Content Source:onclick javascript
  5. given an url as:parent.window.location.replace("/apex/Compitetor?id={!Compitetor__c.Id}");

Now what im facing is when i click on the custom button it should show only the related records to particular parent record,but i get all the records displayed of the child object(i.e custom object).Any suggestion plz.

when i click on the "EDIT All" button ,it should give me an option to edit the child records related to the parent record.For eg:if i have one parent record (quote)and 4 child records (custom) out of which 3 are related to the parent record.now when i click on the edit all button ,it should be give an option to edit those 3 related child record and save.

I have created a vf page and controller but it throws an Error and doesnot display the record details of a related list to edit.PFAScreenSHot

VF Code :

<apex:page controller="CompitetorController" sidebar="false" >
 <apex:form >
  <apex:sectionHeader title="Edit Compitetors for" />
  <apex:pageBlock title="General Information"  mode="inlineEdit">
   <!--<apex:pageMessages /> --->
<!-- Display Save and Cancel Button -->

   <apex:pageBlockButtons >
    <!--<apex:commandButton action="{!edit}" id="editButton" value="Edit"/> -->
    <apex:commandButton value="SAVE" action="{!SAVE}" id="SaveButton" />
    <apex:commandButton value="CANCEL" action="{!CANCEL}" onclick="resetInlineEdit()" id="CancelButton"/>
   </apex:pageBlockButtons>
 <!-- A PageBlockSection for Entry and Display Customer Values -->

   <apex:pageBlockSection columns="5">
        <apex:outputField value="{!com.Part_Number__c}" label="PartNumber"/>
        <apex:outputField value="{!com.Price_Offered__c}" label="Price">
               <apex:inlineEditSupport showOnEdit="saveButton ,cancelButton" hideOnEdit="editButton" event="ondblclick"  changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/> 
               </apex:outputField> 
               <apex:outputField value="{!com.Volume__c}" label="Volume"/>
               <apex:outputField value="{!com.Date_Price_is_valid__c}" label="Date Price is valid"/>  
   </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:form>
</apex:page>

Apex Class :

public with sharing class CompitetorController {

public Compitetor__c com {get;set;}
public String CompitetorId{get;set;}
public String message{get;set;}

/**
    *@purpose : Constructor to fetch current Customer Record and its 

Action
    **/
 public CompitetorController () {
 CompitetorId = System.currentPageReference().getParameters().get

('Id');
       if(CompitetorId != NULL){
         Com = [SELECT Id,Name,Product_Series__c,   Part_Number__c, 

Price_Offered__c ,  Volume__c,  Date_Price_is_valid__c FROM 

Compitetor__c WHERE id=:CompitetorId];
      }
   } 

/**
    *@purpose : Method for Saving the Customer Object Record 
    *@param : None 
    *@return : PageReference to Standard Salesforce Record Detail 

Page 
    **/
    public PageReference SAVE() {
     try{
         upsert com;
         PageReference nextpage= new PageReference('/'+com.id);
           return nextpage;
      }
      catch(Exception e){
            //message='Data Base error during saving...';
            //ApexPages.addMessage( new ApexPages.Message

//(ApexPages.Severity.ERROR, message));
            return null;
        }
   }

    public PageReference CANCEL() {
        return null;
    }
}

Thanks in Advanceenter image description here

Best Answer

This question is very similar to the one you already asked here: how to create a custom button for a custom object on a related list

If I don't misunderstand you requirements, you got a lot of things conceptually wrong.

First Competitors are related to quotes and you want to find all competitors for that quote. So you have to bypass the QuoteId as filter criteria - not the CompetitorId.

So your button code could be something like

/apex/CompitetorsForQuote?id={!Quote.Id}

There is also absolutely no need for using Javascript as Button type. You should use URL.

Then you query for a single competitor (using the wrong where) but you should query for a list.

string QuoteId = System.currentPageReference().getParameters().get('Id');
Competitor__c[] comps = [SELECT Id,Name,Product_Series__c,   Part_Number__c,  
    Price_Offered__c , Volume__c,  Date_Price_is_valid__c FROM Compitetor__c 
    WHERE Quote__c = :QuoteId;
];

This is probably not all and my code is untested and may contain errors. But it could help you to think about the structure.