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
Amr MohsenAmr Mohsen 

VF page doesn'r recognize cutom controller

Hello, 
I've created apex class like below:
public class newTaskForTypeController {
    TaskForTypes__c taskType;
    
    public TaskForTypes__c getTaskType(){
        if(taskType == null) return new TaskForTypes__c();
        return taskType;
    }
    //First page which will contain name 
    public PageReference step1(){
        return Page.Tasks_For_Types1;
    }
    
    //Second page which will contain Sub type name and 
    public PageReference step2(){
        return Page.Tasks_For_Types2;
    }
    
    //Cancel the operation
    public PageReference cancel(){
        //Navigate to first page
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
    
    //Save method
    public PageReference save(){
        insert taskType;
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
}

And VF page code is :
<apex:page standardController="newTaskForTypeController" tabStyle="TaskForTypes__c" >
    <script>
    function confirmCancel() {
        var isCancel = confirm("Are you sure you wish to cancel?");
        if (isCancel) return true; 
        return false;
    } 
    </script>
    <apex:sectionHeader title="Add New Task Assignment For Types Rule"/>
    <apex:form>
        <apex:pageBlock title="Rule Name" mode="edit">
            <apex:pageBlockButtons>
            <apex:commandButton action="{!step2}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Why I get this error message ==>> "newTaskForTypeController does not exist" ??
Best Answer chosen by Amr Mohsen
DebasisDebasis
Hi Amr,

in page you are using standardcontroller attruibute, please chaneg it to controller only as per below code
<apex:page Controller="newTaskForTypeController" tabStyle="TaskForTypes__c" >
    <script>
    function confirmCancel() {
        var isCancel = confirm("Are you sure you wish to cancel?");
        if (isCancel) return true; 
        return false;
    } 
    </script>
    <apex:sectionHeader title="Add New Task Assignment For Types Rule"/>
    <apex:form>
        <apex:pageBlock title="Rule Name" mode="edit">
            <apex:pageBlockButtons>
            <apex:commandButton action="{!step2}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Also change the controller class as below, as custom controller need to have a zero argumnet constructor. I kept this constructor as empty, if you need you can write some logic inside it too.
public class newTaskForTypeController {
    TaskForTypes__c taskType;

//empty constructor
public newTaskForTypeController (){
   //you can write some logic here
}
    
    public TaskForTypes__c getTaskType(){
        if(taskType == null) return new TaskForTypes__c();
        return taskType;
    }
    //First page which will contain name 
    public PageReference step1(){
        return Page.Tasks_For_Types1;
    }
    
    //Second page which will contain Sub type name and 
    public PageReference step2(){
        return Page.Tasks_For_Types2;
    }
    
    //Cancel the operation
    public PageReference cancel(){
        //Navigate to first page
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
    
    //Save method
    public PageReference save(){
        insert taskType;
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
}

please let me know if you need any more assistance on this
 

All Answers

DebasisDebasis
Hi Amr,

in page you are using standardcontroller attruibute, please chaneg it to controller only as per below code
<apex:page Controller="newTaskForTypeController" tabStyle="TaskForTypes__c" >
    <script>
    function confirmCancel() {
        var isCancel = confirm("Are you sure you wish to cancel?");
        if (isCancel) return true; 
        return false;
    } 
    </script>
    <apex:sectionHeader title="Add New Task Assignment For Types Rule"/>
    <apex:form>
        <apex:pageBlock title="Rule Name" mode="edit">
            <apex:pageBlockButtons>
            <apex:commandButton action="{!step2}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Also change the controller class as below, as custom controller need to have a zero argumnet constructor. I kept this constructor as empty, if you need you can write some logic inside it too.
public class newTaskForTypeController {
    TaskForTypes__c taskType;

//empty constructor
public newTaskForTypeController (){
   //you can write some logic here
}
    
    public TaskForTypes__c getTaskType(){
        if(taskType == null) return new TaskForTypes__c();
        return taskType;
    }
    //First page which will contain name 
    public PageReference step1(){
        return Page.Tasks_For_Types1;
    }
    
    //Second page which will contain Sub type name and 
    public PageReference step2(){
        return Page.Tasks_For_Types2;
    }
    
    //Cancel the operation
    public PageReference cancel(){
        //Navigate to first page
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
    
    //Save method
    public PageReference save(){
        insert taskType;
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
}

please let me know if you need any more assistance on this
 
This was selected as the best answer
Amr MohsenAmr Mohsen
Thank you Debasis.