+ Start a Discussion
ShunnShunn 

Apex class deployment without trigger or test class?

Hi All,

I am no developer. I have this test class in sandbox. I tried to deploy it to production and I am hitting a code coverage error(Code Coverage Failure. Your code coverage is 0%. You need at least 75% coverage to complete this deployment.
PBBRunAssignmentRules)


. see the class here:

// Digital Pi - This Apex class is used to reassign a lead using standard assignment rules
public with sharing class PBBRunAssignmentRules {
@InvocableMethod(label='Re-run Assignment Rules on Lead')
public static void ReRunAssignmentRules(list<string> recordIds) {

set<id> LeadIds = new set<id>();

for (string recordId:recordIds){
id rid=id.valueOf(recordId);
Schema.SObjectType sot= rid.getSObjectType();
if (sot == Lead.sObjectType){
LeadIds.add(rid);
}
}

if (!LeadIds.isempty()){
//ID jobID = System.enqueueJob(new PBBLeadReassignQueueable(LeadIds));
if (system.isFuture()) {
system.debug('running in future already; exiting!');
return;
} else {
system.debug('starting future call');
futureLeadReassign(LeadIds);
}
}
}

@future
public static void futureLeadReassign(Set<ID> ReassignSet) {

system.debug('in the future, doing lead reassignment');
List<Lead> UpdList = [SELECT Id FROM Lead WHERE Id IN: ReassignSet];

for (Lead l:UpdList) {
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
// use leadAssignment rules when updating
l.setOptions(dmo);
}
system.debug(UpdList);
update(UpdList);
}
}


What do I need to do? Do I need a trigger or test class?  Any help with writing this test class please?
Best Answer chosen by Shunn
Raj VakatiRaj Vakati
Use this Test class
@isTest
private class PBBRunAssignmentRulesTest {

	static testMethod void processLead(){
		
		Test.startTest();
		List<Lead> lstLead =   new List<Lead>{
                          new Lead(Company = 'JohnMiller', LastName = 'Mike', Status = 'Open'),
                          new Lead(Company = 'Nike', LastName = 'John', Status = 'Open'),
                          new Lead(Company = 'Miles', LastName = 'Davis', Status = 'Open'),
                          new Lead(Company = 'Reebok', LastName = 'Hillen', Status = 'Open'),
                          new Lead(Company = 'Addidas', LastName = 'Shrin', Status = 'Open')
                         };  
        insert lstLead;
        
		Map<Id,Lead> les = new Map<Id,Lead>([Select Id From Lead]);
		List<string> ids = new List<String>();
		ids.addAll(les.keySet());
		
		PBBRunAssignmentRules.ReRunAssignmentRules(ids);
		PBBRunAssignmentRules.futureLeadReassign(les.keySet());
	}
}

 

All Answers

Krishna.AvvaKrishna.Avva
Hi Shunn,

You would need a Apex Test class to deploy this in production. It should also cover 75% of the APEX Class to make a succesful deployment.
Please get started here : https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro

Regards,
Krishna Avva
Raj VakatiRaj Vakati
If you have a test class in your sandbox 
  1. Include the test class also in changeset along with class and migrate it 
  2. Make sure your test class is running successfully in your sandbox without any errors
ShunnShunn
Krishna and Raj, thanks. Unfortunately, I dont have a test class! I dont know how to write apex classes and triggers. I am not a developer. The code above is from a blog. it works fine in a sandbox and I am trying to deploy it to production. Any help?
Rishab TyagiRishab Tyagi
Hello Shunn,

In order to deploy the code, you need an APEX class. There is no workaround for this step. You can write it on your own or you may hire a developer on an hourly basis for the same. I believe that if it's a single class that needs testing then there won't be too much time required for this task.
Raj VakatiRaj Vakati
Use this Test class
@isTest
private class PBBRunAssignmentRulesTest {

	static testMethod void processLead(){
		
		Test.startTest();
		List<Lead> lstLead =   new List<Lead>{
                          new Lead(Company = 'JohnMiller', LastName = 'Mike', Status = 'Open'),
                          new Lead(Company = 'Nike', LastName = 'John', Status = 'Open'),
                          new Lead(Company = 'Miles', LastName = 'Davis', Status = 'Open'),
                          new Lead(Company = 'Reebok', LastName = 'Hillen', Status = 'Open'),
                          new Lead(Company = 'Addidas', LastName = 'Shrin', Status = 'Open')
                         };  
        insert lstLead;
        
		Map<Id,Lead> les = new Map<Id,Lead>([Select Id From Lead]);
		List<string> ids = new List<String>();
		ids.addAll(les.keySet());
		
		PBBRunAssignmentRules.ReRunAssignmentRules(ids);
		PBBRunAssignmentRules.futureLeadReassign(les.keySet());
	}
}

 
This was selected as the best answer
ShunnShunn
@Raj Vakati! Many Thanks for this! it is splendid! Thanks everyone for your help and guidance!