+ Start a Discussion
Sam WardSam Ward 

can anyone help me write a test class??

I have written the above code but I'm unsure how you would write a test class can someone point me to a video or any documention which will help me learn this please? 

I have attached my code incase its a really simple test class to write. 
global class MarketingClicks implements Schedulable {
    global void execute(SchedulableContext ctx) {
        List<Lead> Leadlist = [SELECT Id, Campaign_Name__c FROM Lead WHERE Link_Type__c != ''];

        for(Lead L : LeadList)
            //Create Marketing Click
            L.Link_Type__c = 'TEST';
            Pardot_Campaign__c PC = new Pardot_Campaign__c();
            PC.Lead__c = L.Id;
            PC.Name = L.Campaign_Name__c;
            insert PC;
            L.Campaign_Name__c= '';
            Update L;

Thanks in advance
Agustin BAgustin B
Hi, is quite easy, here you have some links to read, it wont take you long:
Please mark as correct if it helped you, it may help others asking the same.
Sam WardSam Ward
I have tried to write the test class but I'm not really sure where i'm going wrong its just telling me that there where no records inserted (Insertion failed) 
Public Class MarketingClicksTest
    static void setup()
        List<Lead> Leadlist = new List<Lead>();
        for(Integer i=1;i<=10;i++)
         Lead Id = new Lead(Company='Test',Lastname='sam',Status='Open',UK_Canada__c='UK',Phone='000000',Online_Offline__c='Offline',Enquiry_Source__c='Cold Call',Method__c='N/A',Position__c='UNASSIGNED',Industry_Sector__c='Miscellaneous',Campaign_Name__c='Test');
        insert LeadList;
    static testmethod void testMarketingClicksScheduleJob()
        string sch='0 5 12 10 2 ?';
        string jobId=system.schedule('scheduleApexTest',sch,new MarketingClicks());
        List<Lead> LeadList=[SELECT Id, Campaign_Name__c FROM Lead WHERE Campaign_Name__c != ''];
        system.assertEquals(10, Leadlist.size());

can anyone point out where i'm going wrong please? 

ios man 18ios man 18
I see no issue there, what is above the Date line? Is the code executing there? Try with a system debug. 
Maybe you are not even getting inside de batch at all or the "I" record is not filling properly.

Please post entire code relevant to the issue so I can help better. Thanks
ios man 18ios man 18