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
Vadivel MuruganVadivel Murugan 

Recursive error in triger

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger VisitTriggers caused an unexpected exception, contact your administrator: VisitTriggers: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0Cf0000007rjNsEAI; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0Cf0000007rjNs) is currently in trigger VisitTriggers, therefore it cannot recursively update itself: []: Class.VisitTriggerHandler.OrderRaisedVisitUpdate: line 255, column 1

for this code

 Private void OrderRaisedVisitUpdate(Map<id,Visits__c> visitsMap)
        Id visitid;
        List<Visits__c> visit = visitsMap.values();
        //public String visitId;
        //Visits__c visit=[select id,Order_Raised__c from Visits__c where id=:visitid];
        Visits__c vt=[select id,Order_Raised__c from Visits__c where id =: visit[0].id ];
        for(AggregateResult result :[select Visit__c,sum(Total_Amount__c) total from SFDC_Purchase_Order__c where Visit__c =:visit[0].id group by Visit__c]){
          vt.Order_Raised__c =tot;
          update vt; // get error this update field

I have create two object for visit and SFDC_supplier_purchase_Order. when purchase order raised in SFDC_supplier_purchase_Order at that time get total amount and add into the visit field purchase order raised. When purchase order rasie, repeatley do this.

Vadivel - try using a rollup summary instead.

Please remove update vt; statement from the end. I think it solves your problem.