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
vanessa veronvanessa veron 

Class Test


Someone give me the sample test class to my class:

global class AAAA implements System.Schedulable {
global String str{get;set;}
global String mail{get;set;}
global String nomJob{get;set;}
global String inputText{get;set;}
global String heure{get;set;}
global String minute{get;set;}
global String jourMois{get;set;}
global String mois{get;set;}
global String jourSemaine{get;set;}

global void execute(SchedulableContext sc) {

global AAAA () {


global AAAA (String mail, String inputText, String heure, String minute, String jourMois, String mois, String jourSemaine) {
this.mail= mail;
this.inputText = inputText;
this.heure= heure;
this.minute= minute;
this.jourMois= jourMois;
this.mois= mois;
this.jourSemaine= jourSemaine;

public void setMail(String mail) {
    this.mail= mail;

public String getMail() {
    return mail;

public void setRequete(String inputText) {
    this.inputText= inputText;

public String getRequete() {
    return inputText;

public void setHeure(String heure) {
    this.heure= heure;

public String getHeure() {
    return heure;

public void setMinute(String minute) {
    this.minute= minute;

public String getMinute() {
    return minute;

public void setJourMois(String jourMois) {
    this.jourMois= jourMois;

public String getJourMois() {
    return jourMois;

public void setMois(String mois) {
    this.mois= mois;

public String getMois() {
    return mois;

public void setJourSemaine(String jourSemaine) {
    this.jourSemaine= jourSemaine;

public String getJourSemaine() {
    return jourSemaine;

public void schedulejob(){
        String aaa = getMail();
        String req = getRequete();
        String heu = getHeure();
        String min = getMinute();
        String jMois = getJourMois();
        String leMois = getMois();
        String jSemaine = getJourSemaine();
        String NomJobSchedulable = nomJob;
        AAAA p = new AAAA (aaa, req, heu, min, jMois, leMois,jSemaine);
        String sch = '0'+' '+min+' '+heu+' '+jMois+' '+leMois+' '+jSemaine;
        system.schedule(NomJobSchedulable , sch, p);   

public void newPublier(){

    String query=inputText;
    String premier=query.substringAfter('select ');   
    premier=  premier.substringBefore('from');
    string titre= premier+'\n';
    string contenuCSV = titre;

    string queryResultatString = '';

    list<sObject> queryResultat = (List<sObject>)database.query(inputText);
    for(sObject a: queryResultat)

        queryResultatString = queryResultatString + string.valueof(a);
    System.debug('Query result string:'+queryResultatString);

    list<string> queryLignes = queryResultatString.split('}');

    for(string s:queryLignes){
        list<string> queryColonnes = s.split(',');
        for(string st:queryColonnes){
            contenuCSV = contenuCSV + st.substringAfter('=') + ',';

        contenuCSV = contenuCSV.substringBeforeLast(',').substringBeforeLast(',') + '\n';

    String lignes = contenuCSV;
    List<String> parts = lignes.split('\n');
    integer lineNumber = queryResultat.size();

    integer nbLignesPJ = 1000;
    integer compterParties=0;

    for(integer i=0;i<lineNumber;i++){

      string fichierParties = parts[0] + '\n';

      if(math.mod(i,nbLignesPJ)<>0) continue;

        for(integer j=1;j<=(lineNumber-i);j++){
            fichierParties = fichierParties + parts[i+j] + '\n';
         for(integer j=1;j<=nbLignesPJ;j++){
            fichierParties = fichierParties + parts[i+j] + '\n';
      //Envoyer le Mail
      Messaging.EmailFileAttachment csvPJ = new Messaging.EmailFileAttachment();
      blob csvBlob = Blob.valueOf(fichierParties);
      string csvNom = 'cases_fermes_''.csv';
      Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
      String[] adressMail = new list<string> {mail};
      String subject;
          subject = 'CSV - ';
      email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvPJ});
      Messaging.SendEmailResult [] envoyer = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

I want to publish my application but I do not know to do a test class.
Deepak Kumar ShyoranDeepak Kumar Shyoran
I've written a block on how to write test class and test methods.
Please refer the following link to write test class for your class.

Call methods of your class of your class inside the Test.StartTest() and Test.stopTest().

Please mark my answer as a best solution to your question if it solves your problem.

vanessa veronvanessa veron
Thank you...

I am new to Apex and did not understand much.

Can you give me an example based on the code of my class?
Make things easier for me.
Deepak Kumar ShyoranDeepak Kumar Shyoran

private class AAAA_Test{

private static testMethod void unitTest1() {
Test.startTest() ;
AAAA controller = new AAAA() ;

controller.setMail('') ;
System.assertEquals(controller.mail,'') ;

You have to call each and every method of your controller in same fashion to cover for unit testing and also to validate the behavior of your class.

Hope it's enough for you to start with test class.

Please mark my answer as a best solution to your question if it solves your problem.