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
James BensonJames Benson 

Unable to update lead trigger because it needs a test class to reference. However, the trigger doesn't reference any test classes.

Hi,

I'm trying to update the following trigger using a changeset. However, I cannot run apex tests for a specific test class because the trigger doesn't reference one.
 
trigger LeadDomainMatch2 on Lead (before Insert,before update) {
    for (Lead leadInLoop : Trigger.new) {
   
if (leadInLoop.Domain__c != 'gmail.com' && leadInLoop.Domain__c != 'yahoo.com' && LeadInLoop.New_York__c == FALSE && LeadInLoop.New_Jersey__c == FALSE && LeadInLoop.Status == 'MQL' && LeadInLoop.Florida__c == FALSE) {
    // Retrieve owner from Account record based on email domain name
    list <Account> acct = [Select Pro_Associate_ID__c from Account WHERE Account_Email_Domain__c = :leadInLoop.Domain__c AND Account.Type = 'Customer' Limit 2];
    
        if (acct.size() == 1) {

    //the next line is for debugging, to check that you are getting a result back from the query
            System.debug('account owner id is: ' + acct[0].Pro_Associate_ID__c);
    leadInLoop.OwnerId=acct[0].Pro_Associate_ID__c;
        }
    }
}
}
How do I fix this trigger so I can deploy it to production?

James
sfdcMonkey.comsfdcMonkey.com
Hi james, , for triggers you need a minimum of 1%.and  Recommended is to have 75% test class coverage :

create and check folloing test class for your trigger :
 
@isTest
public class UnitTest1 {
    static testMethod void testMethodOne(){
    Lead l = new Lead();
     l.Company = 'Test Lead';
     l.LastName = 'Lead Last Name';
    // add all required fields test data here as per your trigger if condition     
    insert l;
    }
}
Kindly let us know if it helps you, and if it helps you close your query by choosing best answer so it helps other in future 
Thanks

 
James BensonJames Benson

Hi Piyush!

I'm extremley new when it comes to apex code development (learning as I go). When I create this test class, how do I tell my trigger to reference it? Or is it as simple as creating the class, deploying the changeset that contains the trigger, and run the specific test that calls UnitTest1?

Best,
James

sfdcMonkey.comsfdcMonkey.com
no, just create above test class as simple class, and run your test class in developer console and check the status of test class and your trigger :
User-added image
[open image in new tab for better view]

if your test class run successful and trigger code got more then 1% coverge, then while deploying the changeset that contains the trigger, run the specific test and give this test class name.

Thanks
James BensonJames Benson
Piyush,

Thank you - am I able to test this anywhere else but production, by chance?

James
sfdcMonkey.comsfdcMonkey.com
test this on sandbox before upload chnageset to prodction,and after upload  run this specify test class while validate/deploye 
Thanks
 
James BensonJames Benson
Hi Jaipur – I’m testing this solution tomorrow (during one of our planned releases). I will not mark it as best answer until it works after our release. Thanks for your patience, James