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
LaurentDelcambreLaurentDelcambre 

Exception on apex:map when re-rendering

Hi,


When re-rendering the parent element of a apex:map, I get this error message displayed instead of the map:
"HTTP ERROR 401  Problem accessing /maps/JavascriptHandler. Reason:      Unauthorized Powered by Jetty://".

It works fine on the first loading. Any idea?
Deepu BDeepu B
Which Edition are you using? I hope it won't work on developer edition.
Sasha_SFDCSasha_SFDC
@LaurentDelcambre Can you please provide the sample of the code that you're using on your Visualforce page to display and re-render a map? 
mfawcettmfawcett
Did you find the reason for this error, I am having the same issue .
 
Sasha_SFDCSasha_SFDC
@mfawcett Can you please provide the code that you'r using when you experience this error? 
mfawcettmfawcett
Hello Sasha

I found the cause of that exception and it is because there is a limit for 10 geocoding requests per map. I was able to work around this issue calculating the geocode first and then setting the latitude and longitude in the postion.

However this is working fine in my sandbox (winter 16), but I am not getting the same result in production, under this environment I have to set limit 10 in the SOQL.

Sandbox:---------
    public PageReference Nearby()
      {
     rend = true;
      try{
            objAccounts = new list<Account>();  
            objAccounts.addAll([SELECT Name,BillingStreet,BillingCity,BillingPostalCode,
                                BillingCountry,Phone,BillingState,Location__Latitude__s,Location__Longitude__s  FROM Account 
                                Where BillingState =: centerstate and Location__Latitude__s <> null order by Name  ]);
        }catch(Exception ex){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'
                                                        +ex.getMessage()));
         }
     return null;
   }

Production:--------
 public PageReference Nearby()
    
   {
     rend = true;
      try{
            objAccounts = new list<Account>();  
            objAccounts.addAll([SELECT Name,BillingStreet,BillingCity,BillingPostalCode,
                                BillingCountry,Phone,BillingState,Location__Latitude__s,Location__Longitude__s  FROM Account 
                                Where BillingState =: centerstate and Location__Latitude__s <> null order by Name limit 10 ]);
        }catch(Exception ex){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'
                                                        +ex.getMessage()));
         }
     return null;
   }


Thanks
Sasha_SFDCSasha_SFDC
Thanks, @mfawcett. I tried to reproduce this issue in production, but so far I don't get any errors even with more than 10 markers.

Can you please also post the Visualforce page code, or at least the part that is related to the map and map re-rendering? 
mfawcettmfawcett
Here is my code:

<apex:outputPanel id="Map" >
 <apex:pageBlockSection Title="GRCS Fund Managers Location Center Point: {!city} {!state} {!country} " rendered="{!IF(rend, true , false)}" columns="1" collapsible="False">    
  
  <apex:map width="1595px" height="500px" mapType="roadmap" center="{!city},{!state},{!country}"> 
       <!--  center="{latitude: 40.7638848, longitude: -73.9707834}"> -->
 
      <!-- Add markers for account  -->
      <apex:repeat value="{! objAccounts }" var="ct">
        <apex:mapMarker title="{! ct.Name }"  position="{latitude:{!ct.Location__Latitude__s},longitude:{!ct.Location__Longitude__s}}">
        </apex:mapMarker>
      </apex:repeat>

      </apex:map>
    
    </apex:pageBlockSection>
  </apex:outputPanel>  
  </apex:pageBlock>
  </apex:form>  
</apex:page>


here is the controller:
 
Sasha_SFDCSasha_SFDC
Looks like parts of your post are missing - the top of the VF pages and the controller.
mfawcettmfawcett
Ok here is the code:
<apex:page Controller="GRCSAccountList">
<apex:pagemessages id="ErrMsg"></apex:pagemessages>
 <apex:form >
  <apex:pageBlock >
    <apex:pageBlockButtons location="top">
       <apex:commandButton value="Nearby Accounts/Fund Managers" action="{!Nearby}"  id="theButton" rerender="Map,ErrMsg"/>
    </apex:pageBlockButtons>
   <apex:pageBlockSection title="Enter Center Location" columns="1" collapsible="False">
                <apex:pageblockSectionItem >
                    <apex:outputLabel value="Country"/>
                </apex:pageblockSectionItem>        
                <apex:pageblockSectionItem >                
                    <apex:selectList size="1" value="{!country}">
                        <apex:selectOptions value="{!objcountries}"/>
                        <apex:actionSupport event="onchange" reRender="a,c"/> 
                    </apex:selectList>                
                </apex:pageblockSectionItem>
                
                <apex:pageblockSectionItem >
                    <apex:outputLabel value="State"/>
                </apex:pageblockSectionItem>            
                <apex:pageblockSectionItem >
                    <apex:selectList size="1" value="{!state}" id="a">
                        <apex:selectOptions value="{!states}"/>
                        <apex:actionSupport event="onchange" reRender="c"/> 
                    </apex:selectList>
                </apex:pageblockSectionItem>            
                
                <apex:pageblockSectionItem >
                    <apex:outputLabel value="City"/>
                </apex:pageblockSectionItem>            
                <apex:pageblockSectionItem >
                    <apex:selectList size="1" value="{!City}" id="c" >
                        <apex:selectOptions value="{!Cities}"/>
                    </apex:selectList>
                </apex:pageblockSectionItem>   
                
               </apex:pageBlockSection>

  
<apex:outputPanel id="Map" >
 <apex:pageBlockSection Title="GRCS Fund Managers Location Center Point: {!city} {!state} {!country} " rendered="{!IF(rend, true , false)}" columns="1" collapsible="False">    
  
  <apex:map width="1595px" height="500px" mapType="roadmap" center="{!city},{!state},{!country}"> 
       <!--  center="{latitude: 40.7638848, longitude: -73.9707834}"> -->
 
      <!-- Add markers for account contacts -->
      <apex:repeat value="{! objAccounts }" var="ct">
        <apex:mapMarker title="{! ct.Name }"  position="{latitude:{!ct.Location__Latitude__s},longitude:{!ct.Location__Longitude__s}}">
        </apex:mapMarker>
      </apex:repeat>
   </apex:map>
    </apex:pageBlockSection>
  </apex:outputPanel>  
  </apex:pageBlock>
  </apex:form>  
</apex:page>


-------------------------------------------------< Controller >-------------------------------------------------------------
public with sharing class GRCSAccountList {

public list<Account> objAccounts {get;set;}
public string country {get;set;}
public string state {get;set;}
public string City {get;set;}
public string query {get;set;}

public boolean rend {get;set;}


    public GRCSAccountList()
     {}

   public PageReference Nearby()
   { string acsubtype = 'FOF Public Market Alternative';
        query = 'SELECT Name,BillingStreet,BillingCity,BillingPostalCode,BillingCountry,Phone,BillingState,Location__Latitude__s,Location__Longitude__s  FROM Account Where Location__Latitude__s <> null and AC_Sub_Type__c = \'' + acsubtype +'\'';
     rend = true;
      try{
            objAccounts = new list<Account>();  
            
           if (country != 'None' && country != null)
              { query = query + ' and BillingCountry =: country';} 
              
          if (state != 'None' && state != null)
              { query = query + ' and BillingState =: state';} 
              
          if (city != 'None' && city != null)
              { query = query + ' and BillingCity =: city';} 
                      
              system.debug('Query -->' + query);
            objAccounts = (Database.query(query));
                                
        }catch(Exception ex){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'
                                                        +ex.getMessage()));
         }
     return null;
   }
   
    
    public list<SelectOption> getobjcountries()
     {
         List<SelectOption> ccountry = new List<SelectOption>();
        ccountry.add(new SelectOption('None','--- Select ---'));
        list<AggregateResult> results = [SELECT BillingCountry FROM Account where BillingCountry != null and AC_Sub_Type__c = 'FOF Public Market Alternative' group by BillingCountry];
        system.debug(country);
         for (AggregateResult cont : results)
         {
            ccountry.add( new SelectOption(String.valueof(cont.get('BillingCountry')),String.valueof(cont.get('BillingCountry'))));
         }  
        return ccountry;
     }
    
    public List<SelectOption> getStates()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','--- Select ---'));
        if(country != null && country != 'None')
        {
            
         list<AggregateResult> results = [SELECT BillingState FROM Account where BillingState != null and BillingCountry=:country and AC_Sub_Type__c = 'FOF Public Market Alternative' group by BillingState];
         for (AggregateResult cont : results)
         {
            options.add( new SelectOption(String.valueof(cont.get('BillingState')),String.valueof(cont.get('BillingState'))));
         }
        }  
        return options;

    }
    
     public List<SelectOption> getCities()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','--- Select ---'));
        if (state != 'None' && state != null)
        {  system.debug('City---->' +  city);
          
           list<AggregateResult> results = [SELECT BillingCity FROM Account where BillingCity != null and BillingState =: state and BillingCountry=:country and AC_Sub_Type__c = 'FOF Public Market Alternative' group by BillingCity];
             for (AggregateResult cont : results)
             {
                options.add( new SelectOption(String.valueof(cont.get('BillingCity')),String.valueof(cont.get('BillingCity'))));
             }
        }
               
         return options;

    }
    
}
Jeff Harris 11Jeff Harris 11
I had the Unauthorized 401 error also when using apex:map.  In my case the error was caused when the code attempted to access a data field (e.g., account name) with consecutive spaces, e.g., "My  Company".  When corrected to "My Company" (with only one space between tokens) everything was ok.  I'm submitting the bug to SF now.
Sasha_SFDCSasha_SFDC
Jeff,
       What is your browser encoding set to when you run into this issue?
Jeff Harris 11Jeff Harris 11
Browser text encoding on Firefox 42.0 is Unicode.
Sasha_SFDCSasha_SFDC
Thank you Jeff. Is this a separate VF page with map or a part of the account layout? Also, do you see this error when the page is loaded, or when some part of the page is re-rendered?
Jeff Harris 11Jeff Harris 11
This occurs on both initial page load and re-rendering.  This is a custom VF page with a map.

Thanks.
Sasha_SFDCSasha_SFDC
Thank you Jeff. And are you using the account name in marker title or in info window? It would be great if you could give a code sample.
Jeff Harris 11Jeff Harris 11
Let me revise my previous statement.  The page I have with the error doesn't generate a map on page load.  The map is always generated thru a command button, so technically I suppose it's on rerender.

The error can occur when using account name or site in either a mapMarker or mapInfoWindow.

Sample code:

<apex:map width="600px" height="400px" mapType="roadmap" rendered="{!isCalJobs}">
<apex:repeat var="mapjob" value="{!calJobs}">
    <apex:mapMarker title="{!mapjob.Account__r.Name} - {!mapjob.Account__r.Site}" position="{latitude:{!mapjob.Account__r.geopointe__Geocode__r.geopointe__Latitude__c}, longitude:{!mapjob.Account__r.geopointe__Geocode__r.geopointe__Longitude__c}}" rendered="true">
        <apex:mapInfoWindow >
            <apex:outputPanel layout="block">
                <apex:outputText value="{!mapjob.Account__r.Name} - {!mapjob.Account__r.Site}"/>
            </apex:outputPanel>
            <apex:outputPanel layout="block">
                <apex:outputText value="{!mapjob.Account__r.ShippingCity}, {!mapjob.Account__r.ShippingState}"/>
            </apex:outputPanel>
            <apex:outputPanel layout="block">
                <apex:outputText value="Dates: {0,date,MM/dd/yy} - {1,date,MM/dd/yy}">
                    <apex:param value="{!mapjob.Start_Date__c}"/>
                    <apex:param value="{!mapjob.End_Date__c}"/>
                </apex:outputText>
            </apex:outputPanel>
            <apex:outputPanel layout="block">
                <apex:outputText value="Days: {!mapjob.Billing_Days__c}"/>
            </apex:outputPanel>
            <apex:outputPanel layout="block">
                <apex:outputText value="Job No.: {!mapjob.Name}"/>
            </apex:outputPanel>
            <apex:outputPanel layout="block">
                <apex:outputText value="Status: {!mapjob.Status__c}"/>
            </apex:outputPanel>
        </apex:mapInfoWindow>
    </apex:mapMarker>
</apex:repeat>
</apex:map>
Jeff Harris 11Jeff Harris 11
Here is a self-contained visualforce page that demonstrates the issue.

To reproduce the issue:
  1. Create an account with a name with consecutive spaces, e.g., "My  Company"
  2. Implement a visualforce page using code below, calling it, say, "MyTest"
  3. Open this page by navigating to: http://<my_sf_instance>>/MyTest?Id=<account_id>
  4. At this point the map will display properly
  5. Click the "Rerender Map" button, which rerenders the map
  6. The 401, unauthorized error will appear
<apex:page standardController="Account">
  <apex:pageBlock >
    <apex:pageBlockSection title="{! Account.Name } Location">
     <apex:outputPanel >
          <apex:outputField value="{!Account.Site}"/><br/>
      </apex:outputPanel>

      <apex:form>
      <apex:commandButton value="Rerender Map" id="theButton" reRender="mapSectionId"/>
      </apex:form>
           
      <!-- Display the address on a map -->
      <apex:pageBlock id="mapSectionId" title="Test Map">
        <apex:map width="600px" height="400px" mapType="roadmap" center="{latitude: 40.7638848, longitude: -73.9707834}">
          <apex:mapMarker title="{!Account.Name}"
          position="{latitude: 40.7638848, longitude: -73.9707834}">
          </apex:mapMarker>
        </apex:map>
      </apex:pageBlock>
       
      </apex:pageBlockSection>
  </apex:pageBlock>   
</apex:page>

 
Jeff Harris 11Jeff Harris 11
One correction to Step 3: the URL should be: http://<my_sf_instance>>/apex/MyTest?Id=<account_id>
Sasha_SFDCSasha_SFDC
Thank you Jeff, this is a great repro case! Please submit this issue with the repro steps, it is definitely a bug.
Jeff Harris 11Jeff Harris 11
Stupid question: how do I submit the issue?  Help & Training support cases area doesn't allow Development issues for Standard customers, it refers me back here.
Sasha_SFDCSasha_SFDC


Jeff,

   I submitted the issue on your behalf. Here is a link to it: https://success.salesforce.com/issues_view?id=a1p300000008c2YAAQ. You can subscribe to this issue by clicking "This Issue Affects me" button.

   Thank you!