You need to sign in to do that
Don't have an account?
shakila G
Rollup summary trigger formula field?
Hi All,
I have the Qline Item With Cross object Formula Field (Stock_Not_Available__c)
I want to rollup this field in quote object( No_of_Products_Stock_Not_Available__c)
My trigger Working working for add. Sum() Exam- 5
But if the count is reduced in Quote line item it's not revert backing in Quote Emaple 2
Result remain same in Quote as Exam; 5
I wrote a trigger :
trigger RollupProjectCountTrigger on QuoteLineItem (Before Insert, after insert) {
List<Id> VQuoteID = new List<Id>();
for(QuoteLineItem p: Trigger.new) {
VQuoteID.add(p.QuoteiD);
}
AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem
WHERE QuoteiD in :VQuoteID GROUP BY QuoteiD];
Map<id,Quote> QuoteMap = new Map<Id,Quote>([SELECT id, No_of_Products_Stock_Not_Available__c
FROM Quote WHERE Id in :VQuoteID]);
for(AggregateResult ar: groupedResults) {
QuoteMap.get((Id)ar.get('QuoteiD')).No_of_Products_Stock_Not_Available__c = (decimal) ar.get('lineItemCOunt');
}
try {
update QuoteMap.values();
} catch(DmlException e) {
System.debug(e.getMessage());
}
}
Kindly let me know where am doing mistake
I have the Qline Item With Cross object Formula Field (Stock_Not_Available__c)
I want to rollup this field in quote object( No_of_Products_Stock_Not_Available__c)
My trigger Working working for add. Sum() Exam- 5
But if the count is reduced in Quote line item it's not revert backing in Quote Emaple 2
Result remain same in Quote as Exam; 5
I wrote a trigger :
trigger RollupProjectCountTrigger on QuoteLineItem (Before Insert, after insert) {
List<Id> VQuoteID = new List<Id>();
for(QuoteLineItem p: Trigger.new) {
VQuoteID.add(p.QuoteiD);
}
AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem
WHERE QuoteiD in :VQuoteID GROUP BY QuoteiD];
Map<id,Quote> QuoteMap = new Map<Id,Quote>([SELECT id, No_of_Products_Stock_Not_Available__c
FROM Quote WHERE Id in :VQuoteID]);
for(AggregateResult ar: groupedResults) {
QuoteMap.get((Id)ar.get('QuoteiD')).No_of_Products_Stock_Not_Available__c = (decimal) ar.get('lineItemCOunt');
}
try {
update QuoteMap.values();
} catch(DmlException e) {
System.debug(e.getMessage());
}
}
Kindly let me know where am doing mistake
In your Trigger, you used the same event it is not possible.
you used (Before insert, after insert) it wrong change it by (Before insert, before update )
and try this code to rollup field in quote object( No_of_Products_Stock_Not_Available__c)
if you found this answer helpful then please mark it as best answer so it can help others.
Thanks
Akshay Dhiman
All Answers
Let me know If any error occur.
In your Trigger, you used the same event it is not possible.
you used (Before insert, after insert) it wrong change it by (Before insert, before update )
and try this code to rollup field in quote object( No_of_Products_Stock_Not_Available__c)
if you found this answer helpful then please mark it as best answer so it can help others.
Thanks
Akshay Dhiman