function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rebvijkumrebvijkum 

Error: Unknown property 'String.DataCategoryName'

I don't know where i'm doing wrong

My Page:
<apex:page standardController="Core_Benefit__kav" extensions="GetURL" id="corebenefitpageid" applyBodyTag="false"  sidebar="false" showHeader="true" >  
                    <apex:outputText id="categoryname" value="{!Category.DataCategoryName}"/>             
</apex:page>


My Controller:
public class GetURL {
   
    public GetURL(ApexPages.KnowledgeArticleVersionStandardController controller) {
         filterid=[SELECT Id FROM Core_Benefit__kav WHERE ArticleNumber = '{!Core_Benefit__kav.ArticleNumber}' AND PublishStatus = 'online' AND Language = 'en_US'].Id;
          
         CatDetails= [Select DataCategoryName,DataCategoryGroupName from Core_Benefit__DataCategorySelection where ParentId =:'filterid'].DataCategoryName;

    }
    public string CatDetails;
    public string filterid;

    public string getCategory() {
        return CatDetails;
    }  
}
Best Answer chosen by rebvijkum
Deepak Kumar ShyoranDeepak Kumar Shyoran
Well in that you need to modify your code a bit like

public class GetURL {
   
    public GetURL(ApexPages.KnowledgeArticleVersionStandardController controller) {
         filterid=[SELECT Id FROM Core_Benefit__kav WHERE ArticleNumber = '{!Core_Benefit__kav.ArticleNumber}' AND PublishStatus = 'online' AND Language = 'en_US'].Id;
          
         CatDetails= [Select DataCategoryName,DataCategoryGroupName from Core_Benefit__DataCategorySelection where ParentId =:'filterid'];

    }
    public Core_Benefit__DataCategorySelection CatDetails;
    public string filterid;

    public Core_Benefit__DataCategorySelection getCategory() {
        return CatDetails;
    }  
}


//V.F page will be like

<apex:page standardController="Core_Benefit__kav" extensions="GetURL" id="corebenefitpageid" applyBodyTag="false"  sidebar="false" showHeader="true" >  
        <apex:outputText id="categoryname" value="{!Category.DataCategoryName}"/>  
		<apex:outputText id="categoryname" value="{!Category.DataCategoryGroupName}"/>  					
</apex:page>

Use above code to display those fields on V.F page

All Answers

Deepak Kumar ShyoranDeepak Kumar Shyoran
In your SOQL you have written

CatDetails= [Select DataCategoryName,DataCategoryGroupName from Core_Benefit__DataCategorySelection where ParentId =:'filterid'].DataCategoryName;

which will returns a String i.e DataCategoryName for a record.

and on you page you again trying to fetch DataCategoryName from a String.

<apex:outputText id="categoryname" value="{!Category.DataCategoryName}"/>

so to remove this error replace <apex:outputText id="categoryname" value="{!Category.DataCategoryName}"/> with <apex:outputText id="categoryname" value="{!Category}"/> it will solve your problem.
rebvijkumrebvijkum
Thanks for the reply deepak.
so i'm retrieving two field values i.e.,DataCategoryName and DataCategoryGroupName from Core_Benefit__DataCategorySelection object.
so how to display these values in visualforce page, without using .Datacategoryname at the end of second soqlquery???
Deepak Kumar ShyoranDeepak Kumar Shyoran
Well in that you need to modify your code a bit like

public class GetURL {
   
    public GetURL(ApexPages.KnowledgeArticleVersionStandardController controller) {
         filterid=[SELECT Id FROM Core_Benefit__kav WHERE ArticleNumber = '{!Core_Benefit__kav.ArticleNumber}' AND PublishStatus = 'online' AND Language = 'en_US'].Id;
          
         CatDetails= [Select DataCategoryName,DataCategoryGroupName from Core_Benefit__DataCategorySelection where ParentId =:'filterid'];

    }
    public Core_Benefit__DataCategorySelection CatDetails;
    public string filterid;

    public Core_Benefit__DataCategorySelection getCategory() {
        return CatDetails;
    }  
}


//V.F page will be like

<apex:page standardController="Core_Benefit__kav" extensions="GetURL" id="corebenefitpageid" applyBodyTag="false"  sidebar="false" showHeader="true" >  
        <apex:outputText id="categoryname" value="{!Category.DataCategoryName}"/>  
		<apex:outputText id="categoryname" value="{!Category.DataCategoryGroupName}"/>  					
</apex:page>

Use above code to display those fields on V.F page
This was selected as the best answer
rebvijkumrebvijkum
i'm sorry to ask,  too much from you, but i couldn't get any rows from first soql query. Is it because ArticleNumber = '{!Core_Benefit__kav.ArticleNumber}'???

Deepak Kumar ShyoranDeepak Kumar Shyoran
That might be due to the conditions which you have written in you where part may be they are not match to find a records on that basic. First check them using debug log and you will get you answer. Debug logs are best thing in salesforce to shot out these type of errors :)