2

I am new to force.com site development and Template development so please provide me suggestions for below requirement.

I have created on force.com site with one home page. This page is used to display knowledge base articles. By using knowledge component i am displaying all articles and we user click on
article it opening new window with default site template. i.e

<apex:page showHeader="false" id="SiteTemplate"  standardController="KnowledgeArticle" extensions="testContactUs">
  <apex:stylesheet value="{!URLFOR($Resource.SiteSamples, 'SiteStyles.css')}"/>
  <apex:insert name="header">

    <hr/>
  </apex:insert>
  <apex:insert name="body"/>
  <apex:insert name="footer">
    <hr/>

    <site:googleAnalyticsTracking />
  </apex:insert>
</apex:page>

This page is displaying three section header , knowledge article and footer. Now i want to add two buttons i.e feedback "Article Helps" and "Dose not Help" which will store article feedback in custom object. how i can achieve this?

  • Is it working for you. Could you please share how you achieved this ? Thanks – user14768 Dec 12 '14 at 12:44
1

Add two new methods to your extension class testContactUs along these lines. You will need to use your actual custom object name and fields.

public with sharing class testContactUs {

    private final KnowledgeArticle kaFromController;

    public testContactUs(ApexPages.StandardController controller) {
        kaFromController = (KnowledgeArticle)controller.getRecord();
    }

    public PageReference articleHelps() {
         ArticleFeedback__c af = new ArticleFeedback__c();
         af.KnowledgeArticleId__c = kaFromController.Id;
         af.Helpful__c = true;
         insert af;
         return null;
    }

    public PageReference articleDoesNotHelp() {
         ArticleFeedback__c af = new ArticleFeedback__c();
         af.KnowledgeArticleId__c = kaFromController.Id;
         af.Helpful__c = false;
         insert af;
         return null;
    }
}

Then in your Visualforce page add buttons for these methods.

<apex:commandButton value="Article Helps" action="{!articleHelps}" />
<apex:commandButton value="Article Does Not Help" action="{!articleDoesNotHelp}" />
  • I tried your code but if click on button it is giving page not found error – Jayant Jadhav Jul 21 '14 at 4:11
  • @JayantJadhav The code was mostly intended to give you direction in the implementation rather than being an explicit solution. At what point does the error occur? Do the methods execute? Is there an issue with the PageReferences they return? What is in the Debug Log? – Daniel Ballinger Jul 21 '14 at 8:34
  • If i execute this code as VF page it will work but if i open this page in force.com site then it is giving error "page not found" and even it is not calling methods as well. – Jayant Jadhav Jul 21 '14 at 11:29
  • Above page is opening on click <a href="#" onclick="window.open('{!URLFOR($Action.KnowledgeArticle.View, article.id,['popup' = 'true'])}','FAQ','height=600,width=800')">{!article.title}</a> line of code. – Jayant Jadhav Jul 21 '14 at 11:34
  • @JayantJadhav When you are looking at the Site Details that Visualforce Page must appear in the Site Visualforce Pages for access via the public URL. – Daniel Ballinger Jul 21 '14 at 23:52

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.