0

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;
    }
}
29
  • @Koen Wesselman:i have added my complete code of vf page – nikkey Dec 30 '14 at 16:31
  • @KoenWesselman:I have made the necessary changes but it throws an ERROR as :System.QueryException: List has no rows for assignment to SObject ,Class.CompetitorRelatedList.<init>: line 13, column 1,at this line :Compitetor__c currentComp = [SELECT CustomQuote__c FROM Compitetor__c WHERE Id = :currentCompId]; – nikkey Jan 1 '15 at 16:58
  • Is the name of your object "Compitetor__c"? I believe it should be "Competitor__c" instead, right? – Koen Wesselman Jan 1 '15 at 17:12
  • @KoenWesselman:As of now i'm working in Developer Edition ,where my custom object was named as Compitetor__c".Whereas im my org its is Competitor__c. – nikkey Jan 1 '15 at 17:16
  • Can you verify that this error shows on Competitor pages that definitely do have related Competitors as well as pages that definitely do not have related Competitors? – Koen Wesselman Jan 1 '15 at 18:36
3

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:

public with sharing class CompetitorEditExt {

    private List<Competitor__c> comp;
    private Id quoteId;

    public CompetitorEditExt(ApexPages.StandardSetController c) {
        c.setPageSize(10);
        this.quoteId = ApexPages.currentPage().getParameters().get('id');
    }

    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 where CustomQuote__c = :this.quoteId];
        return comp;
    }

    public pageReference save() {
        update comp;
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
        return ret.setRedirect(true);
    }

    public PageReference cancel() {
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
        return ret.setRedirect(true);
    }

}

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.

2
  • Agreed. Your SOQL statement isn't limited to the ID of the Quote, so you're returning all Competitor records. – HomerJ Dec 31 '14 at 17:29
  • @Koean Wesselman:Thanks for your priceless time and needful help.I really appreciate you help. – nikkey Jan 6 '15 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.