You need to sign in to do that
Don't have an account?
Rafael Franco Moreno 24
test driven development
I have this error when I deploy the test but I don´t know why
this my test:
@IsTest
public with sharing class LeadTaskTest {
@IsTest
static void createLeadsAndTasksTest(){
//create new lead
Lead newLead = Build.aLead()
.withFirstName('rafa2')
.withLastName('franco2')
.withDescripcionPersonalizada('description example2')
.withTextoAuxiliar('aux text2')
.build();
Task newTask = Build.aTask()
.withDescripcionPersonalizada(newLead.Descripcion_Personalizada__c)
.withTextoAuxiliar(newLead.Texto_Auxiliar__c)
.withWhoId(newLead);
Test.startTest();
insert newLead;
insert newTask;
Test.stopTest();
List<Task> tasks = [
SELECT WhoId, Descripcion_personalizada__c, Texto_auxiliar__c
FROM Task
WHERE WhoId = :newLead.id];
System.assertEquals(1, tasks.size(),'text');
}
}
this is my handler:
public with sharing class LeadTaskHandler {
public createAndInsertTaskAssociatedLeadHandler(List<Lead> leadList) {
List<task> listTask = new List<task>();
for (Lead lead : leadList) {
/*create a task associated with the lead with fields created
*Description_Personalized and Text_Auxiliar__c with lead info
*/
Task newTask = new Task(
Descripcion_Personalizada__c = lead.Descripcion_Personalizada__c,
Texto_Auxiliar__c = lead.Texto_Auxiliar__c,
WhoId = lead.id
);
listTask.add(newTask);
}
insert listTask;
}
}
my trigger:
trigger LeadTrigger on Lead (before insert, before update, after insert) {
if (Trigger.isBefore) {
if (Trigger.isInsert) {
LeadHandler.leadInsertHandler(Trigger.new);
}
}
if (Trigger.isAfter) {
if (Trigger.isInsert) {
LeadTaskHandler.createAndInsertTaskAssociatedLeadHandler(Trigger.new);
}
}
}
and my build:
//Generated by BuildGenerator v1.7
@IsTest global class Build {
/*------------------------------------------------------------------------
LeadBuilderStart
------------------------------------------------------------------------*/
public class LeadBuilder {
private Lead obj = new Lead(LastName = 'STRING',
Company = 'STRING',
Status = Lead.Status.getDescribe().getPickListValues().get(0).getValue()
);
public LeadBuilder withLastName(String value) {
obj.LastName = value;
return this;
}
public LeadBuilder withFirstName(String value) {
obj.FirstName = value;
return this;
}
public LeadBuilder withTextoAuxiliar(String value) {
obj.Texto_Auxiliar__c = value;
return this;
}
public LeadBuilder withDescripcionPersonalizada(String value) {
obj.Descripcion_Personalizada__c = value;
return this;
}
public Lead build() {
return obj;
}
}
public static LeadBuilder aLead() { return new LeadBuilder(); }
/*------------------------------------------------------------------------
LeadBuilderEnd
------------------------------------------------------------------------*/
/*------------------------------------------------------------------------
TaskBuilderStart
------------------------------------------------------------------------*/
public class TaskBuilder {
private Task obj = new Task(Status = 'Not Started',
Priority = 'High'
);
public TaskBuilder withWhoId(Contact value) {
obj.WhoId = value.Id;
return this;
}
public TaskBuilder withWhoId(Lead value) {
obj.WhoId = value.Id;
return this;
}
public TaskBuilder withDescripcionPersonalizada(String value) {
obj.Descripcion_Personalizada__c = value;
return this;
}
public TaskBuilder withTextoAuxiliar(String value) {
obj.Texto_Auxiliar__c = value;
return this;
}
public Task build() {
return obj;
}
}
public static TaskBuilder aTask() { return new TaskBuilder(); }
/*------------------------------------------------------------------------
TaskBuilderEnd
------------------------------------------------------------------------*/
}
this my test:
@IsTest
public with sharing class LeadTaskTest {
@IsTest
static void createLeadsAndTasksTest(){
//create new lead
Lead newLead = Build.aLead()
.withFirstName('rafa2')
.withLastName('franco2')
.withDescripcionPersonalizada('description example2')
.withTextoAuxiliar('aux text2')
.build();
Task newTask = Build.aTask()
.withDescripcionPersonalizada(newLead.Descripcion_Personalizada__c)
.withTextoAuxiliar(newLead.Texto_Auxiliar__c)
.withWhoId(newLead);
Test.startTest();
insert newLead;
insert newTask;
Test.stopTest();
List<Task> tasks = [
SELECT WhoId, Descripcion_personalizada__c, Texto_auxiliar__c
FROM Task
WHERE WhoId = :newLead.id];
System.assertEquals(1, tasks.size(),'text');
}
}
this is my handler:
public with sharing class LeadTaskHandler {
public createAndInsertTaskAssociatedLeadHandler(List<Lead> leadList) {
List<task> listTask = new List<task>();
for (Lead lead : leadList) {
/*create a task associated with the lead with fields created
*Description_Personalized and Text_Auxiliar__c with lead info
*/
Task newTask = new Task(
Descripcion_Personalizada__c = lead.Descripcion_Personalizada__c,
Texto_Auxiliar__c = lead.Texto_Auxiliar__c,
WhoId = lead.id
);
listTask.add(newTask);
}
insert listTask;
}
}
my trigger:
trigger LeadTrigger on Lead (before insert, before update, after insert) {
if (Trigger.isBefore) {
if (Trigger.isInsert) {
LeadHandler.leadInsertHandler(Trigger.new);
}
}
if (Trigger.isAfter) {
if (Trigger.isInsert) {
LeadTaskHandler.createAndInsertTaskAssociatedLeadHandler(Trigger.new);
}
}
}
and my build:
//Generated by BuildGenerator v1.7
@IsTest global class Build {
/*------------------------------------------------------------------------
LeadBuilderStart
------------------------------------------------------------------------*/
public class LeadBuilder {
private Lead obj = new Lead(LastName = 'STRING',
Company = 'STRING',
Status = Lead.Status.getDescribe().getPickListValues().get(0).getValue()
);
public LeadBuilder withLastName(String value) {
obj.LastName = value;
return this;
}
public LeadBuilder withFirstName(String value) {
obj.FirstName = value;
return this;
}
public LeadBuilder withTextoAuxiliar(String value) {
obj.Texto_Auxiliar__c = value;
return this;
}
public LeadBuilder withDescripcionPersonalizada(String value) {
obj.Descripcion_Personalizada__c = value;
return this;
}
public Lead build() {
return obj;
}
}
public static LeadBuilder aLead() { return new LeadBuilder(); }
/*------------------------------------------------------------------------
LeadBuilderEnd
------------------------------------------------------------------------*/
/*------------------------------------------------------------------------
TaskBuilderStart
------------------------------------------------------------------------*/
public class TaskBuilder {
private Task obj = new Task(Status = 'Not Started',
Priority = 'High'
);
public TaskBuilder withWhoId(Contact value) {
obj.WhoId = value.Id;
return this;
}
public TaskBuilder withWhoId(Lead value) {
obj.WhoId = value.Id;
return this;
}
public TaskBuilder withDescripcionPersonalizada(String value) {
obj.Descripcion_Personalizada__c = value;
return this;
}
public TaskBuilder withTextoAuxiliar(String value) {
obj.Texto_Auxiliar__c = value;
return this;
}
public Task build() {
return obj;
}
}
public static TaskBuilder aTask() { return new TaskBuilder(); }
/*------------------------------------------------------------------------
TaskBuilderEnd
------------------------------------------------------------------------*/
}