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

Average Trigger Code Be Low

Average Code Low . I can update Average Code?



trigger SumSodcSync on Sales_Order_Complete__c(Before insert) {
        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 ,
        from Sales_Order_Complete__c where Sales_OrderID__c  =: 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;
                insert objssc; 



private class TestSumSodcSync {
 static testMethod void myUnitTest() {    
                Account Acc = New Account(Name = 'test',Type='Partner');
                insert Acc;
                Opportunities__c Opp = new Opportunities__c(Account_Name__c = Acc.ID,Stage__c = 'Negotiation',Probability__c ='60%',Unit__c ='Ton');
                insert Opp;
                Opportunities_Line_Item__c OppL = new Opportunities_Line_Item__c(OpportunitiesID__c =;
                insert OppL;
                Quotes__c N = new Quotes__c(,Account_Name__c =;
                insert N;    
                Quotes_Line_Item__c QL = new Quotes_Line_Item__c(QuotesID__c =,Opportunities_Line_Item__c =;
                insert QL;
                Sales_Order__c Sod = new Sales_Order__c(Quotes__c =;
                insert Sod;
                Sales_Order_Line_Item__c SoL = new Sales_Order_Line_Item__c(Sales_OrderID__c =;
                insert SoL;
                Sales_Order_Complete__c Sodc = new Sales_Order_Complete__c(Sales_OrderID__c =,OpportunitiesID__c =,Quotes__c =,Sales_Order_Line_ItemID__c =;
                insert Sodc;
                Sodc_Sumary__c Sos = new Sodc_Sumary__c(Order_Status__c =,Sales_Order__c =;
                insert Sos;



Thank you so much.




It's probably low because you aren't replicating the currentPage, which you are using in your first select.  You can see some code samples here:


That said, I'm not sure I'd recommend have a reference to CurrentPage() being the basis for a trigger, since it will fail if the data is being accessed in any other way, such as how your unit test is doing so.  I believe you'll get an error back on the second SOQL in this case.


Also, I'd suggest moving the DML statement out of your initial for loop, as it could easily hit a governor limit if multiple records are inserted at once.