• Sohel Shaikh 23
  • NEWBIE
  • 10 Points
  • Member since 2016
  • Infosys

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 9
    Replies
Hi All,
Could you please tell , how can I export 0.2 records from salesforce?
Thanks 
Sohel
Hi,

Could anyone please help me.
Following is th exception that I am getting while updating the account trigger.

Log file: 
27.0 APEX_CODE,DEBUG;APEX_PROFILING,NONE;CALLOUT,NONE;DB,NONE;SYSTEM,DEBUG;VALIDATION,NONE;VISUALFORCE,NONE;WORKFLOW,NONE
11:14:49.0 (92554)|USER_INFO|[EXTERNAL]|005M000000780NK|sshaikh4@hersheys.com.patrosbx|Eastern Standard Time|GMT-04:00
11:14:49.0 (124064)|EXECUTION_STARTED
11:14:49.0 (129676)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
11:14:49.0 (168779)|CODE_UNIT_STARTED|[EXTERNAL]|01qE0000000RA3U|Account on Account trigger event BeforeUpdate for [001M000000uArdV]
11:14:49.0 (12522863)|USER_DEBUG|[23]|DEBUG|Passed to NextCycleCall Check
11:14:49.0 (32794956)|USER_DEBUG|[243]|INFO|PCF is K,L,M
11:14:49.0 (64116567)|USER_DEBUG|[263]|INFO|6 week schedules : (Schedule__c:{Id=a0JM0000007bu5qMAA, Store__c=001M000000uArdVIAS, Week__c=1, Route__c=a0HM0000009NcpcMAC})
11:14:49.0 (82886881)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Schedule:a0JM0000007bu5q
11:14:49.0 (83155306)|CODE_UNIT_FINISHED|Validation:Schedule:a0JM0000007bu5q
11:14:49.0 (99018995)|CODE_UNIT_STARTED|[EXTERNAL]|01qE0000000RQ44|Schedule on Schedule trigger event AfterUpdate for [a0JM0000007bu5q]
11:14:49.0 (99255142)|USER_DEBUG|[2]|INFO|Inside Schedule trigger
11:14:49.0 (101371761)|USER_DEBUG|[11]|INFO|Before calling updateCallsForSchedule
11:14:49.0 (101437932)|USER_DEBUG|[12]|INFO|Inside updateCallsForSchedule
11:14:49.0 (101604306)|USER_DEBUG|[17]|DEBUG|before updatedSchedule for loop
11:14:49.0 (101643446)|USER_DEBUG|[20]|INFO|Inside updatedSchedule for loop
11:14:49.0 (101756621)|USER_DEBUG|[22]|INFO|inside updatedSchedule for loop IF block
11:14:49.0 (101796873)|USER_DEBUG|[30]|INFO|inside matchingUpdatedScheduleIds if block
11:14:49.0 (130390406)|USER_DEBUG|[36]|INFO|Inside setDayWorked
11:14:49.0 (130641629)|USER_DEBUG|[88]|INFO|Exiting setDayWorked
11:14:49.0 (130660740)|USER_DEBUG|[20]|INFO|Inside call trigger
11:14:49.0 (132014008)|CODE_UNIT_FINISHED|Call on Call trigger event BeforeUpdate for [a05M000000ACqIA]
11:14:49.0 (150565069)|CODE_UNIT_STARTED|[EXTERNAL]|01qE0000000RA3W|Call on Call trigger event AfterUpdate for [a05M000000ACqIA]
11:14:49.0 (150683462)|USER_DEBUG|[2]|INFO|Inside call trigger
11:14:49.0 (150781141)|USER_DEBUG|[10]|INFO|call trigger isupdate
11:14:49.0 (151547560)|USER_DEBUG|[28]|INFO|Inside Commit_toschedule.updateSchedule
11:14:49.0 (194764302)|USER_DEBUG|[66]|INFO|Exiting Commit_toschedule.updateSchedule
11:14:49.0 (194883644)|USER_DEBUG|[97]|INFO|Inside ChangedDayWorked
11:14:49.0 (195092608)|USER_DEBUG|[133]|INFO|Exiting ChangedDayWorked
11:14:49.0 (195134209)|USER_DEBUG|[4]|INFO|Inside setRouteFlag
11:14:49.0 (199473981)|USER_DEBUG|[9]|DEBUG|Inside call for loop
11:14:49.0 (199572820)|USER_DEBUG|[14]|DEBUG|scheduleMap is ...{}
11:14:49.0 (199604263)|USER_DEBUG|[27]|INFO|Exiting setRouteFlag
11:14:49.0 (199647455)|USER_DEBUG|[161]|INFO|Inside setAssignedTo
11:14:49.0 (202655426)|USER_DEBUG|[179]|INFO|Exiting setAssignedTo
11:14:49.0 (202675533)|USER_DEBUG|[20]|INFO|Inside call trigger
11:14:49.0 (203908101)|CODE_UNIT_FINISHED|Call on Call trigger event AfterUpdate for [a05M000000ACqIA]
11:14:49.0 (204023305)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:01IE00000011EwM
11:14:49.0 (219301160)|CODE_UNIT_FINISHED|Workflow:01IE00000011EwM
11:14:49.0 (224700936)|EXCEPTION_THROWN|[69]|System.DmlException: Update failed. First exception on row 0 with id a05M000000ACqIAIA1; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001M000000uArdV) is currently in trigger Account, therefore it cannot recursively update itself: []
11:14:49.0 (225316140)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id a05M000000ACqIAIA1; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001M000000uArdV) is currently in trigger Account, therefore it cannot recursively update itself: []

Class.ScheduleTrigger.updateCallsForSchedule: line 69, column 1
Trigger.Schedule: line 12, column 1
11:14:49.0 (225335203)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id a05M000000ACqIAIA1; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001M000000uArdV) is currently in trigger Account, therefore it cannot recursively update itself: []

Class.ScheduleTrigger.updateCallsForSchedule: line 69, column 1
Trigger.Schedule: line 12, column 1
11:14:49.0 (226521922)|CODE_UNIT_FINISHED|Schedule on Schedule trigger event AfterUpdate for [a0JM0000007bu5q]
 
Requirement:
I want to check if my mailbox has received an email from specific sender and read the excel sheet attached to it and use the data in excel sheet in my apex code.
Is it possible to read an email from mailbox and also get the contents of attachment using apex?
My requirement:
To poll the mailbox and check if specific email comes in mailbox and read the excel sheet attached to it.
System.URL.getSalesforceBaseUrl() was not working yesterday night.
But when I executed the statement again next day it worked.
It seems salesforce is unpredictable sometimes. 
Want to know why this had happened?
Scenario :
I have an Account object and Schedule__c object.
I want to update account and Schedule__c objects' fields on update before trigger.
When I update Account in Batch class called by Account trigger I am getting following exception:
Update failed. CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
When I remove update accoount; statement from the execute() function of batch class it is not reflecting the changes made in account object as it does automatically in Account trigger.

PLease let me know if anyone has the solution.

Thanks,
Sohel
Here two objects are used.Account and Schedule__c.
The main block's code is called by before trigger on account.
Trigger is on Account object.
It is not allowing me to update the Schedule__c object .

Please let me know why this error is encountered.


Error : 
Error:Apex trigger Account caused an unexpected exception, contact your administrator: Account: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0JM0000007bp55MAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Schedule: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a05M000000ACmimIAD; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001M000000uSEuz) is currently in trigger Account, therefore it cannot recursively update itself: [] Class.ScheduleTrigger.updateCallsForSchedule: line 63, column 1 Trigger.Schedule: line 11, column 1: []: Class.AccountTrigger.NextCallCycleCheck: line 248, column 1

Main Block :
system.debug('Inside 6week block ');
                 a.REX_Call__c=false;
                 boolean acctNextCycle = a.Next_Cycle_Call__c;
                 List<Schedule__c> wk6Schedules = new list<Schedule__c>();

                 if(a.Priority_Cycle_Frequency__c == 'K: 6 Week Cycles: Weeks 1-2' || a.Priority_Cycle_Frequency__c == 'L: 6 Week Cycles: Weeks 3-4' || a.Priority_Cycle_Frequency__c == 'M: 6 Week Cycles: Weeks 5-6'){
                        system.debug('Inside 6week if block ');
                     for(Schedule__c schedule : [SELECT Id,Store__c,Week__c FROM Schedule__c WHERE Active__c = 'Y' AND Status__c = 'Active' AND Route__r.Status__c = 'Active' AND Store__r.Active__c = 'Y'  AND Store__c =: a.Id]){
                           system.debug('Inside schedule for loop ');
                        if (schedule.Week__c == 1 || schedule.Week__c == 2){
                               system.debug('Inside if block of week 1 and 2 ');
                            if (!acctNextCycle){
                                   system.debug('Inside nextcall true ');
                                reverseAcctNextCycleCall(a);
                            }else{
                                system.debug('Inside nextcall false ');
                                wk6Schedules.add(update6wkSchedule(schedule));
                            }
                        }else if (schedule.Week__c == 3 || schedule.Week__c == 4){
                            system.debug('Inside if block of week 3 and 4 ');
                            reverseAcctNextCycleCall(a);
                            wk6Schedules.add(update6wkSchedule(schedule));
                        }    
                     }
                     System.debug('all schedules to update are ...'+ wk6schedules);   
                     if (wk6Schedules.size() > 0) {
                         database.update(wk6Schedules);
                     }

Functions used in main block :
public static Account reverseAcctNextCycleCall(Account account){
         system.debug('Inside reverseAcctNextCycleCall ');
      Account schedAcct = new Account();
      schedAcct = account;
      if (schedAcct.Next_Cycle_Call__c){
        schedAcct.Next_Cycle_Call__c = false;
      }else{
        schedAcct.Next_Cycle_Call__c = true;
      }
        system.debug('New next cycle call :'+schedAcct.Next_Cycle_Call__c);
        system.debug('Exiting reverseAcctNextCycleCall');
      
      return schedAcct;
    }
    
    public static Schedule__c update6wkSchedule(Schedule__c sched){
    // if wk=1or2, +2 , if wk=3or4, -2
    system.debug('inside update6wkSchedule');
    Schedule__c schedule = sched;
    Decimal existingWk = schedule.Week__c;
    system.debug('Existing week : '+existingWk);
    Decimal newWk = 0;
    if (existingWk == 1 || existingWk == 2){
         newWk = existingWk + 2;
    }else if (existingWk == 3 || existingWk == 4){
         newWk = existingWk - 2;
    }else{
         return schedule;
    }
    schedule.Week__c = newWk;
        system.debug('New week : '+newWk+'schedule.Week__c : '+schedule.Week__c);
    return schedule;
  }


 
Here two objects are used.Account and Schedule__c.
The main block's code is called by before trigger on account.
Trigger is on Account object.
It is not allowing me to update the Schedule__c object .

Please let me know why this error is encountered.


Error : 
Error:Apex trigger Account caused an unexpected exception, contact your administrator: Account: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0JM0000007bp55MAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Schedule: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a05M000000ACmimIAD; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001M000000uSEuz) is currently in trigger Account, therefore it cannot recursively update itself: [] Class.ScheduleTrigger.updateCallsForSchedule: line 63, column 1 Trigger.Schedule: line 11, column 1: []: Class.AccountTrigger.NextCallCycleCheck: line 248, column 1

Main Block :
system.debug('Inside 6week block ');
                 a.REX_Call__c=false;
                 boolean acctNextCycle = a.Next_Cycle_Call__c;
                 List<Schedule__c> wk6Schedules = new list<Schedule__c>();

                 if(a.Priority_Cycle_Frequency__c == 'K: 6 Week Cycles: Weeks 1-2' || a.Priority_Cycle_Frequency__c == 'L: 6 Week Cycles: Weeks 3-4' || a.Priority_Cycle_Frequency__c == 'M: 6 Week Cycles: Weeks 5-6'){
                        system.debug('Inside 6week if block ');
                     for(Schedule__c schedule : [SELECT Id,Store__c,Week__c FROM Schedule__c WHERE Active__c = 'Y' AND Status__c = 'Active' AND Route__r.Status__c = 'Active' AND Store__r.Active__c = 'Y'  AND Store__c =: a.Id]){
                           system.debug('Inside schedule for loop ');
                        if (schedule.Week__c == 1 || schedule.Week__c == 2){
                               system.debug('Inside if block of week 1 and 2 ');
                            if (!acctNextCycle){
                                   system.debug('Inside nextcall true ');
                                reverseAcctNextCycleCall(a);
                            }else{
                                system.debug('Inside nextcall false ');
                                wk6Schedules.add(update6wkSchedule(schedule));
                            }
                        }else if (schedule.Week__c == 3 || schedule.Week__c == 4){
                            system.debug('Inside if block of week 3 and 4 ');
                            reverseAcctNextCycleCall(a);
                            wk6Schedules.add(update6wkSchedule(schedule));
                        }    
                     }
                     System.debug('all schedules to update are ...'+ wk6schedules);   
                     if (wk6Schedules.size() > 0) {
                         database.update(wk6Schedules);
                     }

Functions used in main block :
public static Account reverseAcctNextCycleCall(Account account){
         system.debug('Inside reverseAcctNextCycleCall ');
      Account schedAcct = new Account();
      schedAcct = account;
      if (schedAcct.Next_Cycle_Call__c){
        schedAcct.Next_Cycle_Call__c = false;
      }else{
        schedAcct.Next_Cycle_Call__c = true;
      }
        system.debug('New next cycle call :'+schedAcct.Next_Cycle_Call__c);
        system.debug('Exiting reverseAcctNextCycleCall');
      
      return schedAcct;
    }
    
    public static Schedule__c update6wkSchedule(Schedule__c sched){
    // if wk=1or2, +2 , if wk=3or4, -2
    system.debug('inside update6wkSchedule');
    Schedule__c schedule = sched;
    Decimal existingWk = schedule.Week__c;
    system.debug('Existing week : '+existingWk);
    Decimal newWk = 0;
    if (existingWk == 1 || existingWk == 2){
         newWk = existingWk + 2;
    }else if (existingWk == 3 || existingWk == 4){
         newWk = existingWk - 2;
    }else{
         return schedule;
    }
    schedule.Week__c = newWk;
        system.debug('New week : '+newWk+'schedule.Week__c : '+schedule.Week__c);
    return schedule;
  }