function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prazonprazon 

URGENT HELP on trigger

 

 

I have an object Flag_Reporter__c which is child object in master detail relationship with Account...in an account trigger I have set the following code..in test class I having error: System.LimitException: Too many SOQL queries: 101

 

trigger Trg_After_Flag_Updater on Account (after update) {
    
    
    Boolean updateFlag = false;
    Boolean insertFlag = false;
    
    List<Flag_Reporter__c> lstFlagReporter = new List<Flag_Reporter__c>();
    
        Set<ID> aID = trigger.newMap.keySet();
        
        
        
        Map<ID,Flag_Reporter__c> fRC= New Map<ID,Flag_Reporter__c>();
        
        List<Flag_Reporter__c> flags = [Select Overall_Status__c,Overall_Status_Ranking__c,Account_Flag__r.Id,Flag_for_Editorial__c from Flag_Reporter__c Where Account_Flag__c IN : aID];
        for(Flag_Reporter__c fr: flags){        
            fRC.put(fr.Account_Flag__r.Id,fr);
        }
    for(Account accFlag:Trigger.new){
        
        Flag_Reporter__c fr;
        String editorial;
        if(fRC.get(accFlag.Id)!=NULL)
            fr = fRC.get(accFlag.Id);
        
        if(fr!=NULL){
            updateFlag = true;
            
            if(fr.Overall_Status__c == 'RED')
                fr.Overall_Status_Ranking__c = 1;
            else if(fr.Overall_Status__c == 'YELLOW')
                fr.Overall_Status_Ranking__c = 6;
            else if(fr.Overall_Status__c == 'GREEN')
                fr.Overall_Status_Ranking__c = 8;
                
             if(accFlag.Partner_Reviews__c!=NULL){
                if(accFlag.Partner_Reviews__c == '1')
                   fr.Flag_for_Editorial__c= 'RED';
                else 
                    fr.Flag_for_Editorial__c= 'GREEN';
             }
             lstFlagReporter.add(fr);
        }if(fr == NULL){
            insertFlag=true;
            lstFlagReporter.add(new Flag_Reporter__c(Account_Flag__c=accFlag.Id));   
        }
           
        
    
    }try{
        if(updateFlag==true)
            update lstFlagReporter;  
            
         if(insertFlag==true)
            insert lstFlagReporter;    
            
    }catch(Exception ex){
        ex.getMessage();
    }


}

 


stack is showing error in this place:

 

List<Flag_Reporter__c> flags = [Select Overall_Status__c,Overall_Status_Ranking__c,Account_Flag__r.Id,Flag_for_Editorial__c from Flag_Reporter__c Where Account_Flag__c IN : aID];

 

Best Answer chosen by Admin (Salesforce Developers) 
MandyKoolMandyKool

Hi,

 

Trigger looks fine to me.

Is there any trigger on your custom object "Flag_Reporter__c" which is updating the "Account"? If yes, then the two trigger are calling each other in recursion. (In that case you can find out how to avoid recursion while writing triggers on discusstion forum)

 

Else, you can write a system.debug('Trigger Called::::::::') statement on your trigger code or you can use "Limits" class to find out where the query limit is crossing in current context. 

 

Here's a link - http://wiki.developerforce.com/page/Best_Practice:_Use_of_the_Limits_Apex_Methods_to_avoid_Hitting_Governor_Limits 

 

Its hard to understand from the code where the exact issue is :(. But for sure you are crossing governors..

 

 

All Answers

MandyKoolMandyKool

Hi,

 

Not sure if you have used "Test.startTest()" and "Test.stopTest()" in your test method. (try and check if problem persists)

 

Also if possible can u paste your test class here.. so that it will be easy to provide you solution.


 

prazonprazon

Here is the code now I am getting a different error:

@isTest
private class TestAccQuality{
static testMethod void testWithFlag() {
    
        Account flagTestAccount = new Account(Name='Flag Test Account',Actual_Physical_Country__c='UK',BillingCountry='UK',Partner_Reviews__c='1');
        insert flagTestAccount;
        
        Flag_Reporter__c testFlagReporter = new Flag_Reporter__c(Account_Flag__c=flagTestAccount.Id,Venue__c = 'RED', WebsiteFlag__c = 'RED');
        insert testFlagReporter;         
        
        
        
        Account_Flag_Status_Controller cntrl = new  Account_Flag_Status_Controller( new ApexPages.StandardController(flagTestAccount));
        
        Test.startTest();      
        System.assertNotEquals(cntrl.colorSetter, NULL); 
        System.assertEquals(cntrl.back().getURL(), '/' + cntrl.AccountId);
        //cntrl.save();
        cntrl.getItems();
        Test.stopTest();        
         
        // FOR BOTH NULL COMMENTS
        cntrl.flagReport[0].Flag_comments__c = NULL;
        cntrl.flagReport[0].Overall_comments__c = NULL;
        
        Test.startTest();
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue='GREEN';
        
        cntrl.save();
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue= NULL;
       
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= 'GREEN';
        
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website='GREEN';
        cntrl.venue= 'GREEN';
       
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website= NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        Test.stopTest();
        
        
        
        // FOR FLAG COMMENTS
        cntrl.flagReport[0].Flag_comments__c = 'Test comments';
        cntrl.flagReport[0].Overall_comments__c = NULL;
        
        Test.startTest();
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue='GREEN';
        
        cntrl.save();
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue= NULL;
       
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= 'GREEN';
        
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website='GREEN';
        cntrl.venue= 'GREEN';
       
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website= NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        Test.stopTest();
        
        // FOR OVERALL COMMENTS
        cntrl.flagReport[0].Flag_comments__c = NULL;
        cntrl.flagReport[0].Overall_comments__c = 'Test comments';
        
        Test.startTest();
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue='GREEN';
        
        cntrl.save();
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue= NULL;
       
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= 'GREEN';
        
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website='GREEN';
        cntrl.venue= 'GREEN';
       
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website= NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
       
        Test.stopTest();
        
        
    }
}

 

 

prazonprazon

error is now:

 

System.FinalException: Testing already started

 

pointing at 

 

if(fr!=NULL){

prazonprazon

problem is still persisting :(

MandyKoolMandyKool

Hi,

 

Not sure if you are testing a VF Page or a Trigger.. anyways..

 

 

Just remove all "test.StartTest()" and test.StopTest()" statements from the Test class.

 

Place one Test.startTest() and the beginning (just after you start writing the test method) and one in the end.

 

Also it is always better to write your test methods seperately for a VF Page and for a trigger as that will help you reduce no. of DML operations per context.

 


 

MandyKoolMandyKool

Hi,

 

You can have only one "StartTest" and "StopTest" in your entire test method ;)

prazonprazon

changed it but still getting the same error...this test class is for a class ..during execution it is calling that trigger... so getting the same problem..here is the renewed test class

 

@isTest
private class TestAccQuality{
static testMethod void testWithFlag() {
    
        Account flagTestAccount = new Account(Name='Flag Test Account',Actual_Physical_Country__c='UK',BillingCountry='UK',Partner_Reviews__c='1');
        insert flagTestAccount;
        
        Flag_Reporter__c testFlagReporter = new Flag_Reporter__c(Account_Flag__c=flagTestAccount.Id,Venue__c = 'RED', WebsiteFlag__c = 'RED');
        insert testFlagReporter;         
        
        
        
        Account_Flag_Status_Controller cntrl = new  Account_Flag_Status_Controller( new ApexPages.StandardController(flagTestAccount));
        
        Test.startTest();      
        System.assertNotEquals(cntrl.colorSetter, NULL); 
        System.assertEquals(cntrl.back().getURL(), '/' + cntrl.AccountId);
        //cntrl.save();
        cntrl.getItems();
        //Test.stopTest();     
        
        //Test.startTest();   
         
        // FOR BOTH NULL COMMENTS
        cntrl.flagReport[0].Flag_comments__c = NULL;
        cntrl.flagReport[0].Overall_comments__c = NULL;
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue='GREEN';
        
        cntrl.save();
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue= NULL;
       
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= 'GREEN';
        
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website='GREEN';
        cntrl.venue= 'GREEN';
       
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website= NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        //Test.stopTest();
        
        
        //Test.startTest();
        // FOR FLAG COMMENTS
        cntrl.flagReport[0].Flag_comments__c = 'Test comments';
        cntrl.flagReport[0].Overall_comments__c = NULL;
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue='GREEN';
        
        cntrl.save();
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue= NULL;
       
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= 'GREEN';
        
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website='GREEN';
        cntrl.venue= 'GREEN';
       
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website= NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        //Test.stopTest();
        
        //Test.startTest();
        
        // FOR OVERALL COMMENTS
        cntrl.flagReport[0].Flag_comments__c = NULL;
        cntrl.flagReport[0].Overall_comments__c = 'Test comments';
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue='GREEN';
        
        cntrl.save();
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue= NULL;
       
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= 'GREEN';
        
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website='GREEN';
        cntrl.venue= 'GREEN';
       
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website= NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        // FOR OVERALL COMMENTS
        cntrl.flagReport[0].Flag_comments__c = 'Test comments';
        cntrl.flagReport[0].Overall_comments__c = 'Test comments';
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue='GREEN';
        
        cntrl.save();
        
        
        
        cntrl.editorial='GREEN';
        cntrl.website='GREEN';
        cntrl.venue= NULL;
       
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
        
        
        cntrl.editorial='GREEN';
        cntrl.editorial='GREEN';
        cntrl.website=NULL;
        cntrl.venue= 'GREEN';
        
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website='GREEN';
        cntrl.venue= 'GREEN';
       
        cntrl.save();
        
        
        cntrl.editorial= NULL;
        cntrl.website= NULL;
        cntrl.venue= NULL;
        
        cntrl.save();
       
        Test.stopTest();
        
        
    }
}

 

prazonprazon

Here is the save method..for which I am getting the problem...

public Pagereference save(){
        Boolean edited = false;
        
        if(flagReport[0].Overall_comments__c!=NULL)
            this.overallComments=flagReport[0].Overall_comments__c;
        else
            this.overallComments = NULL;
        
        if(flagReport[0].Flag_comments__c!=NULL)
            this.flagComments=flagReport[0].Flag_comments__c;
        else
            this.flagComments = NULL;
        
        //for both comments true
        
        if(this.flagComments!=NULL && this.overallComments!=NULL){
        
            if(this.editorial!= NULL && this.website != NULL && this.venue!= NULL){
                
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c,Venue__c,Flag_comments__c, Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               flagReported[0].WebsiteFlag__c = this.website;
               flagReported[0].Venue__c = this.venue;
               flagReported[0].Flag_comments__c = this.flagComments;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
            }    
            
            else if(this.editorial!= NULL && this.website == NULL && this.venue == NULL){
               
               flagReported=[Select Id, Flag_for_Editorial__c,Flag_comments__c, Overall_comments__c  from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               flagReported[0].Flag_comments__c = this.flagComments;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.website!= NULL && this.editorial== NULL && this.venue == NULL){
                
               flagReported=[Select Id,WebsiteFlag__c,Flag_comments__c, Overall_comments__c from  Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Flag_comments__c = this.flagComments;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial == NULL){
               
               flagReported=[Select Id,Venue__c,Flag_comments__c, Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].Flag_comments__c = this.flagComments;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website!= NULL && this.editorial== NULL){
               
               flagReported=[Select Id,Venue__c,WebsiteFlag__c,Flag_comments__c, Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Flag_comments__c = this.flagComments;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            
            else if(this.venue== NULL && this.website!= NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c,Flag_comments__c, Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Flag_comments__c = this.flagComments;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Venue__c,Flag_for_Editorial__c,Flag_comments__c, Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               flagReported[0].Flag_comments__c = this.flagComments;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
             else if(this.venue== NULL && this.website== NULL && this.editorial == NULL){
                 flagReported=[Select Id,Flag_comments__c, Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                 flagReported[0].Flag_comments__c = this.flagComments;
                 flagReported[0].Overall_comments__c = this.overallComments;
                 edited = true;
             }
            
        }
        
        //for flagcomments true
        
        if(this.flagComments!=NULL && this.overallComments==NULL){
        
            if(this.editorial!= NULL && this.website != NULL && this.venue!= NULL){
                
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c,Venue__c,Flag_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               flagReported[0].WebsiteFlag__c = this.website;
               flagReported[0].Venue__c = this.venue;
               flagReported[0].Flag_comments__c = this.flagComments;
               
               edited = true;
            }    
            
            else if(this.editorial!= NULL && this.website == NULL && this.venue == NULL){
               
               flagReported=[Select Id, Flag_for_Editorial__c,Flag_comments__c  from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               flagReported[0].Flag_comments__c = this.flagComments;
               
               edited = true;
               
            }
            else if(this.website!= NULL && this.editorial== NULL && this.venue == NULL){
                
               flagReported=[Select Id,WebsiteFlag__c,Flag_comments__c from  Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Flag_comments__c = this.flagComments;
               
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial == NULL){
               
               flagReported=[Select Id,Venue__c,Flag_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].Flag_comments__c = this.flagComments;
               
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website!= NULL && this.editorial== NULL){
               
               flagReported=[Select Id,Venue__c,WebsiteFlag__c,Flag_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Flag_comments__c = this.flagComments;
               
               edited = true;
               
            }
            
            else if(this.venue== NULL && this.website!= NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c,Flag_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Flag_comments__c = this.flagComments;
               
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Venue__c,Flag_for_Editorial__c,Flag_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               flagReported[0].Flag_comments__c = this.flagComments;
               
               edited = true;
               
            }
             else if(this.venue== NULL && this.website== NULL && this.editorial == NULL){
                 flagReported=[Select Id,Flag_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                 flagReported[0].Flag_comments__c = this.flagComments;
                 
                 edited = true;
             }
            
        }
        
        
        
        //for overall comments true
        
        if(this.flagComments==NULL && this.overallComments!=NULL){
        
            if(this.editorial!= NULL && this.website != NULL && this.venue!= NULL){
                
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c,Venue__c,Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               flagReported[0].WebsiteFlag__c = this.website;
               flagReported[0].Venue__c = this.venue;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
            }    
            
            else if(this.editorial!= NULL && this.website == NULL && this.venue == NULL){
               
               flagReported=[Select Id, Flag_for_Editorial__c,Overall_comments__c  from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.website!= NULL && this.editorial== NULL && this.venue == NULL){
                
               flagReported=[Select Id,WebsiteFlag__c,Overall_comments__c from  Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial == NULL){
               
               flagReported=[Select Id,Venue__c,Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website!= NULL && this.editorial== NULL){
               
               flagReported=[Select Id,Venue__c,WebsiteFlag__c,Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            
            else if(this.venue== NULL && this.website!= NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c,Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               flagReported[0].WebsiteFlag__c= this.website;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Venue__c,Flag_for_Editorial__c,Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               flagReported[0].Overall_comments__c = this.overallComments;
               edited = true;
               
            }
            else if(this.venue== NULL && this.website== NULL && this.editorial == NULL){
                 flagReported=[Select Id,Overall_comments__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                 flagReported[0].Overall_comments__c = this.overallComments;
                 
                 edited = true;
             }
            
        }
        
        //when there is no comments
        
        if(this.flagComments==NULL && this.overallComments==NULL){
        
            if(this.editorial!= NULL && this.website != NULL && this.venue!= NULL){
                
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c,Venue__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               flagReported[0].WebsiteFlag__c = this.website;
               flagReported[0].Venue__c = this.venue;
               
               edited = true;
            }    
            
            else if(this.editorial!= NULL && this.website == NULL && this.venue == NULL){
               
               flagReported=[Select Id, Flag_for_Editorial__c  from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
                
               flagReported[0].Flag_for_Editorial__c = this.editorial;
               
               edited = true;
               
            }
            else if(this.website!= NULL && this.editorial== NULL && this.venue == NULL){
                
               flagReported=[Select Id,WebsiteFlag__c from  Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].WebsiteFlag__c= this.website;
               
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial == NULL){
               
               flagReported=[Select Id,Venue__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website!= NULL && this.editorial== NULL){
               
               flagReported=[Select Id,Venue__c,WebsiteFlag__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].WebsiteFlag__c= this.website;
               
               edited = true;
               
            }
            
            else if(this.venue== NULL && this.website!= NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Flag_for_Editorial__c,WebsiteFlag__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               flagReported[0].WebsiteFlag__c= this.website;
               
               edited = true;
               
            }
            else if(this.venue!= NULL && this.website== NULL && this.editorial != NULL){
               
               flagReported=[Select Id,Venue__c,Flag_for_Editorial__c from Flag_Reporter__c where Account_Flag__c =:this.AccountId LIMIT 1]; 
               flagReported[0].Venue__c= this.venue;
               flagReported[0].Flag_for_Editorial__c= this.editorial;
               
               edited = true;
               
            }
            
            
        }
        
        try{
            if(edited == true){
                update flagReported;
            
                PageReference pgRef = new PageReference('/apex/flagStatusPage?id=' + AccountId); 
                pgRef.setredirect(true); 
                return pgRef;
            }
            else{
                PageReference pgRef = new PageReference('/apex/flagStatusPage?id=' + AccountId); 
                pgRef.setredirect(true); 
                return pgRef;
            }
          
            
        }catch(Exception ex){
            ex.getMessage();
            
            return null;
        }
    
    
    
    }

 

MandyKoolMandyKool

Hi,

 

Just place your StartTest() statement before the insertion of Account.

 

Also check if Test class for Account trigger has "StartTest" and "StopTest". 

 

Also from your code it looks like that there are no DML oprations or SOQL statements in your Save() method.

Just make sure that in your code/test class you have not written any queries in For loop.

 

 

prazonprazon

It has an update at the last in Save method please check...

MandyKoolMandyKool

one update is fine,

 

but somewhere in your context other code snippet is getting called.. So number of SOQL for the context is crossing the governors of 100. StartTest and StopTest limits the governors context to that block only..

prazonprazon

Save method can only that trigger that I pasted..do you think that trigger is calling something in loop please have a look and tell me

MandyKoolMandyKool

Hi,

 

Trigger looks fine to me.

Is there any trigger on your custom object "Flag_Reporter__c" which is updating the "Account"? If yes, then the two trigger are calling each other in recursion. (In that case you can find out how to avoid recursion while writing triggers on discusstion forum)

 

Else, you can write a system.debug('Trigger Called::::::::') statement on your trigger code or you can use "Limits" class to find out where the query limit is crossing in current context. 

 

Here's a link - http://wiki.developerforce.com/page/Best_Practice:_Use_of_the_Limits_Apex_Methods_to_avoid_Hitting_Governor_Limits 

 

Its hard to understand from the code where the exact issue is :(. But for sure you are crossing governors..

 

 

This was selected as the best answer
prazonprazon

Hi,

 

There's an work flow  which updates a field in Account due to update in Flag Reporter...

MandyKoolMandyKool

Ok.

 

So the issue is related with the calling the same trigger recursively.

One workaround is to create your acount and update it in such a way that it will not fire workflow (try to set the criteria in u r code in such a way that workflow should not fire.) If that is not possible, try to find on forum about avoiding recursive triggers.

 

Going to bed now :) . If possible i will be online tomorrow.. and we can try to resolve this issue. Hope before that you will be able to resolve this one ;) .

 

If you need any help just drop me an email to mandy.kool@yahoo.com; i will try to help. 

 

Have a gr8 day!!!

prazonprazon

Thanks Kulkarni..solved it..it was related with the cycle of updation..needed to break it..