You need to sign in to do that
Don't have an account?
lucky013219147071527237
can u write the test class in this trigger
controlaAreaTalhaoAutomatico on Talhao__c trigger (after insert, after update, after delete) {
Map <Id, List <Talhao__c>> fazendaTalhoes = new Map <Id, List <Talhao__c>> ();
<Talhao__c> talhoesAutoInsert List = new List <Talhao__c> ();
List <Talhao__c> talhoesAutoUpdate <Talhao__c> = new List ();
List <Talhao__c> talhoesAutoDelete <Talhao__c> = new List ();
Integer i = 0;
List <Talhao__c> plots,
if (Trigger.isDelete)
plots = Trigger.old;
else
= Trigger.new plots,
for (Field Talhao__c: areas) {
if (Util.impedeTriggerAreaTalhaoAutomatico)
Util.impedeTriggerAreaTalhaoAutomatico = false;
else {
if (talhao.Talhao_Automatico__c && Trigger.isDelete)
talhao.addError ('Not You can delete the Auto Field '),
if (talhao.Talhao_Automatico__c && Trigger.isUpdate && (Trigger.old [i] Name = talhao.Name / / | | Trigger.old [i] = Area_do_Talhao__c talhao.Area_do_Talhao__c.!.!
) )
talhao.addError ('Can not Change Name or Area Auto Field'),
if (talhao.Talhao_Automatico__c && (Trigger.isDelete | | Trigger.isInsert | | (Trigger.isUpdate && Trigger.old [i] Area_do_Talhao__c!. ! talhao.Area_do_Talhao__c =))) {
List list = <Talhao__c> fazendaTalhoes.get (talhao.BR_Farm__c),
if (list == null)
list = new List <Talhao__c> ();
lista.add (Field);
fazendaTalhoes. put (talhao.BR_Farm__c, list);
}
}
i + +;
}
if (fazendaTalhoes.isEmpty ()) {
Map = new Map <Id,Account> fazendaArea <Id,Account> ([SELECT Id FROM Account WHERE Id BR_AreaFarm__c = : fazendaTalhoes.keySet ()]);
Map <Id,Decimal> fazendaAreaTalhoes <Id,Decimal> = new Map (),
is (AggregateResult areaTalhoes: [BR_Farm__c SELECT SUM (Area_do_Talhao__c) Area Talhao__c FROM WHERE = BR_Farm__c: fazendaTalhoes.keySet () = false AND Talhao_Automatico__c IsDeleted AND GROUP BY BR_Farm__c = false])
fazendaAreaTalhoes.put ((Id) areaTalhoes.get ('BR_Farm__c'), (Decimal) areaTalhoes.get ('Area'));
Map <Id,Talhao__c> talhaoAuto <Id,Talhao__c> = new Map (),
for (Field Talhao__c: [SELECT Id, BR_Farm__c, Area_do_Talhao__c Talhao__c FROM WHERE = BR_Farm__c: fazendaTalhoes.keySet () = true AND AND Talhao_Automatico__c IsDeleted = false ORDER BY DESC LastModifiedDate])
if (talhaoAuto.get (talhao.BR_Farm__c) == null)
talhaoAuto.put (talhao.BR_Farm__c, field);
else
talhoesAutoDelete.add (Field),
for (Id idFazenda: fazendaTalhoes.keySet ()) {
Decimal = areaFazenda fazendaArea.get . (idFazenda) BR_AreaFarm__c;
areaTalhoes Decimal = fazendaAreaTalhoes.get (idFazenda);
Automatic Talhao__c = talhaoAuto.get (idFazenda),
if (areaTalhoes == null)
areaTalhoes = 0,
if (areaFazenda <areaTalhoes) {
for (Talhao__c error: fazendaTalhoes . get (idFazenda))
erro.addError ('The sum of the areas of non-Automatic Plots must not exceed the area of the corresponding Treasury.');
} else if (automatic == null) {
field = new Talhao__c Talhao__c ();
Field . Name = 'Automatic Field';
talhao.Area_do_Talhao__c = areaFazenda - areaTalhoes;
system.debug ('gggggggggggg' + talhao.Area_do_Talhao__c);
talhao.BR_Farm__c = idFazenda;
talhao.Talhao_Automatico__c = true;
talhoesAutoInsert.add (field);
} else {
automatico.Area_do_Talhao__c = areaFazenda - areaTalhoes;
automatico.Impede_Trigger_Area_Talhao_Automatico__c = true;
talhoesAutoUpdate.add (automatic);
}
}
if (talhoesAutoDelete.isEmpty ()!)
Delete talhoesAutoDelete,
if (talhoesAutoUpdate.isEmpty ()!)
Update talhoesAutoUpdate,
if ( ! talhoesAutoInsert.isEmpty ())
Insert talhoesAutoInsert;
}
}
Map <Id, List <Talhao__c>> fazendaTalhoes = new Map <Id, List <Talhao__c>> ();
<Talhao__c> talhoesAutoInsert List = new List <Talhao__c> ();
List <Talhao__c> talhoesAutoUpdate <Talhao__c> = new List ();
List <Talhao__c> talhoesAutoDelete <Talhao__c> = new List ();
Integer i = 0;
List <Talhao__c> plots,
if (Trigger.isDelete)
plots = Trigger.old;
else
= Trigger.new plots,
for (Field Talhao__c: areas) {
if (Util.impedeTriggerAreaTalhaoAutomatico)
Util.impedeTriggerAreaTalhaoAutomatico = false;
else {
if (talhao.Talhao_Automatico__c && Trigger.isDelete)
talhao.addError ('Not You can delete the Auto Field '),
if (talhao.Talhao_Automatico__c && Trigger.isUpdate && (Trigger.old [i] Name = talhao.Name / / | | Trigger.old [i] = Area_do_Talhao__c talhao.Area_do_Talhao__c.!.!
) )
talhao.addError ('Can not Change Name or Area Auto Field'),
if (talhao.Talhao_Automatico__c && (Trigger.isDelete | | Trigger.isInsert | | (Trigger.isUpdate && Trigger.old [i] Area_do_Talhao__c!. ! talhao.Area_do_Talhao__c =))) {
List list = <Talhao__c> fazendaTalhoes.get (talhao.BR_Farm__c),
if (list == null)
list = new List <Talhao__c> ();
lista.add (Field);
fazendaTalhoes. put (talhao.BR_Farm__c, list);
}
}
i + +;
}
if (fazendaTalhoes.isEmpty ()) {
Map = new Map <Id,Account> fazendaArea <Id,Account> ([SELECT Id FROM Account WHERE Id BR_AreaFarm__c = : fazendaTalhoes.keySet ()]);
Map <Id,Decimal> fazendaAreaTalhoes <Id,Decimal> = new Map (),
is (AggregateResult areaTalhoes: [BR_Farm__c SELECT SUM (Area_do_Talhao__c) Area Talhao__c FROM WHERE = BR_Farm__c: fazendaTalhoes.keySet () = false AND Talhao_Automatico__c IsDeleted AND GROUP BY BR_Farm__c = false])
fazendaAreaTalhoes.put ((Id) areaTalhoes.get ('BR_Farm__c'), (Decimal) areaTalhoes.get ('Area'));
Map <Id,Talhao__c> talhaoAuto <Id,Talhao__c> = new Map (),
for (Field Talhao__c: [SELECT Id, BR_Farm__c, Area_do_Talhao__c Talhao__c FROM WHERE = BR_Farm__c: fazendaTalhoes.keySet () = true AND AND Talhao_Automatico__c IsDeleted = false ORDER BY DESC LastModifiedDate])
if (talhaoAuto.get (talhao.BR_Farm__c) == null)
talhaoAuto.put (talhao.BR_Farm__c, field);
else
talhoesAutoDelete.add (Field),
for (Id idFazenda: fazendaTalhoes.keySet ()) {
Decimal = areaFazenda fazendaArea.get . (idFazenda) BR_AreaFarm__c;
areaTalhoes Decimal = fazendaAreaTalhoes.get (idFazenda);
Automatic Talhao__c = talhaoAuto.get (idFazenda),
if (areaTalhoes == null)
areaTalhoes = 0,
if (areaFazenda <areaTalhoes) {
for (Talhao__c error: fazendaTalhoes . get (idFazenda))
erro.addError ('The sum of the areas of non-Automatic Plots must not exceed the area of the corresponding Treasury.');
} else if (automatic == null) {
field = new Talhao__c Talhao__c ();
Field . Name = 'Automatic Field';
talhao.Area_do_Talhao__c = areaFazenda - areaTalhoes;
system.debug ('gggggggggggg' + talhao.Area_do_Talhao__c);
talhao.BR_Farm__c = idFazenda;
talhao.Talhao_Automatico__c = true;
talhoesAutoInsert.add (field);
} else {
automatico.Area_do_Talhao__c = areaFazenda - areaTalhoes;
automatico.Impede_Trigger_Area_Talhao_Automatico__c = true;
talhoesAutoUpdate.add (automatic);
}
}
if (talhoesAutoDelete.isEmpty ()!)
Delete talhoesAutoDelete,
if (talhoesAutoUpdate.isEmpty ()!)
Update talhoesAutoUpdate,
if ( ! talhoesAutoInsert.isEmpty ())
Insert talhoesAutoInsert;
}
}
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
You need to insert a record in the Talhao__c object and confirm if the changes/updates you are doing in the trigger are being executed or not.
If you face any issues, pls post it back to this thread..