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
Steve PeckSteve Peck 

Change set Validation Failed - code coverage 72%

Hello community,

I completely understand that this has failed to deploy because the code coverage needs to be at least 75%. 2 things to say and ask please:

1. I sourced this on-line and it works well in my Sandbox (I realise why vs Production). I'm triggering in from a Process Builder Flow.
2. I would like to deploy this in Production. So if this can presumably be modified so that it will pass a) can someone here assist or b) should I source a developer elswehere to help or c) is there a reason that this should not be used?

I'm an admin - obviously not a developer.

All advice & guidance would be very welcome.

Thanks,
Steve
Apex ClassUser-added image
Ajeet28augAjeet28aug
Hi Steve,

Can you please share the test class for this? Are you using seeAllData=True in your test class? 

Regards
-Ajeet 
Salesforcegig (https://salesforcegig.com)
 
Steve PeckSteve Peck
Righ here Ajeet:

Public class AutoConvertLeads
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();

List<Lead> myLeads = [Select id, name, company from Lead where id IN:LeadIds];
List<String> Company = New List<String>();

for (Lead l:myLeads){
Company.add(l.company);
}

List<Account> matchAccount = [Select id, Name from account where Name IN:Company];

Integer i=0;
for(Lead currentlead: myLeads){
for (Account a:matchAccount){
if (currentlead.Company == a.name){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setAccountId(a.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
i++;
Break;
}
}
If (i==0)
{
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
i=0;
}

if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
Ajeet28augAjeet28aug
Hi Steve,

The above is the apex class. Can you please share its test class?

Regards
-Ajeet
Salesforcegig (https://salesforcegig.com)
Steve PeckSteve Peck
This is all I have and it's all I used in Sandbox to test. Is it surprising that it worked at all?

So something is missing.

What's can be done Ajeet?



 
Ajeet28augAjeet28aug

Hi Steve,

To deploy the apex, the test class must be there. You can create the test class. Here's the code: https://github.com/Rakeshistom/Auto-Convert-Leads/blob/master/TestAutoConvertLeads

 

Let me know if the above helps, or let me know if you want further help, I can walk you through the above process, just send me Hi on skype: salesforcegig

Regards
-Ajeet Jain
Salesforcegig (https://salesforcegig.com)

Steve PeckSteve Peck
Thanks very much Ajeet. Let me try this and if I have trouble - and if I get it working - I will update you here.
Cheers,
Steve
Steve PeckSteve Peck
OK, I created the new class and deployed them both together to production and got this error with validation.

User-added image
Ajeet28augAjeet28aug

Hi Steve, 

Can you open the developer console in your sandbox and run this test class? And please share the lines which are not covered. 
Or you can you try once with the below-updated test class:

@isTest 
      public class TestAutoConvertLeads{
      static testMethod void createnewlead() {
      User userToCreate = [Select id from user where profile.name='System Administrator' Limit 1];
      Account acc = new Account(Name='Salesforce');
      insert acc;
      Test.startTest();    
      Lead leadToCreate =new Lead();
      List<id> Ids= New List<Id>();
      leadToCreate.ownerid= userToCreate.id;
      leadToCreate.LastName ='Gupta';
      leadToCreate.Company='Salesforce';
      leadToCreate.LeadSource='Partner Referral';
      leadToCreate.Rating='';
      leadToCreate.Status='';
      insert leadToCreate; 
      
      Ids.add(leadToCreate.id);
      AutoConvertLeads.LeadAssign(Ids);
      
      Test.stopTest();
   }
}

Regards
-Ajeet Jain
SalesforceGig (https://salesforcegig.com)

Steve PeckSteve Peck
OK, I used your updated code, redeployed it and validated. The code coverage seems OK now and was at 82% in the dev console. But I have another error which I'd overlooked in previous validations and I know that this relates to another Apex class (I recongnise the name here which was produced last year and also relates to Lead to Contact conversion). I don't actually need the other class anymore so I'll have to look back and figure out how to stop that and a trigger and it hopefully that should prevent this validation error.

Does that sound logical?

User-added image
Ajeet28augAjeet28aug
Hi Steve,

In that case, just deactivate that trigger in the sandbox and deploy it along with the above changeset. 

Regards
-Ajeet Jain
Salesforcegig (https://salesforcegig.com)
Steve PeckSteve Peck
Hi Ajeet,

Back again...there is no trigger. I need to deactivate/delete these batch classes which are stopping this deployment.
This seems my simplest way but Force.com IDE is discontinued.

"Probably the simplest way to delete / disable is to connect to your Salesforce production org using eclipse and Force.com IDE, download the apex class / trigger, change the status of the Apex class / trigger to “Deleted” or “Inactive” in the class/trigger XML file in Force.com IDE and save. Here is the step-by-step guide with screenshots on how to do the same"

Any other tool I can use?

Steve
Steve PeckSteve Peck
Forgot to add the image.User-added image
Ajeet28augAjeet28aug
Hi Steve, 

Please refer to this article: https://www.salesforceben.com/way-to-delete-apex-classes-from-production/

Regards
-Ajeet Jain
Salesforcegig (https://salesforcegig.com)