+ Start a Discussion
John AthitakisJohn Athitakis 

Apex Code not working via data loader

Scratching my head--works fine in the UI, but not via data loader. Any suggestions?

GIST: Check to see if company name is in another table, OR in some other conditions (basic if then) flag a field as true on lead. Nothing complex. Why is Data Loader skipping it?

trigger LeadAssignmentRuleTest on Lead (before insert) {
  for (Lead a : Trigger.new) {
      List<Inside_View_Company__c> b= [select id, Account_Name__c from Inside_View_Company__c where Account_Name__c = :a.Company LIMIT 1];
     

    if(!b.isEmpty() || a.Event_Temperature__c=='Hot'|| a.Event_Temperature__c=='Warm') {
          a.Direct_to_Sales__c=True;
    }
    if(!String.isblank(a.Form_Name__c)){
          if(a.Form_Name__c.containsIgnoreCase('buy') || a.Form_Name__c.containsIgnoreCase('inquiry')){
		  a.Direct_to_Sales__c=True; 												
          }
	}
 }
}
CyberJusCyberJus
Are the record actually being inserted via dataloader? Your code contains a SOQL query inside a loop which means that you are probably hitting your Govenor limits and the insert is erroring out. You need to move your query outside a loop and use Sets, Maps, etc to bulkify.  

Here is more information on best practice: https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
John AthitakisJohn Athitakis
Actually the insert is happening just fine? No errors are being hit, or reported back. In a test load of 2000 records all 2000 are being inserted without any issue. When I test it with just one insert, it also inserts just fine and I imagine that single record would not hit the governer limits, so I'm not sure this is the issue at all.