I have a custom object as "Competitor__c" which has a lookup relation to Quote Object.I have a created a visualforce page on Competitor object to fetch related list record ,when user clicks on list button for editing.Now the issue is instead of getting the related list record of Competitor , i get all the records listed in my vf page related to competitor.Any Suggestion plz.
For Example :I have one quote record named as :QuotePDF and 2 related records of competitor.when the user clicks on the list button ,it should display only 2 records related to competitor for editing.
Here is VISUAL FORCE Page :
<apex:page standardcontroller="Competitor__c" sidebar="false" recordSetVar="Competitors" extensions="CompetitorEditExt" >
<apex:form >
<apex:sectionHeader title="Edit Competitors for" subtitle=""/>
<apex:pageBlock id="comp">
<apex:pageBlockButtons >
<apex:commandButton value="SAVE" action="{!SAVE}"/>
<apex:commandButton value="CANCEL" action="{!CANCEL}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!comp}" var="c" rendered="{!NOT(ISNULL(comp))}">
<apex:column value="{!c.Name}"/ >
<apex:column value="{!c.Product_Series__c}"/ >
<apex:column value="{!c.Part_Number__c}"/ >
<apex:column headerValue="Price">
<apex:inputField value="{!c.Price_Offered__c}"/>
</apex:column>
<apex:column headerValue="Volume">
<apex:inputField value="{!c.Volume__c}"/>
</apex:column>
<apex:column value="{!c.Date_Price_is_Valid__c}"/ >
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code :
public with sharing class CompetitorEditExt {
private List<Competitor__c> comp;
//private Quote q;
public CompetitorEditExt(ApexPages.StandardSetController controller) {
controller.setPageSize(10);
// this.q= (Quote)controller.getRecord();
}
public List<Competitor__c> getcomp()
{
comp = [Select Id, Name, Part_Number__c, Price_Offered__c, Product_Series__c, Volume__c, Date_Price_is_valid__c from Competitor__c ];
return comp;
}
public pageReference saveStatusChange(){
update this.comp;
return null;
}
}
Best Answer
Have you looked into the apex:relatedList tag yet? https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_relatedList.htm
If this is not a solution for you, please share your full VisualForce page. I think you've only copied the last two lines. You'll have a add a where-clause in your query based on the ID that you pass to the class in VisualForce.
Update:
Please replace your Apex code with:
Now we use the Quote's Id to look for the Competitor records that are related to it. I've also made sure your save() and cancel() methods return to the original Quote.