• pixelriese
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hello, i have the problem that i would like to calucute exact distance between a lead and a list of accounts. I'm currently use a visual force page with a map component and i am use a standard function distance() to calculate the distance. Has someone an idea how to solve this issue? I would like to use a JavaScript-FrameWork or google Maps API. 
public class ldController {
    public Lead leadRecord{get;set;}
   
    public ldController(ApexPages.StandardController sc){
     this.leadRecord = (Lead) sc.getRecord();        
    }
     
	Double leadLatitude = leadRecord.Latitude;
    Double leadLongitude = leadRecord.Longitude;
    
    List<Account> acc = new List<Account>();


    public List<Account> getAccounts(){
        Acc = Database.query('SELECT Id, Name, ShippingLatitude, ShippingLongitude, Phone FROM Account WHERE RecordTypeId=:\'01258000000ATCX\' AND DISTANCE(LOCATION(' + leadLatitude + ', ' + leadLongitude + ' ), LOCATION(ShippingLatitude, ShippingLongitude),\'km\') limit 20');    
        return Acc;
    }
}
 
<apex:page standardController="Lead" extensions="ldController">
    <apex:form >
        <apex:pageBlock title="Lead Information">
            <apex:pageBlockSection title="Details" columns="1">
               
                 Name: {! leadRecord .name} <br />
                Phone: {! leadRecord .Phone} <br />
                
            <apex:commandButton action="{! save}" value="Save"/>    
            </apex:pageBlockSection>
             <apex:pageBlockSection title="Accounts" id="results" >       
            <apex:pageBlockTable value="{!accounts}" var="a" >
            <apex:column value="{!a.id}"/>
            <apex:column value="{!a.name}"/>    
            <apex:column value="{!a.phone}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>
</apex:page>


I would like display a list which shows the nearst customers. I add a Button to the lead - pagelayout. but when i click on it, it thorws an exception :

 

Visualforce Page: /apex/ShowNearLeads



caused by: System.NullPointerException: Attempt to de-reference a null object

Class.ldController.<init>: line 8, column 1

Debug Log:
38.0 APEX_CODE,FINE;APEX_PROFILING,FINE;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,FINE;WORKFLOW,INFO
12:54:50.0 (324935)|USER_INFO|[EXTERNAL]|005580000010hIq|osrc@viessmann.com.dev1|Mitteleuropäische Normalzeit|GMT+01:00
12:54:50.0 (369104)|EXECUTION_STARTED
12:54:50.0 (374755)|CODE_UNIT_STARTED|[EXTERNAL]|0666E0000004CoG|VF: /apex/ShowNearLeads
12:54:50.0 (5930161)|VF_APEX_CALL_START|[EXTERNAL]|01p6E000000Ce2l|ldController <init>
12:54:50.0 (5944369)|SYSTEM_MODE_ENTER|true
12:54:50.0 (6376576)|METHOD_ENTRY|[1]|01p6E000000Ce2l|ldController.ldController()
12:54:50.0 (6389953)|METHOD_EXIT|[1]|ldController
12:54:50.0 (6677559)|EXCEPTION_THROWN|[8]|System.NullPointerException: Attempt to de-reference a null object
12:54:50.0 (7009926)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.ldController.<init>: line 8, column 1
12:54:50.0 (7108339)|VF_APEX_CALL_END|ldController <init>
12:54:50.19 (19837942)|CUMULATIVE_PROFILING_BEGIN
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for SOQL operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for SOSL operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for DML operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|method invocations|
External entry point: public void <init>(ApexPages.StandardController): executed 1 time in 1 ms
Class.ldController.<init>: line 8, column 1: public Lead __sfdc_leadRecord(): executed 1 time in 0 ms

12:54:50.19 (19837942)|CUMULATIVE_PROFILING_END

 

Can someone help me ?

Hello, i have the problem that i would like to calucute exact distance between a lead and a list of accounts. I'm currently use a visual force page with a map component and i am use a standard function distance() to calculate the distance. Has someone an idea how to solve this issue? I would like to use a JavaScript-FrameWork or google Maps API. 
public class ldController {
    public Lead leadRecord{get;set;}
   
    public ldController(ApexPages.StandardController sc){
     this.leadRecord = (Lead) sc.getRecord();        
    }
     
	Double leadLatitude = leadRecord.Latitude;
    Double leadLongitude = leadRecord.Longitude;
    
    List<Account> acc = new List<Account>();


    public List<Account> getAccounts(){
        Acc = Database.query('SELECT Id, Name, ShippingLatitude, ShippingLongitude, Phone FROM Account WHERE RecordTypeId=:\'01258000000ATCX\' AND DISTANCE(LOCATION(' + leadLatitude + ', ' + leadLongitude + ' ), LOCATION(ShippingLatitude, ShippingLongitude),\'km\') limit 20');    
        return Acc;
    }
}
 
<apex:page standardController="Lead" extensions="ldController">
    <apex:form >
        <apex:pageBlock title="Lead Information">
            <apex:pageBlockSection title="Details" columns="1">
               
                 Name: {! leadRecord .name} <br />
                Phone: {! leadRecord .Phone} <br />
                
            <apex:commandButton action="{! save}" value="Save"/>    
            </apex:pageBlockSection>
             <apex:pageBlockSection title="Accounts" id="results" >       
            <apex:pageBlockTable value="{!accounts}" var="a" >
            <apex:column value="{!a.id}"/>
            <apex:column value="{!a.name}"/>    
            <apex:column value="{!a.phone}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>
</apex:page>


I would like display a list which shows the nearst customers. I add a Button to the lead - pagelayout. but when i click on it, it thorws an exception :

 

Visualforce Page: /apex/ShowNearLeads



caused by: System.NullPointerException: Attempt to de-reference a null object

Class.ldController.<init>: line 8, column 1

Debug Log:
38.0 APEX_CODE,FINE;APEX_PROFILING,FINE;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,FINE;WORKFLOW,INFO
12:54:50.0 (324935)|USER_INFO|[EXTERNAL]|005580000010hIq|osrc@viessmann.com.dev1|Mitteleuropäische Normalzeit|GMT+01:00
12:54:50.0 (369104)|EXECUTION_STARTED
12:54:50.0 (374755)|CODE_UNIT_STARTED|[EXTERNAL]|0666E0000004CoG|VF: /apex/ShowNearLeads
12:54:50.0 (5930161)|VF_APEX_CALL_START|[EXTERNAL]|01p6E000000Ce2l|ldController <init>
12:54:50.0 (5944369)|SYSTEM_MODE_ENTER|true
12:54:50.0 (6376576)|METHOD_ENTRY|[1]|01p6E000000Ce2l|ldController.ldController()
12:54:50.0 (6389953)|METHOD_EXIT|[1]|ldController
12:54:50.0 (6677559)|EXCEPTION_THROWN|[8]|System.NullPointerException: Attempt to de-reference a null object
12:54:50.0 (7009926)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.ldController.<init>: line 8, column 1
12:54:50.0 (7108339)|VF_APEX_CALL_END|ldController <init>
12:54:50.19 (19837942)|CUMULATIVE_PROFILING_BEGIN
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for SOQL operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for SOSL operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for DML operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|method invocations|
External entry point: public void <init>(ApexPages.StandardController): executed 1 time in 1 ms
Class.ldController.<init>: line 8, column 1: public Lead __sfdc_leadRecord(): executed 1 time in 0 ms

12:54:50.19 (19837942)|CUMULATIVE_PROFILING_END

 

Can someone help me ?