You need to sign in to do that
Don't have an account?
Vanessa Barros
class test in sandbox 81% and in production dont deploy
Hi.
i had made a class test in sandbox, gives me 81%..then i deploy the class to production to run , gives me an error : Failure Message: "System.QueryException: List has no rows for assignment to SObject", Failure Stack Trace: "Class.myClass.myTest: line 6, column 21 External entry point"
this is my class:
line 6 is this:
Product2 produto3 = [select id from Product2 where name = 'DSL 10ppm CIF NWE AAWZC00'];
Can help me?
@isTest
private class myClass {
static testMethod void myTest() {
//--------------------------------------------------
Product2 produto3 = [select id from Product2 where name = 'DSL 10ppm CIF NWE AAWZC00'];
RecordType rtp = [select id from RecordType where name = 'Platts'];
Pricing__c p = new Pricing__c (RecordTypeId = rtp.id, produto__c =produto3.id, valor_inicial__c =1, cambio_usd_ton__c = 1,
valido_de__c =date.today(), valido_ate__c= date.today());
insert p;
Product2 produto4 = [select id from Product2 where name = 'Diesel - PVP'];
RecordType rtpp4 = [select id from RecordType where name = 'Preço de Venda'];
Pricing__c p4 = new Pricing__c (RecordTypeId = rtpp4.id, produto__c = produto4.id,
valido_de__c =date.today(), valido_ate__c= date.today());
insert p4;
Product2 produto_composto2 = [select id from Product2 where name = 'COMBUSTÍVEL BIODIESEL 10%'];
RecordType rtpp = [select id from RecordType where name = 'Produtos Compostos'];
Pricing__c p3 = new Pricing__c (RecordTypeId = rtpp.id, produto__c = produto_composto2.id,
valido_de__c =date.today(), valido_ate__c= date.today());
insert p3;
Account acc = new Account(name='testing account');
insert acc;
Account acc_filho = new Account(name='testing account filho');
insert acc_filho;
Account a = [select Parentid from Account where //id ='001Q000000AdLXY'
id= :acc_filho.id];
a.parentid = acc.id;
//'001Q000000AdLXO';
update a;
Account aa = [select Parentid from Account where id= :acc_filho.id];
aa.parentid = null;
update aa;
Partidas_Financeiras__c pf_criar = new Partidas_Financeiras__c(conta__c = acc.id,valor_liquido__c =1 );
insert pf_criar;
list<Partidas_Financeiras__c> pf = [select Recebido_aguarda_registo_em_SAP__c from
Partidas_Financeiras__c where conta__c = :acc.id];
for(Partidas_financeiras__c pfff : pf){
pfff.Recebido_aguarda_registo_em_SAP__c =true;
}
update pf;
//create a test opportunity
Opportunity op = new Opportunity(name='testopp1', StageName='Prospecting', CloseDate = date.today(),
AccountId = acc.Id);
insert op;
Product2 produto = [select id from Product2 where name = 'COMBUSTÍVEL GASÓLEO'];
PriceBookEntry pbookEntry = [select id from PriceBookEntry where Product2Id = :produto.id];
Centro_de_carga__c cdc = [select id from Centro_de_carga__c where name = '01 - PrioAF: Matosinhos'];
//create opportunity line item
OpportunityLineItem olitem =
new OpportunityLineItem(OpportunityId = op.Id, PriceBookEntryId = pbookEntry.Id,
Quantity = 1,centro_de_carga2__c = cdc.id, tipo_de_preco_de_referencia__c = 'Preço de Compra',
incoterms__c = 'EXW');
insert olitem;
Product2 produto_composto = [select id from Product2 where name = 'COMBUSTÍVEL BIODIESEL 10%'];
PriceBookEntry pbookEntry2 = [select id from PriceBookEntry where Product2Id = :produto_composto.id];
Centro_de_carga__c cdc2 = [select id from Centro_de_carga__c where name = '01 - PrioAF: Matosinhos'];
OpportunityLineItem olitem2 =
new OpportunityLineItem(OpportunityId = op.Id, PriceBookEntryId = pbookEntry2.Id,
Quantity = 1,centro_de_carga2__c = cdc2.id, tipo_de_preco_de_referencia__c = 'Preço de Compra',
incoterms__c = 'EXW');
insert olitem2;
Product2 produto_composto3 = [select id from Product2 where name = 'COMBUSTÍVEL BIODIESEL 20%'];
PriceBookEntry pbookEntry3 = [select id from PriceBookEntry where Product2Id = :produto_composto3.id];
OpportunityLineItem olitem3 =
new OpportunityLineItem(OpportunityId = op.Id, PriceBookEntryId = pbookEntry3.Id,
Quantity = 1,tipo_de_preco_de_referencia__c = 'Preço de Venda',
incoterms__c = 'EXW');
insert olitem3;
Product2 produto7 = [select id from Product2 where name = 'COMBUSTÍVEL GASÓLEO'];
PriceBookEntry pbookEntry4 = [select id from PriceBookEntry where Product2Id = :produto7.id];
//create opportunity line item
OpportunityLineItem olitem4 =
new OpportunityLineItem(OpportunityId = op.Id, PriceBookEntryId = pbookEntry4.Id,
Quantity = 1, tipo_de_preco_de_referencia__c = 'Platts',
incoterms__c = 'EXW');
insert olitem4;
//---------------------------------------------------------------------
Proposta__c pro =new Proposta__c (Oportunidade__c =op.Id, name ='teste',valido_de__c =Date.today(),
Validade_em_dias__c =3, count_proposta__c =1 );
insert pro;
Proposta__c pro2= [select substituida__c from Proposta__c where id = :pro.id];
pro2.substituida__c = true;
update pro2;
Proposta__c pro3 =new Proposta__c (Oportunidade__c =op.Id, name ='teste2',valido_de__c =Date.today(),
Validade_em_dias__c =3 );
insert pro3;
//-----------------------------------------------------------
RecordType rt = [select id from RecordType where name = 'Combustíveis Compostos'];
Input_Resumo_pricing__c irp= new Input_Resumo_pricing__c(RecordTypeId = rt.id, valido_de__c = Date.today(),
valido_ate__c = Date.today());
insert irp;
RecordType rt2 = [select id from RecordType where name = 'Combustíveis não Compostos'];
Input_Resumo_pricing__c irp2= new Input_Resumo_pricing__c(RecordTypeId = rt2.id, valido_de__c = Date.today(),
valido_ate__c = Date.today());
insert irp2;
RecordType rt3 = [select id from RecordType where name = 'Pricing Manual'];
Input_Resumo_pricing__c irp3= new Input_Resumo_pricing__c(RecordTypeId = rt3.id, valido_de__c = Date.today(),
valido_ate__c = Date.today());
insert irp3;
//--------------------------------------------------------------
//-----------------------------------------------
}
}
Your query is not returning any records with name = 'DSL 10ppm CIF NWE AAWZC00'. Instead, you could insert a Product2 record and use it to assign your p variable:
It looks like that query on line 6 must not have any records in your production environment. Test this by running this query in Anonymous, and see how many results you get.
Beware of counting on particular data being there when you move between orgs. Whenever possible, I would suggest creating your data from scratch in your testmethod.
Jeremy
but the product is created in production and sandbox with the same name
Either run a quick report (or if you're using the force.com IDE, a SOQL query) to verify that your query contains the record.
I always try to create the test records myself to avoid running an extra query that is instance agnostic.
hum.. i have to do that..tks anyway