You need to sign in to do that
Don't have an account?
AichaSF
Test Class Running - Error Exception 'System.QueryException: List has no rows for assignment to SObject'
Hello,
I created this class
and her test class:
I have this error when running test class:
Exception System.QueryException: List has no rows for assignment to SObject
I created this class
public class LNC01_Opp_Bonlivraison { @AuraEnabled public static String getAccountWeather(Id oppid) { try { //Recupetation Opportunity Id Opportunity opp = [SELECT id, AccountId, createddate, OwnerId, Traitement_Fiscal__c,Pricebook2Id FROM Opportunity WHERE Id=:oppid]; system.debug('oppid '+opp.id); //Recuperation de type de transaction Bon de livraison s2cor__Sage_INV_Trade_Document_Type__c typetransaction = [select id from s2cor__Sage_INV_Trade_Document_Type__c where name = :label.LNC_BonLivraison]; if (opp != null || Test.isRunningTest()) { //Creation Nouvelle transaction s2cor__Sage_INV_Trade_Document__c Newtransaction = new s2cor__Sage_INV_Trade_Document__c(); Date myDate = date.newinstance(opp.createddate.year(), opp.createddate.month(), opp.createddate.day()); Newtransaction.s2cor__Account__c= opp.AccountId; Newtransaction.Opportunite__c= oppid; Newtransaction.s2cor__Date__c= myDate; Newtransaction.OwnerId= opp.OwnerId; Newtransaction.s2cor__Tax_Treatment__c= opp.Traitement_Fiscal__c; Newtransaction.s2cor__Trade_Document_Type__c= typetransaction.id; Newtransaction.s2cor__Price_Book__c = opp.Pricebook2Id; insert Newtransaction; system.debug('Newtransaction '+Newtransaction.id); //Creation nouvelles lignes de transaction List<OpportunityLineItem> Opplineitem = [select id,Product2Id,Quantity,Dimension_Tag_Analytique__c,Dimension_Tag_budget__c,Dimension_Tag_BUDGET1__c,Dimension_Tag_BUDGET2__c from OpportunityLineItem where OpportunityId= :opp.id]; system.debug('Opplineitemsize '+Opplineitem.size()); id Product_Tag = NULL; list <s2cor__Sage_INV_Trade_Document_Item__c> listtransactionlinetoupdate = new list <s2cor__Sage_INV_Trade_Document_Item__c>(); for (OpportunityLineItem Opplineit : Opplineitem){ s2cor__Sage_INV_Trade_Document_Item__c transactionlinetoupdate = new s2cor__Sage_INV_Trade_Document_Item__c(); transactionlinetoupdate.s2cor__Trade_Document__c= Newtransaction.id; transactionlinetoupdate.s2cor__Product__c= Opplineit.Product2Id; transactionlinetoupdate.s2cor__Quantity__c = Opplineit.Quantity; listtransactionlinetoupdate.add(transactionlinetoupdate); } system.debug('listtransacsizetionlinetoupdate '+listtransactionlinetoupdate.size()); insert listtransactionlinetoupdate; } return '{"succes": "}'; }catch(Exception ex){ system.debug('Exception '+ex); return '{"error": "}'; } } }
and her test class:
@istest public class LNC01_Opp_Bonlivraison_Test { static testMethod void theTests(){ Opportunity Opp = new Opportunity(); Opp.name = 'testopp1'; Opp.StageName = '1 Pre-Qualified'; Opp.CloseDate= system.today(); Opp.AccountId = '001D0000024cW2MIAU'; insert Opp; LNC01_Opp_Bonlivraison.getAccountWeather(Opp.id); } }
I have this error when running test class:
Exception System.QueryException: List has no rows for assignment to SObject
Can you give youe Cridentials
Thank you for you're response.
But I can't understand you.
I changed test class like this :
I have 58% of coverage and this error in log:
|Exception System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Attempt to de-reference a null object: []
Thank you.