You need to sign in to do that
Don't have an account?

Test Class Example
Hi...
Someone give me the sample example of a test class to my class.
I want to publish my application but I do not know to do a test 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) { newPublier(); } 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; if((lineNumber-i)<nbLignesPJ){ for(integer j=1;j<=(lineNumber-i);j++){ fichierParties = fichierParties + parts[i+j] + '\n'; } } if((lineNumber-i)>=nbLignesPJ){ 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_'+Date.today().format()+'.csv'; csvPJ.setFileName(csvNom); csvPJ.setBody(csvBlob); Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage(); String[] adressMail = new list<string> {mail}; compterParties++; String subject; subject = 'CSV - '+Date.today().format(); email.setSubject(subject); email.setToAddresses(adressMail); email.setPlainTextBody('message'); email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvPJ}); Messaging.SendEmailResult [] envoyer = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); } } }
Someone give me the sample example of a test class to my class.
I want to publish my application but I do not know to do a test class.
Please see the sample code below to begein with..You'll need to populate data into standard/custom objects that will satisfactorily get pulled by the logic you've written in some of the methods of scheduler. Also please correct the values for any of the variables that I've used.
Hope it helps !
Thanks,
Mohammed
All Answers
Please see the sample code below to begein with..You'll need to populate data into standard/custom objects that will satisfactorily get pulled by the logic you've written in some of the methods of scheduler. Also please correct the values for any of the variables that I've used.
Hope it helps !
Thanks,
Mohammed
I'm 56% coverage of the code and I can not move.
You can help me to create unit tests for my method newPublier?
Thank you!!!