You need to sign in to do that
Don't have an account?
TN Admin
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..
Need help sorting not working in lineitem trigger
trigger AS_OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert) { system.debug('trigger values'+ trigger.new); String oppoptyId = [ SELECT Id,Name,OpportunityId,PricebookEntryId,Product2Id FROM OpportunityLineItem where Id IN: trigger.new 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){ productAlignmentTOOpty.put(oli.Contractual_Committed_Revenue__c,Oli); sortRevenue.add(oli.Contractual_Committed_Revenue__c); } system.debug('sortRevenue1 '+ sortRevenue ); sortRevenue.sort(); 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..
[select Id,Name,Contractual_Committed_Revenue__c From OpportunityLineItem Where OpportunityId =: oppoptyId Order by Contractual_Committed_Revenue__c];
Look into soql 'order by' keyword - http://www.crmsalesforcetraining.com/soql-order-by-clause-asc-desc/