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
TN AdminTN Admin 

Need help sorting not working in lineitem trigger

trigger AS_OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert) {
   system.debug('trigger values'+;  
    String  oppoptyId = [ SELECT Id,Name,OpportunityId,PricebookEntryId,Product2Id FROM OpportunityLineItem where Id IN: limit 1].OpportunityId;
    system.debug('Opporutity id'+ oppoptyId);
      List<OpportunityLineItem> OPtyLineItemList = [select Id,Name,OpportunityId,PricebookEntryId,Product2Id,Contractual_Committed_Revenue__c FROM OpportunityLineItem Where OpportunityId =: oppoptyId];
      system.debug('lineitem list '+ OPtyLineItemList );
      opportunity opty =[Select product_1__C,product_2__C from Opportunity where ID =: oppoptyId];
        system.debug('opty list '+ opty.product_1__C);
        system.debug('opty list '+ opty.product_2__C );
      Map<Double,OpportunityLineItem> productAlignmentTOOpty = new  Map<Double,OpportunityLineItem>();
      List<Double> sortRevenue = new List<Double>(); 
         for(OpportunityLineItem Oli: OPtyLineItemList){
         system.debug('sortRevenue1 '+ sortRevenue );
         Integer count = 0;
          system.debug('sortRevenue2 '+ sortRevenue);
         for(Integer i=0 ;sortRevenue.Size()> count ; i++){
            if(count == 0 && sortRevenue[i] != null && productAlignmentTOOpty.get(sortRevenue[i]).Name != null){
              opty.product_1__C = productAlignmentTOOpty.get(sortRevenue[i]).Name;
             if(count == 1 && sortRevenue[i] != null  && productAlignmentTOOpty.get(sortRevenue[i]).Name != null){
              opty.product_2__C =productAlignmentTOOpty.get(sortRevenue[i]).Name;

            count = count +1;
         update opty;

I need to sort the values in asc from the field Contractual_Committed_Revenue__c and populate the lineitem names in opportunity fields (product_1__C,product_2__C).

Thanks in advance..
If i understood, you want to sort Contractual_Committed_Revenue__c field. Use the following query to get sorting field values.

[select Id,Name,Contractual_Committed_Revenue__c From OpportunityLineItem Where OpportunityId =: oppoptyId Order by  Contractual_Committed_Revenue__c];

Look into soql 'order by' keyword -