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
devloper sfdcdevloper sfdc 

how to write test class for this apex class

Hello All ,

I need test class for this code please help me i am not able to create test class for this code.
public class BBH_Survey {
    public  String   Survey_res {get;set;}
    public  String UpdateSurvey_res {get;set;}
    public Survey_Question__c ques_id{get;set;}
    Public String CasId;
    Public String Survey_comments {get;set;} 
    public boolean flag{get;set;}
    public list<BBH_Surveys__c> lstbbhsury;
    Public New_Surveys__c surveyName {get;set;}
     public String modifySurvey{get;set;}
    public string surveyId;
    public String imageURL{get;set;}
    public String modiFiResponce {get;set;}
    public BBH_Survey(apexPages.StandardController std) 
    {
      Survey_comments='';
        flag=false;
        CasId=ApexPages.currentPage().getParameters().get('caId'); 
        surveyId = Apexpages.currentPage().getParameters().get('id');
       // contactId = Apexpages.currentPage().getParameters().get('cId'); 
      lstbbhsury=[select id from BBH_Surveys__c where CaseId__c =:CasId]; 
       List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];  
      imageURL='/servlet/servlet.FileDownload?file='+schoolsurvey[0].School_Logo__c;
         //imageURL='/servlet/servlet.FileDownload?file=01523000000NUuc';
         
        
    }
     
   
    
    Public  PageReference survey_1(){
   if(lstbbhsury.size()>0)
        {
           PageReference Checksuvey = page.SurveyAlreadyFillAndUpdate;   
            Checksuvey.setRedirect(true);
            return Checksuvey; 
        }else
        {
               try{
    List<case> lstCase=[select id,status ,Survey_fill__c from case where id =:CasId];
    List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
        string url=schoolsurvey[0].School_URL__c;
        PageReference myVFPage = new PageReference(url);
              BBH_Surveys__c bbh=new BBH_Surveys__c();
               bbh.CaseId__c=lstCase[0].id;
               bbh.Survey_Response__c= '1';
               bbh.Surveys_Name__c=surveyId;    
        bbh.Survey_Comments__c =Survey_comments;
        
              insert bbh;
             myVFPage.setRedirect(true);
              return myVFPage;
        } catch(Exception e) {
             PageReference myVFPage1 =page.Survey_Permission_Required;  
             myVFPage1.setRedirect(true);
            return myVFPage1;
        }
            
        }
        
    }
}

 
Tad Aalgaard 3Tad Aalgaard 3
Could you please post what you have written so far for your test class?
Tad Aalgaard 3Tad Aalgaard 3
Nearly half of your posts are asking others to write your test classes for you.  It doesn't seem fair to ask others to write your code for you while you get paid for it and we do not.  Just my two cents.

https://developer.salesforce.com/forums/ForumsProfile?communityId=09aF00000004HMG&userId=0050G000009rPlU&showHeader=false (https://developer.salesforce.com/forums/ForumsProfile?communityId=09aF00000004HMG&userId=0050G000009rPlU&showHeader=false)

Please try and create test classes on your own and then post what you have written so far when you have an issue.