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
Shruti NigamShruti Nigam 

Hi I want to perform this scenario Multiple sales representatives can be assigned to the same zip code territory. If this is the case, use a random function to select one of the assigned sales representatives

Hi I want to perform this scenario Multiple sales representatives can be assigned to the same zip code territory. If this is the case, use a random function to select one of the assigned sales representatives  Object is Territory__c
Inside this object : 
Records  
Zip CodeSales Representative
91000Blake
91001Blake
91002Blake
91002Jacqueline
91010Jacqueline
91020Jacqueline
92010Denise
92020Aaron
           Can anyone please help me out??
Navin Selvaraj23Navin Selvaraj23
Hi Shruthi,

You have to use two maps to achieve this functionality.
 
Map<Integer,String> mapOne = new Map<Integer,String>();
mapOne .put(1,'91000');
mapOne .put(2,'91001');
mapOne .put(3,'91002');
mapOne .put(4,'91003');
Map<String,String> mapTwo = new Map<String,String>();
mapTwo .put('91000','Blake');
mapTwo .put('91001','Jacqueline');
mapTwo .put('91002','Denise');
mapTwo .put('91003','Aaron');

Integer randomNumber = Integer.valueof((Math.random() * mapOne.keySet().size()));
System.debug('randomNumber  is'+randomNumber);

String Salesrep = mapTwo.get(mapOne.get(randomNumber ));
System.debug("Salesrep : " + Salesrep);

Hope this example code helps to achieve your functionality. Mark it as best answer if it helps.


Regards,
Navin S
SunnyalexSunnyalex
when i am running this code it is showing 
Line: 15, Column: 8
Unexpected token 'Sales'.