You need to sign in to do that
Don't have an account?
ArchieTechie6
Salesforce Knowledge - Extension to Standard Controller
Hi All,
I am new to salesforce and I need help with the code which I have attempted.
I am trying to fetch some fields from Salesforce Knowledge Standard Object.
I have created a Controller and below is my code:
Below is the code in my markup:
I am new to salesforce and I need help with the code which I have attempted.
I am trying to fetch some fields from Salesforce Knowledge Standard Object.
I have created a Controller and below is my code:
public class KBController {
public list<Knowledge__kav> KBArticles {get;set;}
public KBController (ApexPages.StandardController StdCtrller){
this.KBArticles = new list<Knowledge__kav>();
KBArticles = [Select articleNumber, Title from Knowledge__kav where PublishStatus='Online'];
}
}
public list<Knowledge__kav> KBArticles {get;set;}
public KBController (ApexPages.StandardController StdCtrller){
this.KBArticles = new list<Knowledge__kav>();
KBArticles = [Select articleNumber, Title from Knowledge__kav where PublishStatus='Online'];
}
}
Below is the code in my markup:
<apex:page showHeader="false" sidebar="false" standardController="Knowledge__kav" extensions="KBController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!KBArticles}" var="articles">
<apex:column value="{!articles.articleNumber}"/>
<apex:column value="{!articles.Title}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
With this code, I am getting an error:
Id value null is not valid for the Knowledge__kav standard controller
Could anyone please suggest me here?
Thanks!
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!KBArticles}" var="articles">
<apex:column value="{!articles.articleNumber}"/>
<apex:column value="{!articles.Title}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
With this code, I am getting an error:
Id value null is not valid for the Knowledge__kav standard controller
Could anyone please suggest me here?
Thanks!
All Answers
I think Code is correct but this error is due to record Id which you are fetching in controller class.
I run this sample code and I don't get any error :
Page:
<apex:page showHeader="false" sidebar="false" standardController="Student__c" extensions="studentController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!KBArticles}" var="articles">
<apex:column value="{!articles.Age__c}"/>
<apex:column value="{!articles.Email__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller class:
public class studentController { public list<Student__c> KBArticles {get;set;} public studentController (ApexPages.StandardController StdCtrller){ this.KBArticles = new list<Student__c>(); KBArticles = [Select Age__c, Email__c from Student__c WHERE AGE__c = 100]; } }.
I see, you are passing a parameter in WHERE clause - WHERE AGE__c = 100
Do I need to pass any article number or any such parameter in the same way?
Will I not be able to retrive all articles using this code?
I have updated my code in controller as below:
But still getting same error.
public list<Knowledge__kav> KBArticles {get;set;}
public KBController (ApexPages.StandardController StdCtrller){
this.KBArticles = new list<Knowledge__kav>();
KBArticles = [Select articleNumber, Title from Knowledge__kav where ArticleNumber='000001000'];
}
}
There are some records in the object. I have created at elast 8 KB Articles in this object.
I am missing something and not really sure what.
In my URL, while browsing the page - Do I need to pass any ID? For example, below URL
https://myorgURL/apex/MyKBPage?articleNumber=000001000
and my query will be:
articleId = ApexPages.currentPage().getParameters().get('articleNumber');
KBArticles = [Select articleNumber, Title from Knowledge__kav where ArticleNumber = articleId ];
I tried this as well. Getting the same error.
Thats the mistake I did. I was passing wrong Id and sometimes, I was checking without passing any ID.
As I said, I am really new and you helped me a lot! Thanks again!