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
Jonathan Wolff 7Jonathan Wolff 7 

Error: method in controller cannot be found

Hello, I have a component that includes rows from different objects in one List. But I cant see if it works because I get the following error. Could you try the code out in your org and look if it works?

User-added image

My code ist as follows
Component:
<aura:component controller="ApexActivityWrapper" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global">  
   
    
    <aura:attribute name="TaskList" type="List"/>
    <aura:attribute name="EventList" type="List"/>
    <aura:attribute name="activityWrapper" type="object"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInIt}"/>
   	<aura:attribute name="wrapperList" type="ApexActivityWrapper.wrapper[]"/>
    
	<aura:iteration items="{!v.wrapperList}" var="wrp">
   {!wrp.taskSubject} - {!wrp.taskSubject}
   {!wrp.eventSubject} - {!wrp.eventActivityDate}
</aura:iteration>


    
     <p align="center" class="slds-text-heading_large ">Task List</p>
    <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped">
     <thead>
       <tr class="slds-line-height_reset">
        <th class="" scope="col">
       <div class="slds-truncate" >
        Task Subject
        </div>
         </th> 
         </tr>
        </thead>
        <tbody>
         <tr class="slds-hint-parent">
         <th data-label="" scope="row">
          <div class="slds-truncate" >
          
           <aura:iteration items="{!v.TaskList}" var="task">
            <p>{!task.Subject}</p><br/>
            </aura:iteration>
             </div>
              </th>
              </tr>
        </tbody>
    </table>
    
    <p align="center" class="slds-text-heading_large ">Event List</p>
    <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped">
     <thead>
       <tr class="slds-line-height_reset">
        <th class="" scope="col">
       <div class="slds-truncate" >
        Event Subject
        </div>
         </th> 
         </tr>
        </thead>
        <tbody>
         <tr class="slds-hint-parent">
         <th data-label="" scope="row">
          <div class="slds-truncate" >
           
           <aura:iteration items="{!v.EventList}" var="event">
            <p>{!event.Subject}</p><br/>
            </aura:iteration>
             </div>
              </th>
              </tr>
        </tbody>
    </table>
    <aura:iteration items="{!v.activitytWrapper.wrp }" var="act">
                <tr>
                    <th scope="row">
                        <div class="slds-truncate" title="{!act.subject}">{!act.subject}</div>
                    </th>
                   
                </tr>
            </aura:iteration>

    <br/>
    <br/>
</aura:component>

Controller
({
     doInIt : function(component, event, helper) {
 var action = component.get("c.method1");

       
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS")
            {
     var response = response.getReturnValue();
     component.set("v.wrapperList", response); 
     component.set("v.activityWrapper", response); 
     component.set("v.TaskList", response.taskList); 
     component.set("v.EventList", response.eventList); 
       
            }
            else if(state === "INCOMPLETE")
            {
                //do something 
            }
            else if(state === "ERROR")
            {
             var error = response.getError();
             if(error)
             {
                 console.log("error"+errors);
             }
            }
        });
          $A.enqueueAction(action);
 }
})

Apex Controller
 
public class ApexActivityWrapper {
   @AuraEnabled
   public static List<wrapper> method1() 
   {
        string userId = UserInfo.getUserId();
        List<wrapper> listwrap = new List<wrapper>();
        List<Task> getTaskList = new List<Task>([SELECT Subject, ActivityDate FROM Task WHERE OwnerId = :userId ORDER BY ActivityDate]);
        List<Event> getEventList = new List<Event>([SELECT Subject, ActivityDate FROM Event WHERE OwnerId = :userId ORDER BY ActivityDate]);

        Integer loopCount = getEventList.size() > 0 ? getEventList.size() : getTaskList.size();
        if(loopCount != null && loopCount > 0) 
        {
           for(Integer i = 0; i < loopCount; i++) {
             wrapper wrp = new wrapper();
             if(getTaskList != null && getTaskList.size() >= i && string.isNotEmpty(getTaskList[i].Subject)) {
               wrp.taskSubject = getTaskList[i].Subject;
             }
             if(getTaskList != null && getTaskList.size() >= i && getTaskList[i].ActivityDate != null) {
               wrp.taskActivityDate = getTaskList[i].ActivityDate;
             }
	     if(getEventList != null && getEventList.size() >= i && string.isNotEmpty(getEventList[i].Subject)) {
               wrp.eventSubject = getEventList[i].Subject;
             }
             if(getEventList != null && getEventList.size() >= i && getEventList[i].ActivityDate != null) {
               wrp.eventActivityDate = getEventList[i].ActivityDate;
             }
             listwrap.add(wrp);
           }
        }
        return listwrap;
   }

	public class wrapper{
   	 	@AuraEnabled
    		public string taskSubject;
    	        @AuraEnabled
    		public date taskActivityDate;
    	        @AuraEnabled
    		public string eventSubject;
    	        @AuraEnabled
    		public date eventActivityDate;
	}
}

​​​​​​​​​​​​​​
Sai PraveenSai Praveen (Salesforce Developers) 
Hi  Jonathan,

I have used the same code and did not face any error but the records were not getting displayed may be I am not sure of the code. But I don't see any error.

Can you check if the apex class is saved properly. If you dont mind can you copy the code to other apex class aand change the Controller name in Aura component and check.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
mukesh guptamukesh gupta
Hi Jonathan,

Your code is perfect, First you need to close developer console and open again and open apex class, this class should have method1, 
and then open component and check method1 exist now test your side

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
Jonathan Wolff 7Jonathan Wolff 7
Hi mukesh, thank you. I hoped that I get shown the tasks and events in one List now, but it displays nothing in the columns. Can you help me what to change about my code so it shows the records of both objects in one List.

Thank you very much