• puneet-mishra
  • NEWBIE
  • 40 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 10
    Replies
Hi all,

I am using Google Geocoding api v3 to get latitude and longitude of the address present on my record and I am able to do so but
sometimes I get "OVER QUERY LIMIT" as error message even though I am not exceeding the api limits which is 2500 request per 24 hrs.
And I am requesting geocode for 1 address only i.e. not running a loop. I am not able to figure it out why this so

  User-added image

Below is the class using which I make callouts

public Class LocationCallOuts {
   
    /**
     *  DESCRIPTION   :    This method will create Address to be passed to get Latitude and Longitude of Address provided.
     *                     This method will also check that street name is not null, If street name is null then request is not made
     */
    public static void checkAddress(List<Risk_Location__c> riskLocationList) {
        List<Risk_Location__c> locationList = new List<Risk_Location__c>();
        List<Risk_Location__c> addressNotFound = new List<Risk_Location__c>();
        String streetValue;
        LocationCallOuts riskLocCall = new LocationCallOuts();
        for(Risk_Location__c riskLoc : riskLocationList) {
           
            streetValue = riskLocCall.GetStreetName(riskLoc);
            if(streetValue != null && streetValue != '') {
                locationList.add(riskLoc);
            } else {
                riskLoc.Address_Not_Found__c = true;
                addressNotFound.add(riskLoc);
            }
        }
        if( addressNotFound.size() > 0) {
           
            update addressNotFound;
        }
        if( locationList.size() >0 ) {
            riskLocCall.GetLocation(locationList);
        }
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Street Number.
     */
    @TestVisible private String GetStreetNumber (Risk_Location__c locStreetNumber) {
        String streetNumber = '';
        if(locStreetNumber.Street_Number__c != null && locStreetNumber.Street_Number__c != '') {
            streetNumber += locStreetNumber.Street_Number__c + ',';
        }
        return streetNumber;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Street Name.
     */
    @TestVisible private String GetStreetName (Risk_Location__c locStreetName) {
        String streetName ='';
        if(locStreetName.Location__c != null && locStreetName.Location__c != '') {
            streetName += locStreetName.Location__c + ',';
        }
        return streetName;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Suburb.
     */
    @TestVisible private String GetSuburb (Risk_Location__c locSuburb) {
        String suburbName = '';
        if(locSuburb.Suburb__c != null && locSuburb.Suburb__c != '') {
            suburbName += locSuburb.Suburb__c + ',';
        }
        return suburbName;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return State.
     */
    @TestVisible private String GetState (Risk_Location__c locState) {
        String stateName = '';
        if(locState.State__c != null && locState.State__c != '') {
            stateName += locState.State__c + ',';
        }
        return stateName;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Country.
     */
    @TestVisible private String GetCountry (Risk_Location__c locCountry) {
        String countryName = '';
        if(locCountry.Country__c != null && locCountry.Country__c != '') {
            countryName += locCountry.Country__c + '}';
        }
        return countryName;
    }
   
    /**
     *  DESCRIPTION   :    This method is called to make request to Google with the address and get the Latitude and Longitude and update Risk Location records
     */
     @TestVisible private void GetLocation(List<Risk_Location__c> riskLocationList) {
         double lat = null;
         double lng = null;
         String address = '';
         String formattedAddress = '';
         List<String> splitAddress;
         Risk_Location__c riskLocation = new Risk_Location__c();
        
         for( Risk_Location__c riskLoc : riskLocationList ) {
             splitAddress = new List<String>();
            
             address += '{';
             address += GetStreetNumber(riskLoc);
             address += GetStreetName(riskLoc);
             address += GetSuburb(riskLoc);
             address += GetState(riskLoc);
             address += GetCountry(riskLoc);
            
             Http h = new Http();
             HttpRequest req = new HttpRequest();
             req.setEndpoint('http://maps.googleapis.com/maps/api/geocode/json?address='+address+'&sensor=true');
             req.setMethod('GET');
            
             try {
                 HttpResponse res = h.send(req);
                
                 JSONParser parser = JSON.createParser(res.getBody());
                 system.debug('********* Resquest Body ********' + res.getBody());
                 Boolean addressFlag = false;
                 Boolean latlngFlag = false;
                 while(parser.nextToken() != null ) {
                    
                     if((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'formatted_address') && addressFlag == false ) {
                        parser.nextToken();
                        formattedAddress = parser.getText();
                        addressFlag = true;
                     }
                     if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'location') && latlngFlag == false ) {
                           parser.nextToken();
                           while (parser.nextToken() != JSONToken.END_OBJECT) {
                               String txt = parser.getText();
                               parser.nextToken();
                               if (txt == 'lat')
                                   lat = parser.getDoubleValue();
                               else if (txt == 'lng')
                                   lng = parser.getDoubleValue();
                               if(lat != null && lng != null)
                                    latlngFlag = true;
                           } // End of Inner While Loop
                    }
                 }// End of while Loop
                
                 splitAddress = address.split(',');
                 // If Lat and Lng is not Null and Formatted address is same as Provided, populate Google Address, Address_Not_Found__c and Approximate_Address__c on Risk Location
                 if( lat != null && lng != null ) {
                     // If Formatted address from Google is same as Address on Risk Location, populate Lat, Lng, Google Address and Uncheck Approximate_Address__c and Address_Not_Found__c
                     if((formattedAddress.toUpperCase()).contains((splitAddress[1].toUpperCase())) && (formattedAddress.toUpperCase()).contains((splitAddress[2].toUpperCase())) &&
                        ((formattedAddress.toUpperCase()).contains(('AU')) || (formattedAddress.toUpperCase()).contains(('AUS')) || (formattedAddress.toUpperCase()).contains(('AUSTRALIA')))) {
                        riskLoc.Geolocation__Latitude__s = lat;
                        riskLoc.Geolocation__Longitude__s = lng;
                        riskLoc.Google_Address__c = formattedAddress;
                        riskLoc.Approximate_Address__c = false;
                        riskLoc.Address_Not_Found__c = false;
                     }
                     // If Formatted Address is not same as Address on Risk Location then Polpulate Lat,Lng,Google Address and Check Approximate_Address true and Address_Not_Found = false
                     else {
                        riskLoc.Geolocation__Latitude__s = lat;
                        riskLoc.Geolocation__Longitude__s = lng;
                        riskLoc.Approximate_Address__c = true;
                        riskLoc.Address_Not_Found__c = false;
                        riskLoc.Google_Address__c = formattedAddress;
                     }
                 }
                 // If Lat Lng is Null then Clear Google Address, Lat, Lng and Check Address_Not_Found = true and Approximate_Address = false
                 else {
                    riskLoc.Geolocation__Latitude__s = lat;
                    riskLoc.Geolocation__Longitude__s = lng;
                    riskLoc.Google_Address__c = '';
                    riskLoc.Approximate_Address__c = false;
                    riskLoc.Address_Not_Found__c = true;
                 }
             } catch( Exception e) {
                 system.debug('== Exception Occured ====' + e.getMessage());
             }
             address = '';
         } // End of For Loop
       
         update riskLocationList;
     } // End of Method
    
}

Please help me with this

I have a report including some fields (checkbox) and when it is exported to excel, the value on this fiels is either 1 or 0 depending if the box is checked or not.  The users don't want to se numbers they want to see:  1= Yes or 0=No.  Do you know if there is any way to change the values of the checkbox when exporting?

Hi all, 

 

While working on a report,i come across an issue.If Long Text Area field is used in report, only FIRST 255 CHARACTERS are displayed in REPORT.
But My requirement is that,all characters must be display in report.If not all,at least 1000 characters should be display.
If any body have any sugession regarding this,please help me.Waiting for your replies.

 

Thanks

Problem:- if i assign my user to a queue and then i want when new record is created for my object ( let it be Incident having field which has lookup on User) a field (let name it "Queue") should get autopopulated, how this can be acheived if i don't want to write trigger,

Hi all,

I am using Google Geocoding api v3 to get latitude and longitude of the address present on my record and I am able to do so but
sometimes I get "OVER QUERY LIMIT" as error message even though I am not exceeding the api limits which is 2500 request per 24 hrs.
And I am requesting geocode for 1 address only i.e. not running a loop. I am not able to figure it out why this so

  User-added image

Below is the class using which I make callouts

public Class LocationCallOuts {
   
    /**
     *  DESCRIPTION   :    This method will create Address to be passed to get Latitude and Longitude of Address provided.
     *                     This method will also check that street name is not null, If street name is null then request is not made
     */
    public static void checkAddress(List<Risk_Location__c> riskLocationList) {
        List<Risk_Location__c> locationList = new List<Risk_Location__c>();
        List<Risk_Location__c> addressNotFound = new List<Risk_Location__c>();
        String streetValue;
        LocationCallOuts riskLocCall = new LocationCallOuts();
        for(Risk_Location__c riskLoc : riskLocationList) {
           
            streetValue = riskLocCall.GetStreetName(riskLoc);
            if(streetValue != null && streetValue != '') {
                locationList.add(riskLoc);
            } else {
                riskLoc.Address_Not_Found__c = true;
                addressNotFound.add(riskLoc);
            }
        }
        if( addressNotFound.size() > 0) {
           
            update addressNotFound;
        }
        if( locationList.size() >0 ) {
            riskLocCall.GetLocation(locationList);
        }
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Street Number.
     */
    @TestVisible private String GetStreetNumber (Risk_Location__c locStreetNumber) {
        String streetNumber = '';
        if(locStreetNumber.Street_Number__c != null && locStreetNumber.Street_Number__c != '') {
            streetNumber += locStreetNumber.Street_Number__c + ',';
        }
        return streetNumber;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Street Name.
     */
    @TestVisible private String GetStreetName (Risk_Location__c locStreetName) {
        String streetName ='';
        if(locStreetName.Location__c != null && locStreetName.Location__c != '') {
            streetName += locStreetName.Location__c + ',';
        }
        return streetName;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Suburb.
     */
    @TestVisible private String GetSuburb (Risk_Location__c locSuburb) {
        String suburbName = '';
        if(locSuburb.Suburb__c != null && locSuburb.Suburb__c != '') {
            suburbName += locSuburb.Suburb__c + ',';
        }
        return suburbName;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return State.
     */
    @TestVisible private String GetState (Risk_Location__c locState) {
        String stateName = '';
        if(locState.State__c != null && locState.State__c != '') {
            stateName += locState.State__c + ',';
        }
        return stateName;
    }
   
    /**
     *  DESCRIPTION :       This method will be called to return Country.
     */
    @TestVisible private String GetCountry (Risk_Location__c locCountry) {
        String countryName = '';
        if(locCountry.Country__c != null && locCountry.Country__c != '') {
            countryName += locCountry.Country__c + '}';
        }
        return countryName;
    }
   
    /**
     *  DESCRIPTION   :    This method is called to make request to Google with the address and get the Latitude and Longitude and update Risk Location records
     */
     @TestVisible private void GetLocation(List<Risk_Location__c> riskLocationList) {
         double lat = null;
         double lng = null;
         String address = '';
         String formattedAddress = '';
         List<String> splitAddress;
         Risk_Location__c riskLocation = new Risk_Location__c();
        
         for( Risk_Location__c riskLoc : riskLocationList ) {
             splitAddress = new List<String>();
            
             address += '{';
             address += GetStreetNumber(riskLoc);
             address += GetStreetName(riskLoc);
             address += GetSuburb(riskLoc);
             address += GetState(riskLoc);
             address += GetCountry(riskLoc);
            
             Http h = new Http();
             HttpRequest req = new HttpRequest();
             req.setEndpoint('http://maps.googleapis.com/maps/api/geocode/json?address='+address+'&sensor=true');
             req.setMethod('GET');
            
             try {
                 HttpResponse res = h.send(req);
                
                 JSONParser parser = JSON.createParser(res.getBody());
                 system.debug('********* Resquest Body ********' + res.getBody());
                 Boolean addressFlag = false;
                 Boolean latlngFlag = false;
                 while(parser.nextToken() != null ) {
                    
                     if((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'formatted_address') && addressFlag == false ) {
                        parser.nextToken();
                        formattedAddress = parser.getText();
                        addressFlag = true;
                     }
                     if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'location') && latlngFlag == false ) {
                           parser.nextToken();
                           while (parser.nextToken() != JSONToken.END_OBJECT) {
                               String txt = parser.getText();
                               parser.nextToken();
                               if (txt == 'lat')
                                   lat = parser.getDoubleValue();
                               else if (txt == 'lng')
                                   lng = parser.getDoubleValue();
                               if(lat != null && lng != null)
                                    latlngFlag = true;
                           } // End of Inner While Loop
                    }
                 }// End of while Loop
                
                 splitAddress = address.split(',');
                 // If Lat and Lng is not Null and Formatted address is same as Provided, populate Google Address, Address_Not_Found__c and Approximate_Address__c on Risk Location
                 if( lat != null && lng != null ) {
                     // If Formatted address from Google is same as Address on Risk Location, populate Lat, Lng, Google Address and Uncheck Approximate_Address__c and Address_Not_Found__c
                     if((formattedAddress.toUpperCase()).contains((splitAddress[1].toUpperCase())) && (formattedAddress.toUpperCase()).contains((splitAddress[2].toUpperCase())) &&
                        ((formattedAddress.toUpperCase()).contains(('AU')) || (formattedAddress.toUpperCase()).contains(('AUS')) || (formattedAddress.toUpperCase()).contains(('AUSTRALIA')))) {
                        riskLoc.Geolocation__Latitude__s = lat;
                        riskLoc.Geolocation__Longitude__s = lng;
                        riskLoc.Google_Address__c = formattedAddress;
                        riskLoc.Approximate_Address__c = false;
                        riskLoc.Address_Not_Found__c = false;
                     }
                     // If Formatted Address is not same as Address on Risk Location then Polpulate Lat,Lng,Google Address and Check Approximate_Address true and Address_Not_Found = false
                     else {
                        riskLoc.Geolocation__Latitude__s = lat;
                        riskLoc.Geolocation__Longitude__s = lng;
                        riskLoc.Approximate_Address__c = true;
                        riskLoc.Address_Not_Found__c = false;
                        riskLoc.Google_Address__c = formattedAddress;
                     }
                 }
                 // If Lat Lng is Null then Clear Google Address, Lat, Lng and Check Address_Not_Found = true and Approximate_Address = false
                 else {
                    riskLoc.Geolocation__Latitude__s = lat;
                    riskLoc.Geolocation__Longitude__s = lng;
                    riskLoc.Google_Address__c = '';
                    riskLoc.Approximate_Address__c = false;
                    riskLoc.Address_Not_Found__c = true;
                 }
             } catch( Exception e) {
                 system.debug('== Exception Occured ====' + e.getMessage());
             }
             address = '';
         } // End of For Loop
       
         update riskLocationList;
     } // End of Method
    
}

Please help me with this

<apex:includeScript value="/support/console/26.0/integration.js"/>
<A HREF="#" onClick="testIsInConsole();return false"> Click here to check if the page is in the Service Cloud console</A><br/><br/>
<script type="text/javascript">
window.onload =testIsInConsole();
function testIsInConsole() {
if (sforce.console.isInConsole()) {
alert("in console");
} else {
alert("not in console");
}
}

 

 

when i ececute this code it is giving as "not in console" eventhough i am in service console why?

pls help in this

Greetings!

 

I'm trying to get the opp stage name into the Event and freeze the value, what i'm trying to do is to get a report of all activities of the opp by stage.

 

Is that possible?

 

Thank you.

Can any body provide code sniffet for how to integrate the salesforce with facebook through visualforce page and apex..

Hi all,

 

I have a user picklist on lookup

1.user

2.Customer portal user

 

how to hide the customer portal user in the picklist.Is it possible that is a standard functionality

Is there any method to achive this one

 

any ideas?

 

Thanks!

 

 

 

Problem:- if i assign my user to a queue and then i want when new record is created for my object ( let it be Incident having field which has lookup on User) a field (let name it "Queue") should get autopopulated, how this can be acheived if i don't want to write trigger,

how to create and put dropdownlist in visualforce page?i mean to say take an example country.no.of countries is there.how to take it as a dropdown or picklist in visaul force page.is there any need to create a custom controller.if it is need.pls clarify this how to create apex class for this purpose in visual force page.pls clarify i will wait.

thanks in advance.

Hi,

 

Unable to fetch and save Force.com Components to Project: com.salesforce.ide.api.metadata.types.Metadata$JaxAccessorF_fullName cannot be cast to com.sun.xm.internal.bind.v2.runtime.reflect.Accessor

 

Abort or Continute Force.com project creation?

==============

while i am creating a new force.com project i got this error: can u please tell me why this error came. i downloaded eclipse and added force.com ide.... when i try to creating a new force.com project i got this error... and i am able to create a force.com project but not getting all existing classes and pages. And not added my new page or class content to the sever when i save. Is it required any other software installations?

 

Have a standard object layout that includes a visualforce page. With in the visualforce page there is a  apex:commandLink, the action for the commandLink is point to a function of a pageReference. If validation false the error message gets load to apex:pageMessages. The issue we are having is the pageReference is causing the visualforce page redirect out of the standard object layout. We do not want this behaviour! We want the error message to display within the standard object layout or even better in the visualforce page with in the standard object layout. FYI --> PageReference returns Null.

 

Also we try pointing back to the standard object layout but we lost the error messages when return to the standard object.

 

Any ideas why this is happening?

 

 

Code from the extensions of the VF page:

 

Public PageReference Name() {

    PageReference pageRef = null;

    .......

 

    if (ApexPages.hasMessages(ApexPages.Severity.Error))    {
             Database.rollback(sp);
    }

    return pageRef;

 

}

 

Page Code

 

 <apex:page standardController="standardController" extensions="extensions" >
     <apex:pageBlock >
        <apex:pageMessages />
        <apex:actionRegion >
        <apex:form id="theform" >

           ............

         <apex:commandLink action="action" value="Value" target="_top" />