So, I did a button linked to an apex class which turns a candidate into an account when a recruiter wants, when I try to deploy it on production it says that I have 72% of test coverage, but when I run the test in my developer console (on sandbox) it doesn't show the lines in blue or red to help me improve the percentage. Please take a look on the codes and help me.
The Class:
global with sharing class ContratarCandidato{
global ContratarCandidato(){}
@TestVisible
WebService static void gerarContaFromCandidato (Id idCandidato){
system.Debug(idCandidato);
List<SFDC_Candidate__c> lstCandidato = new List<SFDC_Candidate__c>([
SELECT Sobrenome_do_candidato__c, Name, CPF__c, Genero__c, Telefone__c, Celular__c, Email__c, Email_alternativo__c,
Endereco__c, Bairro__c, Cidade__c, Estado__c, CEP__c, Indicacao_funcionario__c, Id, Origem_da_conta__c
FROM SFDC_Candidate__c
WHERE Id = :idCandidato]);
system.Debug(lstCandidato);
Account newAccount= new Account();
if(lstCandidato[0].Sobrenome_do_candidato__c == null){
newAccount.LastName = 'N/A';
}else{
newAccount.LastName = lstCandidato[0].Sobrenome_do_candidato__c;
}
if(lstCandidato[0].Name== null){
newAccount.FirstName = 'N/A';
}else{
newAccount.FirstName = lstCandidato[0].Name;
}
if(lstCandidato[0].CPF__c== null){
newAccount.CPF__pc= 'N/A';
}else{
newAccount.CPF__pc= lstCandidato[0].CPF__c;
}
if(lstCandidato[0].Genero__c == 'Feminino'){
newAccount.Salutation = 'Sra.';
}
if(lstCandidato[0].Genero__c == 'Masculino'){
newAccount.Salutation = 'Sr.';
}
if(lstCandidato[0].Telefone__c != null){
newAccount.Phone = lstCandidato[0].Telefone__c;
}
if(lstCandidato[0].Celular__c != null){
newAccount.PersonMobilePhone = lstCandidato[0].Celular__c;
}
if(lstCandidato[0].Email__c != null){
newAccount.PersonEmail = lstCandidato[0].Email__c;
}
if(lstCandidato[0].Endereco__c != null){
newAccount.PersonMailingStreet = lstCandidato[0].Endereco__c;
}
if(lstCandidato[0].Bairro__c != null){
newAccount.Bairro_de_correspondencia__pc = lstCandidato[0].Bairro__c;
}
if(lstCandidato[0].Cidade__c != null){
newAccount.PersonMailingCity = lstCandidato[0].Cidade__c;
}
if (lstCandidato[0].Estado__c != null){
newAccount.PersonMailingState = lstCandidato[0].Estado__c;
}
if (lstCandidato[0].CEP__c != null){
newAccount.PersonMailingPostalCode = lstCandidato[0].CEP__c;
}
if (lstCandidato[0].Origem_da_conta__c != null){
newAccount.AccountSource = lstCandidato[0].Origem_da_conta__c;
}
newAccount.Status_da_conta__c = 'Ativa';
newAccount.Type = 'Colaborador PJ';
newAccount.Colaborador_RCS__c = true;
newAccount.RecordTypeId = '012q00000000STyAAM';
insert newAccount;
}
}
The Test:
@isTest
public class ContratarCandidatoTest {
static testMethod void gerarContaFromCandidatoTest(){
SFDC_Candidate__c newCandidato = new SFDC_Candidate__c();
newCandidato.Sobrenome_do_candidato__c = 'Class';
newCandidato.Name = 'Test';
newCandidato.CPF__c = '980.091.918-22';
newCandidato.Telefone__c = '(19) 3910-0295';
newCandidato.Celular__c = '(19) 98940-0982';
newCandidato.Email__c = 'testclass12@rcs.com.br';
newCandidato.Email_alternativo__c = 'emailalternativo@rcs.com.br';
newCandidato.Endereco__c = 'Avenida Andromêda, 885';
newCandidato.Estado__c = 'São Paulo';
newCandidato.Bairro__c = 'Alphaville';
newCandidato.Cidade__c = 'Barueri';
newCandidato.CEP__c = '86000-000';
insert newCandidato;
newCandidato.Celular__c = '(19) 91234-5678';
update newCandidato;
List<SFDC_Candidate__c> lstCandidato = new List<SFDC_Candidate__c>([
SELECT Sobrenome_do_candidato__c, Name, CPF__c, Telefone__c, Celular__c, Email__c,
Email_alternativo__c, Endereco__c, Estado__c, Bairro__c, Cidade__c, CEP__c, Genero__c
FROM SFDC_Candidate__c
WHERE Name = 'Test'
]);
List<RecordType> newRecordType = new List<RecordType>([
SELECT Name, Id, SobjectType
FROM RecordType
WHERE Name = 'Colaborador RCS'
AND SObjectType = 'Account']);
Account newAccount = new Account();
if(lstCandidato[0].Sobrenome_do_candidato__c == null){
newAccount.LastName = 'N/A';
}else{
newAccount.LastName = newCandidato.Sobrenome_do_candidato__c;
}
if(lstCandidato[0].Name== null){
newAccount.FirstName = 'N/A';
}else{
newAccount.FirstName = newCandidato.Name;
}
if(lstCandidato[0].CPF__c== null){
newAccount.CPF__pc= 'N/A';
}else{
newAccount.CPF__pc= newCandidato.CPF__c;
}
if(lstCandidato[0].Genero__c == 'Feminino'){
newAccount.Salutation = 'Sra.';
}else{
newAccount.Salutation = 'Sr.';
}
if(lstCandidato[0].Telefone__c != null){
newAccount.Phone = newCandidato.Telefone__c;
}
if(lstCandidato[0].Celular__c != null){
newAccount.PersonMobilePhone = newCandidato.Celular__c;
}
if(lstCandidato[0].Email__c != null){
newAccount.PersonEmail= newCandidato.Email__c;
}
if(lstCandidato[0].Endereco__c != null){
newAccount.PersonMailingStreet = newCandidato.Endereco__c;
}
newAccount.Bairro_de_correspondencia__pc = newCandidato.Bairro__c;
if(newCandidato.Cidade__c != null){
newAccount.PersonMailingCity = newCandidato.Cidade__c;
}
if (newCandidato.Estado__c != null){
newAccount.PersonMailingState = newCandidato.Estado__c;
}
if (newCandidato.CEP__c != null){
newAccount.PersonMailingPostalCode = newCandidato.CEP__c;
}
newAccount.Status_da_conta__c = 'Ativa';
newAccount.Type = 'Colaborador PJ';
newAccount.Colaborador_RCS__c = true;
newAccount.RecordTypeId = newRecordType[0].Id;
insert newAccount;
List<SFDC_Candidate__c> lstCandidato2 = new List<SFDC_Candidate__c>([
SELECT Name
FROM SFDC_Candidate__c
WHERE Name = 'Test'
]);
System.debug(lstCandidato2);
lstCandidato2[0].Name = 'Teste';
update lstCandidato2[0];
List<Account> lstTeste = new List<Account>([
SELECT Status_da_conta__c, FirstName
FROM Account
WHERE FirstName = 'Test'
]);
System.debug(lstTeste);
lstTeste[0].Status_da_conta__c = 'Inativa';
update lstTeste[0];
System.debug(lstTeste);
delete newCandidato;
delete newAccount;
}
}

