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
benwrigleybenwrigley 

Bulk uploader

Hi All,

 

This isn't really an APEX question but I still think you are the right crowd.

 

I've written a trigger on Account to catch the country field and populate a relevant tax field. Simple enough.

 

Now I want to run that query on all 30k account records that I have. 

 

I thought I could just use the Bulk Uploader and perform an update on all Accounts and set Name=Name so that the trigger will execute. This works fine for about the first 56 records and then fails with 'Too many SOQL...'

 

Does anyone else have a good solution for this?

 

TIA

dmchengdmcheng

Can you post your trigger code?

benwrigleybenwrigley

I have two triggers on Account

 

 

trigger noEditAfterSale on Account (before update) {
	
	//who is running this update
		String userid = UserInfo.getUserId();
		
		//check if this user is 
		Integer cu = [select count() from GroupMember where UserOrGroupId=:userid and Group.Name='canChangeAccountAfterSale'];
	
		//if they are not then check if they are allowed to update
		if (cu == 0){

			for (Account a : Trigger.new) {
				//count the active opportunites for this account
				Integer c = [select count() from Opportunity where Activated__c != null and AccountId=:a.Id];
		
				if (c > 0){
					a.addError('You cannot edit this account as it has activated opportunities. Please speak to Finance.');
				}
			}
		}
}

 

 

and

 

 

trigger setVatType on Account (before insert, before update) {
    /*When a country is selected by the user we need to update the input VAT Code
    	UK = VOSTD
    	EU = VOEXT
    	Other = ? */
    
    for (Account a : Trigger.new) {
		TMDR_FinancialForce.setVATCode(a); 
    }
}



public static void setVATCode(Account a){
	/*calculate the correct VAT code for this Account country*/
	String zone = '';
	if (a.Registered_Charity__c	== true){
    	    zone = 'VOEXT';
    	}
		
	else if (a.Billing_Country__c != null){
    
    		Country__c country = [select id,Vat_Zone__c from Country__c where id =:a.Billing_Country__c];
    				
    			
        	if (country.Vat_Zone__c == 'UK'){
            	    zone = 'VOSTD';
        	}
        	else{
            	    zone = 'VOEXT';
        	}
	}
	else{
		zone = 'VOSTD';
	}
    		
    	List <c2g__codaTaxCode__c> codes = [select ID from c2g__codaTaxCode__c where Name=:zone];
        if (codes.size() == 1){
        	a.c2g__CODAInputVATCode__c = codes[0].ID;
    	}
		
		
}

 

 

and

 

 

trigger TMDR_copyBillingAddress on Account (before insert, before update) {

	for (Account a : Trigger.new) {
		
		if (a.Billing_Country__c != null){
			Country__c country = [select Name from Country__c where ID=:a.Billing_Country__c limit 1];
			a.BillingCountry = country.Name;
		}
		a.BillingCity = a.Billing_City__c;
		a.BillingPostalCode = a.Billing_Postal_Code__c;
		a.BillingState = a.Billing_County__c;
		a.BillingStreet = a.Billing_Address_1__c + '\n' + a.Billing_Address_2__c + '\n' + a.Billing_Address_3__c + '\n' + a.Billing_Address_4__c;
		
	}
}

 

thanks for your help.

 

dmchengdmcheng

You have SOQL statements inside your FOR loops, which is why you are exceeding the governor limits.  See this link on how to code for "bulk" operations.

 

http://wiki.developerforce.com/index.php/Apex_Code_Best_Practices