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
shobana shobanashobana shobana 

Test class failed for Apex class

Hi everyone
I wrote a test class for custom case object.It showing the error
" Invalid bind expression type of Schema.SObjectField for column of type Id".
My Apex class:
public class OpenEventsforPotentials {

public List<OpenActivity> open{get;set;}

    public Boolean refreshPage {get; set;}

    public List<Event> accs { get; set;}

    public Id Potentialld{get;set;}
    public Id Accountid{get;set;}

    public string SelectedEventId { get; set;}

    public OpenEventsforPotentials (ApexPages.StandardController controller) {

        Potentialld= ApexPages.CurrentPage().getparameters().get('id');
        list<Account> Accountid=[select id from Account]; 
        list<Opportunity>   c =[SELECT Name,

                                (Select Id,Subject,IsTask, WhoId, ActivityDate,Status, Priority, OwnerId FROM OpenActivities WHERE IsTask=False)

                           FROM Opportunity WHERE Id = :Potentialld];

        if(c.size() > 0){

            open = c[0].OpenActivities;






    public pageReference DeleteEvent(){


        // if for any reason we are missing the reference

        if (SelectedEventId != null) {

            Event tobeDeleted = [SELECT Id FROM Event WHERE Id =:SelectedEventId];

            if(tobeDeleted != null){

                delete tobeDeleted;



            for(Integer i=0;i < open.size();i++){

                if(open[i].Id == SelectedEventId){







        return null;


    public Pagereference refresh(){

        PageReference secondPage = new PageReference('{!Leadld}');




        return secondPage;



Test class:
public class  Testclassforcases{

    static TestMethod void testforcases(){

       User usr = [SELECT Id From User WHERE Id =:UserInfo.getUserID()];

           Account A1=[select id from account
                       where id = : case__c.Account_Name__c];
           case__c case1=new case__c(OwnerId=usr.Id,CurrencyIsoCode = 'INR',Name=A1.Id

            Insert case1;


            Event event1=new Event(OwnerId=usr.Id,Subject='cc',DurationInMinutes=60,ActivityDateTime=Datetime.newInstance(2015,25,2,00,00,00),
            Insert event1;

            ApexPages.StandardController stdcontroller = new ApexPages.Standardcontroller(case1);

            OpenEventsforCases eve=new OpenEventsforCases(stdcontroller);
           // eve.refresh();
            OpenTasksforCases eve1= new OpenTasksforCases( stdcontroller);
            eve1.listwrapper[0].checked = true;



Can anyone help me out to solve this problem.
Thank you in advance.....
Waqar Hussain SFWaqar Hussain SF
Account A1=[select id from account
                       where id = : case__c.AccountId];
           case__c case1=new case__c(OwnerId=usr.Id,CurrencyIsoCode = 'INR',Name=A1.Name

Hello  Shobana, Try this code, it will solve your problem
shobana shobanashobana shobana
Hi Vickey
Thank you for your replay 
Now it showing error <span unselectable="on" "="" style="display: block; padding: 3px 4px; overflow: hidden; margin-left: 0px; color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; white-space: nowrap;">
"System.ListException: List index out o"

at line 128.Actually i wrote test class for two apex class but i post only one apex class.For another apex class it showing error.
Waqar Hussain SFWaqar Hussain SF
Hello shobana, have a look to this site, 
the problem is in your query.. (

Mark it as a best answere if it helps you. So other can take help