• GrumpyDev
  • NEWBIE
  • 65 Points
  • Member since 2018

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 12
    Replies
Hi Experts,

I have below code which is calling before update on account ,i have nested loops because of that i am getting cpu time out issue, can anyone convert my code into MAp please.

        Set<Id> Accids= New Set<Id>();
        Set<String>Fun= new set<string>();
        
        Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('RecordType').getRecordTypeId();
        
        
        if(AccRecordTypeId !=null)
        {
        FOR(Account A : newList)
        { 
            
            if(A.RecordTypeId == AccRecordTypeId)
            {
                Accids.Add(A.id);
                system.debug('%%%%%%'+Accids);
            }    
            
        }
        
       } 
        String samp = System.Label.User_ID; 
        List<Function__c> PR = [Select Id,Salesforce_ID__c,Function_Def__c,Person__c,Pernr__c from Function__c where Salesforce_ID__c IN : Accids and Pernr__c !=null ];
        system.debug('$$$$$$'+PR );
        
        for(Function__c pf: PR)
        {
            if( pf.Salesforce_ID__c != Null)
            {
                system.debug('^^^^^^'+pf);
                Fun.add(pf.Pernr__c);
                system.debug('#######'+Fun);
            }
        }
        
        list<Person__c> gp = [ select id , Employee_ID__c,User__c,OwnerId from Person__c where Employee_ID__c in : Fun];
        system.debug('@@@@@'+gp );
        
        if(gp.size()>0)
        {
            
            FOR(Account A : newList)
                
            {
                
                for(Person__c gpr: gp)
                {
                    for( Function__c pfr: PR)
                    {
                        if(gpr.User__c!=null && pfr.Function_Def__c!=null )
                        {
                            
                            if(pfr.Function_Def__c== 'ABC' )
                            {
                                
                                system.debug('&&&&&'+gpr);
                                A.OwnerId=gpr.User__c;
                                system.debug('!!!!!'+A.ownerid);
                                
                            }
                            else if(pfr.Function_Def__c== 'DEF' || pfr.Function_Def__c== 'GHI' || pfr.Function_Def__c== 'JKL')
                            {
                                A.OwnerId=gpr.User__c;
                                system.debug('88888'+A.ownerid);
                                
                            }
                        }
                        else 
                        {
                            A.OwnerId=samp;
                            system.debug('***'+A.ownerid);
                        }
                    }
                }
            }
            
        }
error :- First exception on row 0 with id 0012v00002J69maAAB; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0012v00002J69ma) is currently in trigger isdead, therefore it cannot recursively update itself: []: Trigger.isdead: line 43, column 1.

Code-
trigger isdead on Account (before insert,before update) {
    
    list <Account> up=new list<Account>();
    
    Set<Id> stdIds = new Set<Id>();
    for(Account ac : Trigger.new)
    {
        stdIds.add(ac.Id);
    }
    List<contact> contactlist = new List<Contact>();
        integer x=0;
        List<Account> Act =[select id from Account where Id in :stdIds];
        System.debug(Act);
        for(Account A : Act)
        {
           contactlist=[select Id,Dead__c from Contact where AccountId =:A.Id];
            x=0;
           system.debug(contactlist);
            for(Contact c:contactlist){
                if(c.Dead__c==true){
                    system.debug('here');
                    x++;
                }
            }
            
            system.debug('value of x='+x);
            system.debug(contactlist.size());
            
            if(x>contactlist.size()){
                A.need_intel__c=true;
            
            }
            else{
                A.need_intel__c=false;
                
            }
 
            up.add(A);

            
        }
  
      ------->  update up; // code gets stuck at this point cannot really                                              figure it out why 
       
        
    }
Hi All,
I have developed a visual force page so i wanted to add URL(link) in this page, Kindly help me on this.

Apex code:

<apex:page standardController="Lead" extensions="CreateLeadC" sidebar="false" showheader="false">

<apex:commandLinkaction =”http://www.google.com/search” value=”Google”>
</apex:commandLinkaction>

<apex:form>
<apex:outputLabel ><b> #Call: </b></apex:outputLabel>
<apex:outputField value="{!Lead.Call_Number__c}"/>

<apex:outputLabel ><b> #Attempt: </b></apex:outputLabel>
<apex:outputField value="{!Lead.Attempt_Number__c}"/>

<apex:pageBlock >
 
 

<apex:pageBlockSection columns="1"  title="Patient details"  rendered="{!Lead.Country__c== 'India'}">


<apex:outputField value="{!Lead.name}"/>
<apex:outputField value="{!Lead.Phone}"/>

<apex:inlineEditSupport />


</apex:pageBlockSection>

<apex:pageBlockSection title="Patient Consent" rendered="{!Lead.Country__c== 'India'}">

<apex:outputField value="{!Lead.Gendre__c}"/>

<apex:inlineEditSupport />

</apex:pageBlockSection>
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlock>
                
                
           
</apex:form>

 
</apex:page>
Hi Experts,

I have below code which is calling before update on account ,i have nested loops because of that i am getting cpu time out issue, can anyone convert my code into MAp please.

        Set<Id> Accids= New Set<Id>();
        Set<String>Fun= new set<string>();
        
        Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('RecordType').getRecordTypeId();
        
        
        if(AccRecordTypeId !=null)
        {
        FOR(Account A : newList)
        { 
            
            if(A.RecordTypeId == AccRecordTypeId)
            {
                Accids.Add(A.id);
                system.debug('%%%%%%'+Accids);
            }    
            
        }
        
       } 
        String samp = System.Label.User_ID; 
        List<Function__c> PR = [Select Id,Salesforce_ID__c,Function_Def__c,Person__c,Pernr__c from Function__c where Salesforce_ID__c IN : Accids and Pernr__c !=null ];
        system.debug('$$$$$$'+PR );
        
        for(Function__c pf: PR)
        {
            if( pf.Salesforce_ID__c != Null)
            {
                system.debug('^^^^^^'+pf);
                Fun.add(pf.Pernr__c);
                system.debug('#######'+Fun);
            }
        }
        
        list<Person__c> gp = [ select id , Employee_ID__c,User__c,OwnerId from Person__c where Employee_ID__c in : Fun];
        system.debug('@@@@@'+gp );
        
        if(gp.size()>0)
        {
            
            FOR(Account A : newList)
                
            {
                
                for(Person__c gpr: gp)
                {
                    for( Function__c pfr: PR)
                    {
                        if(gpr.User__c!=null && pfr.Function_Def__c!=null )
                        {
                            
                            if(pfr.Function_Def__c== 'ABC' )
                            {
                                
                                system.debug('&&&&&'+gpr);
                                A.OwnerId=gpr.User__c;
                                system.debug('!!!!!'+A.ownerid);
                                
                            }
                            else if(pfr.Function_Def__c== 'DEF' || pfr.Function_Def__c== 'GHI' || pfr.Function_Def__c== 'JKL')
                            {
                                A.OwnerId=gpr.User__c;
                                system.debug('88888'+A.ownerid);
                                
                            }
                        }
                        else 
                        {
                            A.OwnerId=samp;
                            system.debug('***'+A.ownerid);
                        }
                    }
                }
            }
            
        }
Hi All,

When a user is trying to create a Quote for an Opportunity then the below Error is displayed :

Apex trigger trg_QuoteLineItem has caused an unexpected exception. Contact your administrator: trg_QuoteLineItem: execution of AfterInsert caused by: System.ListException: Duplicate id in list: 0QL1E000004rJkSWAU: ()

Also since this code is not developed by me , I am unable to understand on whats causing the issue in the below Code :
 
trigger trg_QuoteLineItem on QuoteLineItem ( after insert, after update, after delete, before insert, before update ) {
    
    cls_trg_QuoteLineItem handler = new cls_trg_QuoteLineItem();
    
    if (trigger.isafter && trigger.isInsert) {
        system.debug('inside after insert');
      handler.removeWarrantyFromQuote( trigger.new );
    }
    
    if ( trigger.isAfter ) {
        
        if ( trigger.isInsert || trigger.isUpdate ) {
                    
            //Set Quote's 'QLI Rebate Names' and 'QLI_Conga_Template_ID_s_c' Process
            handler.updateQuoteFromQLIInsert(trigger.new);
            handler.updatePromotionListPrice(trigger.new);
        }
        
        if ( trigger.isDelete ){
            
            //Set Quote's 'QLI Rebate Names' and 'QLI_Conga_Template_ID_s_c' Process
            handler.updateQuoteFromQLIInsert(trigger.old);
        }
    } else if(trigger.Isbefore) {
        
        //handler.updatePromotionListPrice(trigger.new);
    }
}

Please Help...Thanks for All Help in Advance

If a record is in Lead Status 'Working' and untouched(didn't edit) for 3 business days, I have to send a Task and Email to Lead owner and Manager (user lookup in Lead).

I tried with time-based workflow and process builder but it is not working properly. I believe this is can be done using Scheduler.

1. Can anyone help me how to achieve this using Apex Scheduler?

2. I have created Task and Email Alert in workflow actions. Is it possible to trigger them with scheduler Apex?

  • October 25, 2018
  • Like
  • 0