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
ssrssr 

need help to write testclasses

Hi tell me the good example how to write test classes
Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet For Test Method.

 

public class flagtst

{

public boolean flag;

public void testflag()

{

    if(flag== false)

    {

        flag=true;

        system.debug('_______check flag___________');

    }

}

 

public static testMethod void CoverConstructor()

{

    flagtst f=new flagtst();

    f.flag=false;

    f.testflag();

}      

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

ssrssr
how to insert code here it is throwing error when iam keeping code in body
ssrssr
hai jain may i know your mail id so that i can interact with you when i get doubys dont mind for asking thsi is my mail id salesfor63@gmail.com
ssrssr
hi we have two custom fields like End_Time_cems__c and Start_Time_c ems__c how to write validation for End_time_cems_c should greter than Start_Time_cems__c plesae help me in this through coding
ssrssr

I have schedular for the below class,

 

please help how to write test class for this code.

 

global class cEMS_SAP_Report_Scheduler Implements Schedulable
{
    global void execute(SchedulableContext sc)
   {
    cEMS_Controller_SAP cSAP = new cEMS_Controller_SAP();
    cSAP.init();
    List<Sap_Report_cems__c> lstSpekerReport = new List<Sap_Report_cems__c>();
    String strSpeakerReport = 'Event ID,Event Start Date,Event End Date,Department,Cost Center,Applicant name,Applicant Date,Order Type,Company Code,Controlling Area\n';            
    for(integer i =0 ;i < cSAP.lstWrapEvent.size();i++)
          {
            Sap_Report_cems__c src=new Sap_Report_cems__c();
            src.Event_ID_cems__c = cSAP.lstWrapEvent[i].EventId1;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].EventId1 + ',';
            src.Event_Start_Date_cems__c = cSAP.lstWrapEvent[i].eventStartDate;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].eventStartDate + ',';
            src.Event_End_Date_cems__c = cSAP.lstWrapEvent[i].EventendDate;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].EventendDate + ',';
            src.Department_cems__c = cSAP.lstWrapEvent[i].Department;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].Department + ',';
            src.Description_cems__c = cSAP.lstWrapEvent[i].Objectives;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].Objectives + ',';
            src.Cost_Center_cems__c = cSAP.lstWrapEvent[i].Costcenter;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].Costcenter + ',';
            src.Applicant_cems_ref__c = cSAP.lstWrapEvent[i].ApplicantId;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].Applicant + ','; 
            src.Applicant_Date_cems__c = cSAP.lstWrapEvent[i].ApplicantDate;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].ApplicantDate + ',';
            src.Order_type_cems__c = cSAP.lstWrapEvent[i].OrderType;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].OrderType + ',';
            src.Company_code_cems__c = cSAP.lstWrapEvent[i].CompanyCode;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].CompanyCode + ',';
            src.Controlling_Area_cems__c = cSAP.lstWrapEvent[i].ControllingArea;
            strSpeakerReport = strSpeakerReport + cSAP.lstWrapEvent[i].ControllingArea + '\n';
            lstSpekerReport.add(src);
            }
            insert LstSpekerReport;           
         Document doc  = new document();
         doc.Name  = 'EMSSAP_' + system.now().format('dd/MM/yyyy hh:mm:ss') + '.csv';      
         doc.ContentType = 'text/csv';
         doc.body = blob.valueof(strSpeakerReport);
         doc.folderid = [select id from folder where name='cEMS_SAP_Report'].id; // Stores in the currennt users "My Personal 
         insert doc;
     }
}