• boliset kumar
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Helo,

I am trying to log the exceptions in an custom object ,but after throwing an exception entire transaction is rolled back and i am not able to see in the custom objecy any help would be if great help  for example 

List<IBA_Store_Log__c> ibaLogs = New List<IBA_Store_Log__c>(); 
try {
    integer x = 1/0;
} catch (exception e) {
     IBA_Store_Log__c priceLog = IBA_store_datatableHelper.createIbaLog('ERROR', e.getmessage() + e.getlinenumber(), 'Iba_Store_Sap_Simulation', '');
     ibalogs.add(priceLog);    
    throw e;
}finally {
    IBA_store_datatableHelper.createIbaStoreLog(ibalogs);
}
 
Scenario:Trigger to be written when a new leave request created is approved.
When the Approval process incurs and leave is approved, the Leave status field is changed to Approved.

Criteria : Trigger should work when the 'Approval status' field on Leaves object changes its picklist value to 'APPROVED'
Action : Total Available Leaves = Total Available leaves - Requested Days Off
Trigger:
trigger LeavesTrigger on Leaves__c (after update) {
  TriggerHandlerLeave handler = new TriggerHandlerLeave();  
   handler.onAfterInsert();
}

Handler Class
public with sharing class TriggerHandlerLeave {
 public void onAfterInsert(){
    totalLeave();
  }
Map<Id, Leaves__c> merMap = new Map<Id, Leaves__c>([Select Id, Name,Approval_Status__c,
                                                     Total_Available_Leave__c,
                                                     Req_Days_Off__c 
                                                     From Leaves__c]);
public void totalLeave(){ 
 for(Leaves__c approvedList:Trigger.New){
 if(approvedList.Approval_Status__c =='Approved'){               
 merMap.get(approvedList.Leaves__c).Total_Available_Leave__c=merMap.get(approvedList.Leaves__c).Total_Available_Leave__c - merMap.get(approvedList.Leaves__c).Req_Days_Off__c;
 
       }
}      
update merMap.values();
}
}
  • April 07, 2020
  • Like
  • 0
Helo,

I am trying to log the exceptions in an custom object ,but after throwing an exception entire transaction is rolled back and i am not able to see in the custom objecy any help would be if great help  for example 

List<IBA_Store_Log__c> ibaLogs = New List<IBA_Store_Log__c>(); 
try {
    integer x = 1/0;
} catch (exception e) {
     IBA_Store_Log__c priceLog = IBA_store_datatableHelper.createIbaLog('ERROR', e.getmessage() + e.getlinenumber(), 'Iba_Store_Sap_Simulation', '');
     ibalogs.add(priceLog);    
    throw e;
}finally {
    IBA_store_datatableHelper.createIbaStoreLog(ibalogs);
}