function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
maiyakumaiyaku 

Error List has no rows

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SumSodcSync: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.SumSodcSync: line 4, column 31: []

 

 

trigger SumSodcSync on Sales_Order_Complete__c(After insert) {
for(Sales_Order_Complete__c sodc:trigger.new){
      
        
       Sales_Order__c  Sod = [Select id from Sales_Order__c Where id = : 	    ApexPages.currentPage().getParameters().get('id')];        
        Sales_Order_Complete__c[] Scom = [Select id,OpportunitiesID__c ,DimensionTxWxL__c,Grade__c,Total_Weight__c,Quotes__c,
        Fail__c, Name, Products__c, Quantity__c,Quantity_Remain__c,Sales_OrderID__c,Success__c,Date__c,Pop__c,
        Sales_Order_Line_ItemID__c,Deliver_Remain__c,Delivery_Good_Pcs__c,Order_Quantity__c,Total_Finished_Good__c ,
        Delivery_Good_Ton__c,Delivery_Remain_Ton__c,Finished_Good_Remain__c,Finished_Good_Remain_Ton__c,Finished_Tons__c 
        from Sales_Order_Complete__c where Sales_OrderID__c =: sod.id And Pop__c != true ];
            
            Sodc_Sumary__c[] objssc = new Sodc_Sumary__c[]{};
            Sodc_Sumary__c Sc = new Sodc_Sumary__c();
      
                for(Sales_Order_Complete__c Ssc: Scom ){
                
                Sc = new Sodc_Sumary__c();
                Sc.Sales_Order__c = Ssc.Sales_OrderID__c;
                Sc.Dimen__c = Ssc.DimensionTxWxL__c;
                Sc.Grade__c = Ssc.Grade__c;
                Sc.Order_Status__c = Ssc.Id;
                Sc.Name = Ssc.Name;
                Sc.Finished_Good_Remain__c = Ssc.Finished_Good_Remain__c;
                Sc.Finished_Good_Remain_Ton__c = Ssc.Finished_Good_Remain_Ton__c;
                Sc.Deliver_Remain__c= Ssc.Deliver_Remain__c;
                Sc.Delivery_Remain_Ton__c = Ssc.Delivery_Remain_Ton__c;
                Sc.Quantity__c = Ssc.Order_Quantity__c;
                
                objssc.add(Sc); 
                }
                insert objssc; 
        
    }
}

Please guide me or sample

Thank you so much

 

kiranmutturukiranmutturu

in the trigger u are not supposed to use the apexpages.currentpages............this will not give u any result

maiyakumaiyaku

Thank you. But should I change from Apex.Current is what!

kiranmutturukiranmutturu

what u r doing in the trigger is not suggestable.. you are not supposed to write the query in the for loop and also the dml satements.. this will go to hit the governing limits.. use collections and work it out....

Ankit AroraAnkit Arora

I will not dip into your code to find where you can optimize your code, you can find many best practices. Now error is in this line

 

 

Sales_Order__c  Sod = [Select id from Sales_Order__c Where id = : 	    ApexPages.currentPage().getParameters().get('id')];

 Either initialize the Sales_Order__c first and then keep record fetched from query like this :

 

 

 

Sales_Order__c Sod = new Sales_Order__c() ;

 Or create a list of Sales_Order__c and perform next steps if the list size is greater than 0.

 

 

 

Thanks
Ankit Arora