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
B GhoshB Ghosh 

accessing a element

Hi all, I am newbie to Apex coding and need a help regarding this . I'm trying to execute this but its showing a strange problem.

 

The moment i access chkLead.Z_Sales_Office_Code__c the value becomes null. I've used debug statements to prove it, Here1 returns a value but Here 2 the value is null.

 

Is there any other way to achieve this ?

 

 

for(Lead chkLead :currentLeadList){
Decimal Flag=0;
//system.debug('Here 1--------'+salesRepUserIdMap.get(chkLead));
//chkLead.Z_Sales_Office_Code__c=salesRepUserIdMap.get(chkLead);
//system.debug('Here 2--------'+salesRepUserIdMap.get(chkLead));
for(Z_Sales_Office_Code_Default__c teamAssRec: teamAssignList){

if(salesRepUserIdMap.get(chkLead)==teamAssRec.name && teamAssRec.Z_Sales_Office_Type__c=='REN'){
if(chkLead.z_product_type__c=='Display'){
chkLead.OwnerId=displaySalesMap.get( salesRepUserIdMap.get(chkLead));
Flag=1;
}
else{
chkLead.OwnerId=semiSalesMap.get( salesRepUserIdMap.get(chkLead));
Flag=1;
}

}

 

 

 

Thanks a lot

Jerun JoseJerun Jose
Shouldnt be happening. Could you post the code that you executed and debug log for that execution. It would help if you could set the logging level to fine for apex code.
Richa KRicha K

Are you properly closing the opening for loop braces. I know it should not be the case, but still wondering.

Leon MorockiLeon Morocki

How do you declare the salesRepUserIdMap variable?

 

If the keys in the map are Lead objects, you cannot expect the map's get method to return the same value after you change the Lead's field (because effectively you are then changing the map's key and technically the Lead after change is not equal to the Lead before the change). Optionally you can override the equals method to return the same value regardless of the value of the field you are changing (Z_Sales_Office_Code__c)