You need to sign in to do that
Don't have an account?
Vagner Andrade
How to create a roll-up field with criteria?
Hi,
I need to create a custom field on opportunity that shows the amount of all opportunities with the same CloseDate month and year.
I've tried a trigger, but i'm geting this error "SELF_REFERENCE_FROM_TRIGGER". I can't update the field of the record that fires the trigger.
How can I reach this?
Trigger:
I need to create a custom field on opportunity that shows the amount of all opportunities with the same CloseDate month and year.
I've tried a trigger, but i'm geting this error "SELF_REFERENCE_FROM_TRIGGER". I can't update the field of the record that fires the trigger.
How can I reach this?
Trigger:
trigger calculateTotalAmount on Opportunity(after update, after insert) { double totalAmount; date firstDayReference; date lastDayReference; Integer daysInMonth; If(Trigger.IsInsert || Trigger.IsUpdate) { For(Opportunity opp: Trigger.New) { daysInMonth = Date.daysInMonth(opp.CloseDate.year(), opp.CloseDate.month()); firstDayReference = date.newinstance(opp.CloseDate.year(), opp.CloseDate.month(), 1); lastDayReference = date.newinstance(opp.CloseDate.year(), opp.CloseDate.month(), daysInMonth); List < Opportunity > Oppor = [SELECT ID, Name, CloseDate, Amount FROM Opportunity WHERE CloseDate >=: firstDayReference AND CloseDate <=: lastDayReference AND StageName = 'Closed Won' ]; For(Opportunity o: Oppor) { totalAmount = totalAmount + o.Amount; } For(Opportunity o: Oppor) { o.total_amount__c = totalAmount; } update Oppor; } } }
https://help.salesforce.com/articleView?id=000005278&type=1
http://force-salesforce.blogspot.com/2012/06/controlling-recursive-triggers.html
All Answers
https://help.salesforce.com/articleView?id=000005278&type=1
http://force-salesforce.blogspot.com/2012/06/controlling-recursive-triggers.html