You need to sign in to do that
Don't have an account?
Steve 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
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
Can you please share the test class for this? Are you using seeAllData=True in your test class?
Regards
-Ajeet
Salesforcegig (https://salesforcegig.com)
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);
}
}
}
The above is the apex class. Can you please share its test class?
Regards
-Ajeet
Salesforcegig (https://salesforcegig.com)
So something is missing.
What's can be done Ajeet?
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)
Cheers,
Steve
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)
Does that sound logical?
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)
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
Please refer to this article: https://www.salesforceben.com/way-to-delete-apex-classes-from-production/
Regards
-Ajeet Jain
Salesforcegig (https://salesforcegig.com)