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
SkottypSkottyp 

Initial term of expression must be a concrete

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!
Best Answer chosen by Skottyp
SkottypSkottyp
Answering my own question here: This is my solution that works.
 
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() != 1)
            {
                DSzip.add(ds.X3_Digit_Zip__c);
                //system.debug('5 digits - ' + ds.X3_Digit_Zip__c);
            }      	
        }
    
    //list of territories needed to map to Distributor Sales zip
    List<Territory__c> terr = [SELECT X3_Digit_Zip__c, Sales_Rep__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip];
    List<Territory__c> terr2 =  ([SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip]);
    
    //mapping the territory info for Sales Rep
    Map <String, Id> terrMap = new Map<String, Id>();
    for(Territory__c t : terr)
    {
        terrMap.put(t.X3_Digit_Zip__c, t.Sales_Rep__c);
    }
    
    //mapping the territory info for Sales Rep for later assignment
    Map <String, Id> terrMap2 = new Map<String, Id>();
    for(Territory__c t2 : terr2)
    {
        terrMap2.put(t2.X3_Digit_Zip__c, t2.Sales_Rep_for_Later_Assignment__c);
    }
   
   //loop through and assign Sales Rep for Later Assignment
   for(Distributor_Sales__c dsnew : trigger.new)
   {
       if(dsnew.X3_Digit_Zip__c !=null)
       {
           dsnew.Sales_Rep__c  = terrMap.get(dsnew.X3_Digit_Zip__c);
    	}   
   			//system.debug('get info - ' +terrMap.get(dsnew.X3_Digit_Zip__c));
        if(dsnew.Sales_Rep__c == null)
        {
            dsnew.Sales_Rep__c = '00536000';
        }
   }
    //loop through and assign Sales Rep for Later Assignment
   for(Distributor_Sales__c dsnew2 : trigger.new)
   {
       if(dsnew2.X3_Digit_Zip__c !=null)
       {
           dsnew2.Sales_Rep_for_Later_Assignment__c  = terrMap2.get(dsnew2.X3_Digit_Zip__c);
    	}   
   			//system.debug('get info - ' +terrMap2.get(dsnew2.X3_Digit_Zip__c));
        if(dsnew2.Sales_Rep_for_Later_Assignment__c == null)
        {
            dsnew2.Sales_Rep_for_Later_Assignment__c = '00336000';
        }
   }
}

 

All Answers

Pramodh KumarPramodh Kumar
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);

The string in the map terrMap is not the 'X3_Digit_Zip__c'....its ID of that particular record.

I checked with same kind of query in org results below.
 
Map<String,contact> terrMap = new Map<String, contact> ([SELECT accountId, title,name FROM contact limit 3]);

terrMap{003i000001u9JyuAAE=Contact:{AccountId=001i000000Z8aRzAAJ, Name=Pramodh Thammishetty, Id=003i000001u9JyuAAE}, 003i000002y3FthAAE=Contact:{AccountId=001i000001cvfdWAAQ, Name=hello, Id=003i000002y3FthAAE}, 003i0000039h8otAAA=Contact:{AccountId=001i000001fBlu0AAC, Title=CEO, Name=Amanda Smith, Id=003i0000039h8otAAA}}

so in line 28 what ever you trying to do that wont get exist in the map.

Change your map query accordingly

Thanks,
pRAMODH.
 
SkottypSkottyp
Thank you for the response pRAMODH! Here is what my map displays (minus some Id characters): 
08:23:27:287 USER_DEBUG [23]|DEBUG|potentialTerr - {a00m000000=Territory__c:{X3_Digit_Zip__c=100, Sales_Rep_for_Later_Assignment__c=003m000000, Id=a00m000000}, a00m000000=Territory__c:{X3_Digit_Zip__c=113, Sales_Rep_for_Later_Assignment__c=003m000000, Id=a00m000000}, 

I have this 3 digit zip on both my Territory Object and my Distributor Sales Object and I want to use this as a way to map the territory owner (Sales Rep) from the Territory to my Distributor Sales object. Does that make sense?

DistributionSales Object.Sales Rep = terrMap2.get( X3_Digit_Zip__c ).Sales_Rep_for_Later_Assignment__c;

Something like that!
SkottypSkottyp
Answering my own question here: This is my solution that works.
 
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() != 1)
            {
                DSzip.add(ds.X3_Digit_Zip__c);
                //system.debug('5 digits - ' + ds.X3_Digit_Zip__c);
            }      	
        }
    
    //list of territories needed to map to Distributor Sales zip
    List<Territory__c> terr = [SELECT X3_Digit_Zip__c, Sales_Rep__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip];
    List<Territory__c> terr2 =  ([SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :DSzip]);
    
    //mapping the territory info for Sales Rep
    Map <String, Id> terrMap = new Map<String, Id>();
    for(Territory__c t : terr)
    {
        terrMap.put(t.X3_Digit_Zip__c, t.Sales_Rep__c);
    }
    
    //mapping the territory info for Sales Rep for later assignment
    Map <String, Id> terrMap2 = new Map<String, Id>();
    for(Territory__c t2 : terr2)
    {
        terrMap2.put(t2.X3_Digit_Zip__c, t2.Sales_Rep_for_Later_Assignment__c);
    }
   
   //loop through and assign Sales Rep for Later Assignment
   for(Distributor_Sales__c dsnew : trigger.new)
   {
       if(dsnew.X3_Digit_Zip__c !=null)
       {
           dsnew.Sales_Rep__c  = terrMap.get(dsnew.X3_Digit_Zip__c);
    	}   
   			//system.debug('get info - ' +terrMap.get(dsnew.X3_Digit_Zip__c));
        if(dsnew.Sales_Rep__c == null)
        {
            dsnew.Sales_Rep__c = '00536000';
        }
   }
    //loop through and assign Sales Rep for Later Assignment
   for(Distributor_Sales__c dsnew2 : trigger.new)
   {
       if(dsnew2.X3_Digit_Zip__c !=null)
       {
           dsnew2.Sales_Rep_for_Later_Assignment__c  = terrMap2.get(dsnew2.X3_Digit_Zip__c);
    	}   
   			//system.debug('get info - ' +terrMap2.get(dsnew2.X3_Digit_Zip__c));
        if(dsnew2.Sales_Rep_for_Later_Assignment__c == null)
        {
            dsnew2.Sales_Rep_for_Later_Assignment__c = '00336000';
        }
   }
}

 
This was selected as the best answer