You need to sign in to do that
Don't have an account?

strange..
Hi. since january i do triggers and depoloy to production without doing a test class..
Today when im going to deploy one trigger, Production SF get me an error saying "Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required"..
I have tested the trigger on sandbox with real case - with insert records..
What can i do?
you should write a test class for that.You cannot deploy the triggers like that.
but until yesterday i always deploy and SF never give me error..
You should write test case. The reason why you didn't get error before could be that other code except the one, that you uploaded without test case(let's say above 85%), had a very good test coverage, and your trigger is not that long, so the average test coverage could be still above 75% even though your code has zero coverage. Now the exceed space is runned out, so the system complains.
i have done tests but user tests..not a test class.. it's not enough user tests?
i have read about the test class..it's a test class to the trigger? i put the input and make run the trigger?
No. User test is not relevant at all. You have write some code, try to read this
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
yes, create some test data in the code and call the functions which you want to test
if the trigger runs with a record insert, i simulate a record insert into the class test?
Noop, then you need to check that a record has really been inserted by checking its id or whatever. Maybe you can post your trigger here.
ok tks. when i deploy one trigger, SF return me error on 8 trigger that allready i had deploy..
I yhave to do one test class to each one?
In principle it is not neccessary, because you didn't get warning before, so if you write a test class for the new trigger, the average test coverage should be above 75% again. But it is right and good way to deploy every trigger with test method/class.
trigger actualizaCondicaoComercial on Pricing__c (after insert) {
List<Condicao_Comercial__c> CondComercialActiva = [select id,produto__c, Tipo_de_Preco_de_Referencia__c,
Centro_de_Carga__c, valido_de__c,
valido_ate__c from Condicao_Comercial__c
where Inactivo__c = false and Aprovada__c = true
];
List<Condicao_Comercial__c> CondComerPC = [select id,produto__c, Centro_de_Carga__c, valido_de__c,
valido_ate__c from Condicao_Comercial__c
where Tipo_de_Preco_de_Referencia__c ='Preço de Compra' AND
Inactivo__c = false and Aprovada__c = true];
List<Pricing_Produto_Final__c> PrecoCompra = [select id,produto__c,
Centro_de_Carga2__c, valido_de__c,
valido_ate__c, Preco_de_Compra_iva__c from Pricing_Produto_Final__c
];
List<Pricing_Produto_Final__c> PrecoVenda = [select id,produto__c,
valido_de__c,
valido_ate__c, pvp_ref_iva__c from Pricing_Produto_Final__c
];
//--------------------------------id dos produtos referencia
Set<Id> prodIds = new Set<Id>();
for (Pricing__c pr : Trigger.new)
if(pr.TR_background__c == 'Platts' || pr.TR_background__c == 'Preço de Venda' ){
prodIds.add(pr.Produto__c);}
//---------------------------Id produtos finais para platts
List <Product2> ProdRefPlatts = new List<Product2>(
[Select Id from
Product2 where Produto_Referencia_Platts__c in :prodIds AND
Grupo_de_Materiais__c = '']);
//---------------------------Id produtos finais para preço de venda
List<Product2> ProdRefPVP =
[select id from Product2
where Produto_Referencia_Preco_de_venda__c in :prodIds AND
Grupo_de_Materiais__c = ''];
for (Pricing__c pr : Trigger.new){
for(Condicao_Comercial__c cca : CondComercialActiva){
if(cca.Tipo_de_Preco_de_Referencia__c == pr.tr_background__c //&& pr.valido_de__c <= cca.valido_de__c
//&& pr.valido_ate__c >= cca.valido_ate__c
) {
if(cca.Tipo_de_Preco_de_Referencia__c == 'Preço de Venda'){
for(Product2 pvp: ProdRefPVP){
if(pvp.id ==cca.produto__c){
cca.Preco_de_referencia__c = pr.preco_final__c *1000;
cca.valido_de__c =pr.valido_de__c;
cca.valido_ate__c =pr.valido_ate__c;
}
}
}else{
//Platts
for(Product2 platts: ProdRefPlatts){
if(platts.id ==cca.produto__c){
cca.Preco_de_referencia__c = pr.preco_final__c;
cca.valido_de__c =pr.valido_de__c;
cca.valido_ate__c =pr.valido_ate__c;
for(Condicao_Comercial__c ccpc :CondComerPC){
for(Pricing_Produto_Final__c ppf :PrecoCompra){
if(ppf.produto__c ==ccpc.produto__c && ppf.Centro_de_Carga2__c==ccpc.Centro_de_Carga__c
&& ppf.valido_de__c == pr.valido_de__c
&& ppf.valido_ate__c == pr.valido_ate__c){
ccpc.Preco_de_referencia__c = ppf.Preco_de_Compra_iva__c;
ccpc.valido_de__c =pr.valido_de__c;
ccpc.valido_ate__c =pr.valido_ate__c;
}}}
}}
}
}else {
if(pr.tr_background__c == 'Produtos Compostos' && cca.produto__c == pr.produto__c)
{
if(cca.Tipo_de_Preco_de_Referencia__c == 'Preço de Compra'){
for(Pricing_Produto_Final__c ppf :PrecoCompra){
if(ppf.produto__c == cca.produto__c && ppf.valido_de__c == pr.valido_de__c
&& ppf.valido_ate__c == pr.valido_ate__c &&ppf.Centro_de_Carga2__c ==cca.Centro_de_Carga__c
){
cca.Preco_de_referencia__c = ppf.Preco_de_Compra_iva__c;
cca.valido_de__c =pr.valido_de__c;
cca.valido_ate__c =pr.valido_ate__c;
}
}}else{
for(Pricing_Produto_Final__c ppfvenda :PrecoVenda){
if(ppfvenda.produto__c == cca.produto__c && ppfvenda.valido_de__c == pr.valido_de__c
&& ppfvenda.valido_ate__c == pr.valido_ate__c){
cca.Preco_de_referencia__c = ppfvenda.pvp_ref_iva__c;
cca.valido_de__c =pr.valido_de__c;
cca.valido_ate__c =pr.valido_ate__c;
}
}
}
}
}
}}
update CondComercialActiva;
update CondComerPC ;
}
my trigger is too big eehhe
First of all, your trigger is in bad shape. Salesforce only allows 20 query or DMI in a trigger. In your code there are 3 levels' loop, it will hit the limitation very easily. If someone in your insert two or more pricing recors, it will 100% break the limitation. You's better read this http://wiki.developerforce.com/index.php/Apex_Code_Best_Practices to optimize your code.
For test this trigger, you need to mimic a pricing record is insearted, and then evaluate the results of trigger execution. For example, check cca.valido_de__c really equals pr(the pricing record which you mimic inserting in test class).valido_de__c as you expected.
yes i know it is in bad shape..the others are bulked eheh. they never make more than one at one time..so will pass..
hum i see..can you give me an sort example with my code?
I am sorry that I can't. It is a bit difficult to understand the relationship of thoes objects and its logic. The code itself makes difficulty for writing test case, because test case is also a good and common way to check the code quality. If it is too difficult to write test case or the coverage can't be improved, then it means the developer needs to re-think the logic of the code. If I were you, I would optimize the code before writing test case.
tks anyway
i had done the test class..i have to pass that no production to run there?or runs only in sandbox?
you need to run in the sandbox first and it will return a test coverage and error/success message. If it is success and test coverage is above 75%, then you can deploy it to prod. That's it.
hum ok :) many tks
i have 78% of coverage test in sandbox.. but when i deploy the trigger to production, SF tells me that my test are 0%! :((((
check your test method, is there any dependent data which is only existing in test environment and not in prod? If so , then it can explain.
yes i put the id of the products hard code.