• Skottyp
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 10
    Replies
I have been working on launching some apex classes and triggers. The code works and all the tests pass when in the test environment, however when I try to move it to production it fails. I thought something may have changed in my production environment so I refreshed another test environment and deployed to that environment with no issues. What else can I do to try to find the issue?

Thanks in advance for the help.
I've been working on this a while and I am close, but running into this error:
trigger AssignDistSales2 on Distributor_Sales__c (before insert, before update) 
{
    //get set of 3 digit zips from Distributor Sales to be inserted or updated
    List<String> DSzip = new List<String>();
        for(Distributor_Sales__c ds : Trigger.new)
        {
            if(ds.ZipCode__c.length() == 5)
            {
                DSzip.add(ds.X3_Digit_Zip__c);
                //system.debug('5 digits - ' + ds.X3_Digit_Zip__c);
            }
            else 
            {
                DSzip.add('0'+ ds.X3_Digit_Zip__c);
                //system.debug('4 digits - ' + ds.X3_Digit_Zip__c);
            }
           	
        }
    
    	//list of territories needed to map to Distributor Sales zip
    Map<String,Territory__c> terrMap = new Map<String, Territory__c> ([SELECT X3_Digit_Zip__c, Sales_Rep__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip]);
    Map<String,Territory__c> terrMap2 = new Map<String, Territory__c> ([SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip]);
    	system.debug('potentialTerr - ' + terrMap2);
       
    List<Distributor_Sales__c> currentDS = new List<Distributor_Sales__c>();
    for(Distributor_Sales__c dsnew : DSzip)
    {
        dsnew.Sales_Rep_for_Later_Assignment__c  = terrMap2.get(DSzip.X3_Digit_Zip__c).Sales_Rep_for_Later_Assignment__c;
    	currentDS.add(dsnew);
    }      
	update currentDS;
}

Line 28 is the error. I have written in 10 different ways and am not sure where I am making the mistake. I am just trying to get 1 map to work and then the other should be the same code. Thanks!

Thanks for the help!
Hey Team,

My trigger works correctly when changing one record but when I use the data loader it is only assigning 1 sales rep for all the records. I have seen others that have had this same issue and it appears to be something with the mapping, but after a long time of comparing answers in other posts I'm not seeing my error. Please let me know where I am going wrong.
 
trigger AssignDistSales1 on Distributor_Sales__c ( before insert, before update) 
{
    //get set of 3 digit zips from Distributor Sales to be inserted or updated
    Set<String> ZIP = new Set<String>();
    for(Distributor_Sales__c distsales : Trigger.new){
        if(distsales.X3_Digit_Zip__c != null){
            ZIP.add(distsales.X3_Digit_Zip__c);
        }
    }
    
    //list of territories needed to map to Distributor Sales
    List<Territory__c> potentialTerr =  [SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :ZIP];
    
    //map that lets me search for territories by their zip
    Map<String,Territory__c> DistToTerrMap = new Map<String, Territory__c>();
        for (Territory__c t: potentialTerr) {
        DistToTerrMap.put(t.X3_Digit_Zip__c, t);
        
    //match the distributor sales 3 digit zip territory by 3 digit zip
    for(Distributor_Sales__c distsales : Trigger.new){
        distsales.Sales_Rep_for_Later_Assignment__c = DistToTerrMap.get(t.X3_Digit_Zip__c).Sales_Rep_for_Later_Assignment__c;
      }
   }
}

 
I have been working on launching some apex classes and triggers. The code works and all the tests pass when in the test environment, however when I try to move it to production it fails. I thought something may have changed in my production environment so I refreshed another test environment and deployed to that environment with no issues. What else can I do to try to find the issue?

Thanks in advance for the help.
I've been working on this a while and I am close, but running into this error:
trigger AssignDistSales2 on Distributor_Sales__c (before insert, before update) 
{
    //get set of 3 digit zips from Distributor Sales to be inserted or updated
    List<String> DSzip = new List<String>();
        for(Distributor_Sales__c ds : Trigger.new)
        {
            if(ds.ZipCode__c.length() == 5)
            {
                DSzip.add(ds.X3_Digit_Zip__c);
                //system.debug('5 digits - ' + ds.X3_Digit_Zip__c);
            }
            else 
            {
                DSzip.add('0'+ ds.X3_Digit_Zip__c);
                //system.debug('4 digits - ' + ds.X3_Digit_Zip__c);
            }
           	
        }
    
    	//list of territories needed to map to Distributor Sales zip
    Map<String,Territory__c> terrMap = new Map<String, Territory__c> ([SELECT X3_Digit_Zip__c, Sales_Rep__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip]);
    Map<String,Territory__c> terrMap2 = new Map<String, Territory__c> ([SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip]);
    	system.debug('potentialTerr - ' + terrMap2);
       
    List<Distributor_Sales__c> currentDS = new List<Distributor_Sales__c>();
    for(Distributor_Sales__c dsnew : DSzip)
    {
        dsnew.Sales_Rep_for_Later_Assignment__c  = terrMap2.get(DSzip.X3_Digit_Zip__c).Sales_Rep_for_Later_Assignment__c;
    	currentDS.add(dsnew);
    }      
	update currentDS;
}

Line 28 is the error. I have written in 10 different ways and am not sure where I am making the mistake. I am just trying to get 1 map to work and then the other should be the same code. Thanks!

Thanks for the help!
Hey Team,

My trigger works correctly when changing one record but when I use the data loader it is only assigning 1 sales rep for all the records. I have seen others that have had this same issue and it appears to be something with the mapping, but after a long time of comparing answers in other posts I'm not seeing my error. Please let me know where I am going wrong.
 
trigger AssignDistSales1 on Distributor_Sales__c ( before insert, before update) 
{
    //get set of 3 digit zips from Distributor Sales to be inserted or updated
    Set<String> ZIP = new Set<String>();
    for(Distributor_Sales__c distsales : Trigger.new){
        if(distsales.X3_Digit_Zip__c != null){
            ZIP.add(distsales.X3_Digit_Zip__c);
        }
    }
    
    //list of territories needed to map to Distributor Sales
    List<Territory__c> potentialTerr =  [SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :ZIP];
    
    //map that lets me search for territories by their zip
    Map<String,Territory__c> DistToTerrMap = new Map<String, Territory__c>();
        for (Territory__c t: potentialTerr) {
        DistToTerrMap.put(t.X3_Digit_Zip__c, t);
        
    //match the distributor sales 3 digit zip territory by 3 digit zip
    for(Distributor_Sales__c distsales : Trigger.new){
        distsales.Sales_Rep_for_Later_Assignment__c = DistToTerrMap.get(t.X3_Digit_Zip__c).Sales_Rep_for_Later_Assignment__c;
      }
   }
}

 
I am trying to query records using IN clause via SOAP API, but It is throwing  me the error --

'Failed to process query: MALFORMED_QUERY: SOQL statements cannot be empty or null'
Query - list contains around 550 ID's like
 SELECT id from Account where id IN ('001i000000iG2EJAA0','001i000000iGHzvAAS','001i000000iFHpbAAS','001i000000iFGYXAAW','001i000001F2hTgAAJ','001i000000iErcWAAS','00001i000000iExVNAA0','001i000000iF44RAAS','001i000000iV17RAG','001i000000iEf43AAK','001i000000iF8QQAA0','001i000000iEer3AAC')

Even the length of query is within limits (around 12k char)Can you please let me know what I am doing wrong?
  • April 26, 2016
  • Like
  • 0
Sharing this in case anyone else needs it.  Here is a formula field for clean company name. 
TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Company, 
",", " ") /*remove commas*/,
".", " ") /*remove periods*/,
" inc", "") /*remove inc*/,
" Inc", "") /*remove Inc*/,
" INC", "") /*remove INC*/,
" llc", "") /*remove llc*/,
" Llc", "") /*remove Llc*/,
" LLC", "") /*remove LLC*/,
" Ltd", "") /*remove Ltd*/,
" LTD", "") /*remove LTD*/,
"Corporation", "") /*remove Corporation*/
)

If you have an improved version please post :)