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
staylorstaylor 

Can someone please help me create test class?

I'm very new at working with Apex code.  Can someone please help me create a test class for the following Apex trigger?

 

1
2
3
4
5
6
7
8
9
10
11
12
13
trigger LeadFixPhoneFormat on Lead (before insert, before update) {
for (Lead i : Trigger.new) {
// Fix Phone Number issues
if (i.Phone != NULL) {
if (i.Phone.startsWith('+1')) {
i.Phone = i.Phone.substring(3);
i.Phone = i.Phone.replace('.', '-');
i.Phone = i.Phone.replaceFirst('(^[0-9][0-9][0-9]).','($1) ');
}
i.Phone = i.Phone.replace('.', '-');
}
    }
}

 

Thank you in advance!

kiranmutturukiranmutturu

try this out

 

@isTest
private class leadtest{
    static testmethod void lkdk(){
    
        lead obj = new lead();
        obj.lastname = 'test';
        obj.company = 'test';
        obj.phone = '+1212321398';
        insert obj;
    }
}