• Suresh Satyam
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Hi ,

      I wrote a trigger on my custom object ,it is the child of opportunity object.Opportunity having Account field and My custom object also having Account field.if i update my custom object thus account field is updated with Parent object opportunity accountfield.

The trigger working fine but when i edit record and click on save.Than it shows error i.e,

Apex trigger EM_Key_Player_update_Account caused an unexpected exception, contact your administrator: EM_Key_Player_update_Account: System.LimitException: Too many query rows: 50001

 

Trigger:


trigger EM_Key_Player_update_Account on PW_Key_Players__c (after insert, after update) {

list<opportunity> opp=[SELECT Id,StageName,accountid FROM Opportunity WHERE RecordTypeId in (SELECT Id FROM RecordType WHERE (Name='IS_Opportunity') OR (Name='EM_IS_Speedi'))];
list<PW_Key_Players__c> lokp=[select id,name,PW_Account__c from PW_Key_Players__c];
list<opportunity> lopp=new list<opportunity>();
for(PW_Key_Players__c okp:trigger.new){
for(opportunity o:opp){
if(okp.EM_IS_WinAccCu__c==true){
o.accountid=okp.PW_Account__c;
lopp.add(o);
}

}
update opp;
}
}

I thought this can be achieve by bulk trigger,but i dont no exactly.Could anyone help me out.

 

Hi,This is Suresh

I have developed a class for this i wrote a test class,but coverage be in 45%only.Can anyone improve this.

Class:

  public GE_EM_Request_Button_Logic(ApexPages.StandardController controller) {

       
            this.Record = (Opportunity)controller.getRecord();
            Record1 = [select id,name from opportunity where id=:record.id];
            string oppname = [select name from opportunity where id =: Record.id].Name;
            string usrObj = UserInfo.getUserId();
            string usrObj1 = UserInfo.getName();
            reqname = new GE_EM_Request__c();
            reqname.GE_EM_Status__c = 'Open';
            reqname.GE_EM_RFQ_Indicator_Value__c = 'G';
            reqname.GE_EM_Opportunity__c = Record.id;
            reqname.Name= oppname;
            
    }    
   
    public PageReference request(){
            system.debug('--------'+reqname);
            string usrObj = UserInfo.getUserId();
            string usrObj1 = UserInfo.getName();
            insert reqname;
            return  new PageReference('/a2c/e?&00NZ0000000mFtb='+reqname.GE_EM_Status__c+'&Name='+reqname.Name+'&00NZ0000000mFxY=G&CF00NZ0000000mFtH__lkid='+usrObj+'&CF00NZ0000000mFtH='+usrObj1+'&recordType=012Z00000000Mv9'+'&CF00NZ0000000m62x__lkid=+record1.id&CF00NZ0000000m62x__lkid=+record1.name');         
    }

-----------------------------------------

Test Class:

 static testmethod void GE_EM_Request_Button_Logictest(){
    
    Opportunity obj = new Opportunity(); 
    ApexPages.StandardController ob = new ApexPages.StandardController(obj); 
    GE_EM_Request_Button_Logic gel = new GE_EM_Request_Button_Logic (ob); 
    
    obj.Name = 'opportunity';  
    obj.CloseDate = system.today(); 
    obj.StageName = 'qualification';  
    insert obj; 
      system.debug('The opp is '+obj);
      
  GE_EM_Request__c gr = new GE_EM_Request__c();   
    gr.GE_EM_Status__c = 'Open';   
    gr.GE_EM_RFQ_Indicator_Value__c = 'g';   
    gr.GE_EM_Opportunity__c = obj.id;   
    gr.name = 'suresh';
    insert gr; 
         gel.request(); 
    }