• Thayalan Guhathashan 11
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Hi , I have this handler methods on after update trigger, why do I get CPU time limit exceed exception


trigger AccountTrigger on Account (before update, after insert, after update ) 
{
   
    if( AccountTriggerHandler.runFlag )
      {
        AccountTriggerHandler.runFlag = false;
       
        if( Trigger.isUpdate && Trigger.isAfter )
        {
            AccountTriggerHandler.handleAfterUpdate( Trigger.newMap, Trigger.oldMap );
            AccountTriggerHandler.forceSync(Trigger.new,Trigger.oldMap);
            
        }
        
        AccountTriggerHandler.runFlag = true;
    }

}










public class AccountTriggerHandler 
{
    public static boolean runFlag = true;
    
     public static void  forceSync(List<Account> acc, Map<id,Account> oldaccounts)
     {
        Set<Id> accIds = new Set<Id>();
        MAP<Id,Guarantor__c> guarantorMap = new MAP<Id,Guarantor__c>();
        List<Security_Holder__c> sclisttoUpdate= new List<Security_Holder__c>();
        List<Certificate__c> certlisttoUpdate= new List<Certificate__c>();
        
 
         
        for ( Account a:acc )
         {
           Account oldAcc = oldaccounts.get(a.Id);
           if((a.Last_Updated_Date_Non_Integration_User__c != null) && (a.lastmodifieddate != oldAcc.lastmodifieddate)) 
           {
             accIds.add(a.id);
            } 
         }
         
        if(accIds.size()> 0) 
        {
        for (Account accs: [
             select id,
             (SELECT id,Force_Sync__c FROM Guarantors__r),  (SELECT id,Force_Sync__c FROM GuaranteeProviders__r) , (SELECT id,Force_Sync__c FROM Certificates__r), (SELECT id,Force_Sync__c FROM Security_Holders__r)
             from Account 
             where (Id in :accIds )]) {
           
            if(accs.Guarantors__r.size() > 0)
            {
            for(Guarantor__c gc:accs.Guarantors__r)
            { gc.Force_Sync__c = true;
              guarantorMap.put(gc.id,  gc);
            }
            }
        
           if(accs.GuaranteeProviders__r.size() > 0)
            {
            for(Guarantor__c gcs:accs.GuaranteeProviders__r)
            { gcs.Force_Sync__c = true;
              guarantorMap.put(gcs.id,  gcs);
            }
            }
             
            if(accs.Security_Holders__r.size() > 0)
            {   
              for(Security_Holder__c sc:accs.Security_Holders__r)
            { sc.Force_Sync__c = true;
              sclisttoUpdate.add(sc);
            }
            }
             
              if(accs.Certificates__r.size() > 0)
            { 
             for(Certificate__c cr:accs.Certificates__r)
            { cr.Force_Sync__c = true;
              certlisttoUpdate.add(cr);
            } 
            }
         }
        }
        if (!guarantorMap.isEmpty()) {
             Database.update(guarantorMap.values(), false);
           }
            
             
            
        if (!sclisttoUpdate.isEmpty()) {
            Database.update(sclisttoUpdate, false); 
           } 
         
         if (!certlisttoUpdate.isEmpty()) {
            Database.update(certlisttoUpdate, false); 
        }  
    }  
    
   
  
  // Thayalan finish
    public static void handleAfterInsert( List<Account> insertedAccounts )
    {
        updateNonIntegrationAuditFields( insertedAccounts );
    }
    
    public static void handleAfterUpdate( Map<Id, Account> updatedAccounts, Map<Id, Account> oldAccounts )
    {
        updateNonIntegrationAuditFields( updatedAccounts.values() );
        updatePendingApplicationFields( updatedAccounts , oldAccounts);
    }
    
    private static void updateNonIntegrationAuditFields( List<Account> accounts )
    {
        Set<Id> userIds = new Set<Id>();
        for( Account a: accounts )
        {
            userIds.add( a.LastModifiedById );
        }
        
        Map<ID, User> users = new Map<Id, User>([Select Id, Integration_User__c from User
                           where id in: userIds
                           and Integration_User__c = false]);
        
        List<Account> accountsToUpdate = new List<Account>();
        for( Account a: accounts )
        {
            if( users.containsKey( a.LastModifiedById ) )
            {
                Account b = new Account( Id=a.Id );
                b.Last_Updated_by_Non_Integration_User__c = a.LastModifiedDate;
                b.Last_Updated_Date_Non_Integration_User__c = a.LastModifiedById;
                accountsToUpdate.add(b);
            }        
        }
        
        if( accountsToUpdate.size() > 0 )
        {
            update accountsToUpdate;
        }

    }
}
Is there any way to capture newly assigned apporver through 'Reassign'.  we have an apporvalprocess in Opporunity object and a picklist field of names Approvers. when an apporver reassigns, we want new apporver's name to be slected from the picklist.
is it possible through flow or code?
 
Hi ,

Partner community users are unbale to see the approver comments on the detail vew of Process Instance Step Layout.

They can see the approver comments on the list view of Approval History, but when they get into  Process Instance Step detail view they can not see the comments but they can see other fields.

How to make the comments visbile on the dteil view?
Hi there,
The code works for normal scenario with single lead, but the code does not support bulkifying. When Multiple leads try to convert same time, I am getting a "System.LimitException: Too many SOQL queries" error.

trigger LeadIntegrationTrigger on Lead (after update, after insert)
{
    
    List<String> LeadNames = new List<String>{};
    Set<ID> Oppid =new Set<ID>();
    List<Contact>lcon = New List<Contact>();
    List<OpportunityLineItem> ListLine = New List<OpportunityLineItem>();
    List<Opportunity> OppList = New List<Opportunity>();
    
 
    if (Trigger.isInsert) {
        for(Lead aLead: Trigger.new){
          
                if((aLead.isconverted==false) && (aLead.Status == 'Qualified - Enrolled')) {
                    Database.LeadConvert lc = new database.LeadConvert();
                    lc.setLeadId(aLead.Id);
                    lc.convertedStatus = 'Qualified - Enrolled';
                    lc.setDoNotCreateOpportunity(false);
                    Database.LeadConvertResult lcr = Database.convertLead(lc);
                    System.assert(lcr.isSuccess());
                    //aLead.IsConverted=false;
                }
                 
        }
    
    }
    
    if (Trigger.isUpdate ) {
        List<OpportunityStudent__c> aNewStudents = new List<OpportunityStudent__c>();
        Map<Id, Lead> aLeadToCheck = new Map<Id, Lead>();
        for(Integer x = 0; x < Trigger.new.size(); x++)
            {        
                    if((Trigger.new[x].isconverted==false) && (Trigger.new[x].Status == 'Qualified - Enrolled'&&Trigger.new[x].Status!=Trigger.old[x].Status)) {
                    Database.LeadConvert lc = new database.LeadConvert();
                    lc.setLeadId(Trigger.new[x].Id);
                    lc.convertedStatus = 'Qualified - Enrolled';
                    lc.setDoNotCreateOpportunity(false);
                    Database.LeadConvertResult lcr = Database.convertLead(lc);
                    System.assert(lcr.isSuccess());
                   }
        
        
            if (Trigger.new[x].IsConverted == true && Trigger.oldMap.get(Trigger.new[x].Id).IsConverted == false&& Trigger.new[x].ConvertedOpportunityId != null && Trigger.new[x].ConvertedContactId != null){  
                aLeadToCheck.put(Trigger.new[x].ConvertedOpportunityId, Trigger.new[x]);
            }
        }
         
        //Auto add student on Opportuntiy
        List<Opportunity> anOppList = [SELECT Id, AccountId, Account.Name,account.recordtype.name FROM Opportunity WHERE Id IN :aLeadToCheck.keySet()];
        
        for (Opportunity anOpp: anOppList){
        
           if (anOpp.AccountId != null){
                Lead aLead = aLeadToCheck.get(anOpp.Id);
                //update Opportunity Detail
               
                anOpp.Training_Program__c=aLead.Product__c;
                OppList.add(anOpp);
                //
                Contact con=[SELECT id,Avetmiss_At_School__c,Contact_Method__c,Avetmiss_Country_Of_Birth__c,
                Avetmiss_Disability__c,Avetmiss_Disability_List__c,Gender__c,Avetmiss_Highest_School_Level__c,
                Avetmiss_Indigenous_Status__c,Avetmiss_Labour_Force_Status__c,Avetmiss_Learner_Unique_Identifier__c,
                Avetmiss_Main_Language__c,Avetmiss_Nationality__c,Avetmiss_Prior_Education__c,Prior_Education__c,Avetmiss_Prior_Education_List__c,
                Avetmiss_School_Identifier__c,Avetmiss_Spoken_English_Proefficiency__c,Avetmiss_Year_Highest_School_Level__c,BirthDate
                FROM contact WHERE id=:aLead.ConvertedContactId];
                system.debug('Cloning');
                //Clone data to personAccount
                con.Avetmiss_At_School__c=aLead.Avetmiss_At_School__c;
               
                               
            
                con.Avetmiss_Year_Highest_School_Level__c = aLead.Avetmiss_Year_Highest_School_Level__c;
                lcon.add(con);
                // end clone data
                
                //Add New PricebookEntry
                if(aLead.Product__c!=null){
                    PricebookEntry Pricebook=[SELECT id FROM PricebookEntry WHERE Product2Id=:aLead.Product__c Limit 1];
                  
                }                    
                OpportunityStudent__c aNewStudent = new OpportunityStudent__c();
                aNewStudent.Contact__c = aLead.ConvertedContactId;
                aNewStudent.Opportunity__c = aLead.ConvertedOpportunityId;                                          
                Oppid.add(aNewStudent.Opportunity__c);
                aNewStudents.add(aNewStudent);
                system.debug('@@@@@ CCCC');
            }
            else{
                Oppid.add(anOpp.id);
            }
        }
        
        //Prevent Duplicate Manage student [Person Acccount]
        try{
            List <OpportunityContactRole> Role=[SELECT id,opportunityid FROM OpportunityContactRole WHERE Opportunityid in : Oppid];
            delete Role;
        }
        catch(System.QueryException e){}
        
        insert aNewStudents;
        //insert ListLine;
        update OppList;
        Update lcon;   
        List<OpportunityStudent__c> ListStudent=[SELECT id,Opportunity__c,Contact__c FROM OpportunityStudent__c WHERE Opportunity__c in:Oppid];
        IF(ListStudent.size()>1){
            delete ListStudent[1];
        }    
    }
}
Hi All,

I have the follwing code makes a long blank page on IE11 and it works fien on other browsers, including Firebox nad chrome. Could you please advise on how to fix & which tag makes the the problem on IE

 <h4 class="row heading"><u>2. Course Detail </u></h4>
                        </div>
    
                        <div class="article">
                        <p>Please select one of the below courses that your school is contracted to deliever</p>
                        </div>
                         <div class="article" >
                        <!-- <apex:inputhidden value="{!objEnrolmentForm.aipt_Course_Start_Date__c}"  id="Start_Date"   />-->
                        
                         <apex:inputText value="{!strSelectedcourse}" id="ID_course" onblur="checkFieldValidation(this.id);"  style="display:none;"  rendered="{!if(objEnrolmentForm.aipt_Product__c!=null,false,true)}"  styleClass="isrequired " />
                          <span class="errorMsg">{!$Label.AIPT_isCourseSelected}</span>
                        </div>
                         <apex:actionregion >
                  <apex:actionFunction name="abc" action="{!checkSelectedValue}" status="idstatus" reRender="InPannel">
                    <apex:param name="abc" value="" assignTo="{!IdSelectvalue}"/>
                  </apex:actionFunction>
                  
                  
                   <apex:actionFunction name="getYear" action="{!calculateEnddate}" status="idstatus1" reRender="endDateId">
                    <apex:param name="getYear" value="" assignTo="{!SelectedyearfromPage}"/>
                  </apex:actionFunction>
                  
                  
                  <apex:actionFunction name="getDate" action="{!calculateEnddate}" status="idstatus2" reRender="endDateId">
                    <apex:param name="getDate" value="" assignTo="{!strSelectedStartDate}"/>
                  </apex:actionFunction>  
                  
                   <apex:actionFunction name="getIntakeName" action="{!displayStartDate}" status="idstatus3" reRender="Start_Date">
                    <apex:param name="getIntakeName" value="" assignTo="{!intakeName}"/>
                  </apex:actionFunction>
                  
                        
                        <div id="no-more-tables">
                        <table class="col-md-12 table-bordered table-condensed2 cf">
                        <thead class="cf">
                        <tr>
                        <th class="numeric">Course Code</th>
                        <th class="numeric">Course Name</th>
                        <th class="numeric">Delivery Method</th>
                        <th class="numeric">Course Cost</th>
                        <th class="numeric">&nbsp;</th>
                        </tr>
                        </thead>

            
Hi , I have this handler methods on after update trigger, why do I get CPU time limit exceed exception


trigger AccountTrigger on Account (before update, after insert, after update ) 
{
   
    if( AccountTriggerHandler.runFlag )
      {
        AccountTriggerHandler.runFlag = false;
       
        if( Trigger.isUpdate && Trigger.isAfter )
        {
            AccountTriggerHandler.handleAfterUpdate( Trigger.newMap, Trigger.oldMap );
            AccountTriggerHandler.forceSync(Trigger.new,Trigger.oldMap);
            
        }
        
        AccountTriggerHandler.runFlag = true;
    }

}










public class AccountTriggerHandler 
{
    public static boolean runFlag = true;
    
     public static void  forceSync(List<Account> acc, Map<id,Account> oldaccounts)
     {
        Set<Id> accIds = new Set<Id>();
        MAP<Id,Guarantor__c> guarantorMap = new MAP<Id,Guarantor__c>();
        List<Security_Holder__c> sclisttoUpdate= new List<Security_Holder__c>();
        List<Certificate__c> certlisttoUpdate= new List<Certificate__c>();
        
 
         
        for ( Account a:acc )
         {
           Account oldAcc = oldaccounts.get(a.Id);
           if((a.Last_Updated_Date_Non_Integration_User__c != null) && (a.lastmodifieddate != oldAcc.lastmodifieddate)) 
           {
             accIds.add(a.id);
            } 
         }
         
        if(accIds.size()> 0) 
        {
        for (Account accs: [
             select id,
             (SELECT id,Force_Sync__c FROM Guarantors__r),  (SELECT id,Force_Sync__c FROM GuaranteeProviders__r) , (SELECT id,Force_Sync__c FROM Certificates__r), (SELECT id,Force_Sync__c FROM Security_Holders__r)
             from Account 
             where (Id in :accIds )]) {
           
            if(accs.Guarantors__r.size() > 0)
            {
            for(Guarantor__c gc:accs.Guarantors__r)
            { gc.Force_Sync__c = true;
              guarantorMap.put(gc.id,  gc);
            }
            }
        
           if(accs.GuaranteeProviders__r.size() > 0)
            {
            for(Guarantor__c gcs:accs.GuaranteeProviders__r)
            { gcs.Force_Sync__c = true;
              guarantorMap.put(gcs.id,  gcs);
            }
            }
             
            if(accs.Security_Holders__r.size() > 0)
            {   
              for(Security_Holder__c sc:accs.Security_Holders__r)
            { sc.Force_Sync__c = true;
              sclisttoUpdate.add(sc);
            }
            }
             
              if(accs.Certificates__r.size() > 0)
            { 
             for(Certificate__c cr:accs.Certificates__r)
            { cr.Force_Sync__c = true;
              certlisttoUpdate.add(cr);
            } 
            }
         }
        }
        if (!guarantorMap.isEmpty()) {
             Database.update(guarantorMap.values(), false);
           }
            
             
            
        if (!sclisttoUpdate.isEmpty()) {
            Database.update(sclisttoUpdate, false); 
           } 
         
         if (!certlisttoUpdate.isEmpty()) {
            Database.update(certlisttoUpdate, false); 
        }  
    }  
    
   
  
  // Thayalan finish
    public static void handleAfterInsert( List<Account> insertedAccounts )
    {
        updateNonIntegrationAuditFields( insertedAccounts );
    }
    
    public static void handleAfterUpdate( Map<Id, Account> updatedAccounts, Map<Id, Account> oldAccounts )
    {
        updateNonIntegrationAuditFields( updatedAccounts.values() );
        updatePendingApplicationFields( updatedAccounts , oldAccounts);
    }
    
    private static void updateNonIntegrationAuditFields( List<Account> accounts )
    {
        Set<Id> userIds = new Set<Id>();
        for( Account a: accounts )
        {
            userIds.add( a.LastModifiedById );
        }
        
        Map<ID, User> users = new Map<Id, User>([Select Id, Integration_User__c from User
                           where id in: userIds
                           and Integration_User__c = false]);
        
        List<Account> accountsToUpdate = new List<Account>();
        for( Account a: accounts )
        {
            if( users.containsKey( a.LastModifiedById ) )
            {
                Account b = new Account( Id=a.Id );
                b.Last_Updated_by_Non_Integration_User__c = a.LastModifiedDate;
                b.Last_Updated_Date_Non_Integration_User__c = a.LastModifiedById;
                accountsToUpdate.add(b);
            }        
        }
        
        if( accountsToUpdate.size() > 0 )
        {
            update accountsToUpdate;
        }

    }
}
Hi there,
The code works for normal scenario with single lead, but the code does not support bulkifying. When Multiple leads try to convert same time, I am getting a "System.LimitException: Too many SOQL queries" error.

trigger LeadIntegrationTrigger on Lead (after update, after insert)
{
    
    List<String> LeadNames = new List<String>{};
    Set<ID> Oppid =new Set<ID>();
    List<Contact>lcon = New List<Contact>();
    List<OpportunityLineItem> ListLine = New List<OpportunityLineItem>();
    List<Opportunity> OppList = New List<Opportunity>();
    
 
    if (Trigger.isInsert) {
        for(Lead aLead: Trigger.new){
          
                if((aLead.isconverted==false) && (aLead.Status == 'Qualified - Enrolled')) {
                    Database.LeadConvert lc = new database.LeadConvert();
                    lc.setLeadId(aLead.Id);
                    lc.convertedStatus = 'Qualified - Enrolled';
                    lc.setDoNotCreateOpportunity(false);
                    Database.LeadConvertResult lcr = Database.convertLead(lc);
                    System.assert(lcr.isSuccess());
                    //aLead.IsConverted=false;
                }
                 
        }
    
    }
    
    if (Trigger.isUpdate ) {
        List<OpportunityStudent__c> aNewStudents = new List<OpportunityStudent__c>();
        Map<Id, Lead> aLeadToCheck = new Map<Id, Lead>();
        for(Integer x = 0; x < Trigger.new.size(); x++)
            {        
                    if((Trigger.new[x].isconverted==false) && (Trigger.new[x].Status == 'Qualified - Enrolled'&&Trigger.new[x].Status!=Trigger.old[x].Status)) {
                    Database.LeadConvert lc = new database.LeadConvert();
                    lc.setLeadId(Trigger.new[x].Id);
                    lc.convertedStatus = 'Qualified - Enrolled';
                    lc.setDoNotCreateOpportunity(false);
                    Database.LeadConvertResult lcr = Database.convertLead(lc);
                    System.assert(lcr.isSuccess());
                   }
        
        
            if (Trigger.new[x].IsConverted == true && Trigger.oldMap.get(Trigger.new[x].Id).IsConverted == false&& Trigger.new[x].ConvertedOpportunityId != null && Trigger.new[x].ConvertedContactId != null){  
                aLeadToCheck.put(Trigger.new[x].ConvertedOpportunityId, Trigger.new[x]);
            }
        }
         
        //Auto add student on Opportuntiy
        List<Opportunity> anOppList = [SELECT Id, AccountId, Account.Name,account.recordtype.name FROM Opportunity WHERE Id IN :aLeadToCheck.keySet()];
        
        for (Opportunity anOpp: anOppList){
        
           if (anOpp.AccountId != null){
                Lead aLead = aLeadToCheck.get(anOpp.Id);
                //update Opportunity Detail
               
                anOpp.Training_Program__c=aLead.Product__c;
                OppList.add(anOpp);
                //
                Contact con=[SELECT id,Avetmiss_At_School__c,Contact_Method__c,Avetmiss_Country_Of_Birth__c,
                Avetmiss_Disability__c,Avetmiss_Disability_List__c,Gender__c,Avetmiss_Highest_School_Level__c,
                Avetmiss_Indigenous_Status__c,Avetmiss_Labour_Force_Status__c,Avetmiss_Learner_Unique_Identifier__c,
                Avetmiss_Main_Language__c,Avetmiss_Nationality__c,Avetmiss_Prior_Education__c,Prior_Education__c,Avetmiss_Prior_Education_List__c,
                Avetmiss_School_Identifier__c,Avetmiss_Spoken_English_Proefficiency__c,Avetmiss_Year_Highest_School_Level__c,BirthDate
                FROM contact WHERE id=:aLead.ConvertedContactId];
                system.debug('Cloning');
                //Clone data to personAccount
                con.Avetmiss_At_School__c=aLead.Avetmiss_At_School__c;
               
                               
            
                con.Avetmiss_Year_Highest_School_Level__c = aLead.Avetmiss_Year_Highest_School_Level__c;
                lcon.add(con);
                // end clone data
                
                //Add New PricebookEntry
                if(aLead.Product__c!=null){
                    PricebookEntry Pricebook=[SELECT id FROM PricebookEntry WHERE Product2Id=:aLead.Product__c Limit 1];
                  
                }                    
                OpportunityStudent__c aNewStudent = new OpportunityStudent__c();
                aNewStudent.Contact__c = aLead.ConvertedContactId;
                aNewStudent.Opportunity__c = aLead.ConvertedOpportunityId;                                          
                Oppid.add(aNewStudent.Opportunity__c);
                aNewStudents.add(aNewStudent);
                system.debug('@@@@@ CCCC');
            }
            else{
                Oppid.add(anOpp.id);
            }
        }
        
        //Prevent Duplicate Manage student [Person Acccount]
        try{
            List <OpportunityContactRole> Role=[SELECT id,opportunityid FROM OpportunityContactRole WHERE Opportunityid in : Oppid];
            delete Role;
        }
        catch(System.QueryException e){}
        
        insert aNewStudents;
        //insert ListLine;
        update OppList;
        Update lcon;   
        List<OpportunityStudent__c> ListStudent=[SELECT id,Opportunity__c,Contact__c FROM OpportunityStudent__c WHERE Opportunity__c in:Oppid];
        IF(ListStudent.size()>1){
            delete ListStudent[1];
        }    
    }
}