0

I know there are other questions similar to this but I could not figure out a way to solve my issue. In my Visualforce page, I have a repeater - I need to call the controller method to get data from another object using ID from the repeater object.

Visualforce:

  <apex:repeat var="a" value="{!articles}">            
        <!-- this is how I am setting the ArticleId variable in apex ---NOT WORKING -->
        <apex:param name="ArticleId" value="{!(a.Article_Id__c)}" assignTo="{!ArticleId}"/>          

        <!setFaqAnswer>  <!-- Calling the method -->
        <div class="divQuestion" "> {!a.Title__c} </div>
        <div class="divSummary" > {!a.Summary__c} </div>
        <div  class="divAnswer" > {!faq.Answer__c} </div>  <!--   <-- Using the faq object here -->
  </apex:repeat>

Controller:

public FAQ faq {get;private set;}

public Id ArticleId {
    get; set;
}

public void setFaqAnswer {
    get {
        try {
            faq = [select Answer__c, Links__c from FAQ__kav where KnowledgeArticleId = :ArticleId and IsVisibleInPkb = true];
        }
        catch (QueryException qe) {
            System.debug('@@@@' + qe); // <-- Not being able to view this in setup>log>debug logs
        }
    }
}
  • You can't use the repeater to retrieve FAQs related to each Article in the way you've got it written. Can you edit your question and add the relevant bit of code which is performing the query for Articles? – Mark Pond Dec 10 '14 at 20:14
1

Build your data structure in your controller class using a wrapper (AKA decorator) class such as this:

public class ArticleWrapper {
    public Article Art {get; set;}
    public FAQ__kav Faq {get; set;}
}

And then make your repeater loop round a list of the ArticelWrapper classes.

You can't use Visualforce repeaters in the same way you use for loops in apex - do the apex bit first, then use the repeater purely for generating the user interface.

| improve this answer | |
1

I solved my problem using Visualforce Component. I am passing value from the page to this componet.

Here is my component:

<apex:component controller="PKB_DataForScraping_MobileController">
    <apex:attribute name="articleId" description="Article Id" type="Id" assignTo="{!artId}" required="true"/>
    {!Faq.Answer__c}
</apex:component>

I created controller for the component like Force Hero said:

public with sharing class PKB_DataForScraping_MobileController{ 
   public Id artId {
        get;
        set {
            artId = value;
        }   
   }

   public FAQ__kav getFaq() {
       try {
              faq = [select Answer__c, Links__c from FAQ__kav where PublishStatus = 'Online' and KnowledgeArticleId = :artId and IsVisibleInPkb = true];
       }
       catch (QueryException qe) {}
       return faq;
   }
} 

This is how I call this component from the page:

<c:PKB_SearchResultForScraping_Mobile articleid="{!a.Article_Id__c}" />      

This is equivalent of calling a method with parameters from Salesforce page.

| improve this answer | |

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.