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
hickmand1hickmand1 

Test for basis Apex Trigger

I',m newbie to apex.  I've written a basic Apex trigger that creates a new custom record when a Lead is created.  I now need to write a test in order to deploy it..... I have no clue where to start.  Please help!

 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Trigger createAMSLead_c on Lead (after insert) {
    
    List <AMS_Leads__c> AMSLeadsInsert = new List <AMS_Leads__c> ();
        for (Lead o : Trigger.new) {
        if (o.LeadSource == 'Lead from Med4All website') {
        AMS_Leads__c v = new AMS_Leads__c (); 
        v.Campaign_Lead_Info__c = o.Id; 
        v.Email_Address__c = o.Email;
        v.Notes__c = o.Description;
        v.Home_Work__c = o.Phone;
        v.Cell_Phone__c = o.MobilePhone;
        v.Date_Time_of_Response__c = system.NOW();
        v.Follow_Up_Method__c = 'Telephonic - Outsource'; 
        
              
        AMSLeadsInsert.add(v);
        
        
       } 
       
    }
        try {
        insert AMSLeadsInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
        }
        }
Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

See this develope your test class. If any issue let me know.

 

http://forceschool.blogspot.com/2011/06/testing-trigger-structure.html