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
Dharmin Kansara 8Dharmin Kansara 8 

Variable does not exist: while returning the list

I want the apex class  to return a list of Topics in experience cloud, I am getting error that variable does not exists: getNavigationTopics

 

Here is the code, and also can you please provide a test class for this? 

public with sharing class CustomAccordionLWC{
    @AuraEnabled(cacheable=true)
    public static List<ConnectApi.Topic> getNavigationTopics(){

        string commId = [Select Id from Network where Name = 'Payer Help Center'].Id;    
        ConnectApi.ManagedTopicCollection topics = ConnectApi.ManagedTopics.getManagedTopics(commId);
        for (ConnectApi.ManagedTopic managedTopic : topics.managedTopics) {
            System.debug('###managedTopic.topic.name = ' + ((ConnectApi.Topic)managedTopic.topic).name);
        
            Set<String> topicNames = new Set<String>();
            for (ConnectApi.ManagedTopic childManagedTopic : managedTopic.children) {
                topicNames.add(((ConnectApi.Topic)childManagedTopic.topic).name + '\n');
            }
        
            System.debug('### childTopicNames:\n' + String.join(topicNames, '\n'));
        }
			return getNavigationTopics; 
    }
            
}
 

 

Mahesh GorrepatiMahesh Gorrepati
public with sharing class CustomAccordionLWC{
    @AuraEnabled(cacheable=true)
    public static List<ConnectApi.Topic> getNavigationTopics(){

        string commId = [Select Id from Network where Name = 'Payer Help Center'].Id;    
        ConnectApi.ManagedTopicCollection topics = ConnectApi.ManagedTopics.getManagedTopics(commId);

                   Set<String> topicNames = new Set<String>();

        for (ConnectApi.ManagedTopic managedTopic : topics.managedTopics) {
            System.debug('###managedTopic.topic.name = ' + ((ConnectApi.Topic)managedTopic.topic).name);
        
           
            for (ConnectApi.ManagedTopic childManagedTopic : managedTopic.children) {
                topicNames.add(((ConnectApi.Topic)childManagedTopic.topic).name + '\n');
            }
        
            System.debug('### childTopicNames:\n' + String.join(topicNames, '\n'));
        }
            return getNavigationTopics
    }
            
}


Here , You returned the method name that's why it is showing the Error.
Update it with  List<ConnectApi.Topic> variable 
Dharmin Kansara 8Dharmin Kansara 8

@Mahesh Thanks for the reply

 

It seems to give same error!

Mahesh GorrepatiMahesh Gorrepati
@Dharmin Kansara 8
Can you Share the error ?
Dharmin Kansara 8Dharmin Kansara 8

@Mahesh

Variable does not exist: getNavigationTopics

 

-------

 

Just before you work on it, I exactly need this - https://salesforce.stackexchange.com/questions/406193/dynamic-topic-name-in-community-cloud-using-lwc

 

Would appreciate.