• Milan Hrdlicka
  • NEWBIE
  • 60 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 15
    Replies
Hi all,

I am trying to use this JSON parsing in a trigger.
The purpose of the trigger is to insert latitude and longtitude data to custom object "Branch__c" once data like address, city etc. are inserted so geolocation details are inserted automatically after the trigger is fired.
The point is to gather address details from Branch__c custom object and construct a String to be put in "endPointString" variable.
I am doing this by using a formula field where I want to concatenate all necessary details. 
In order to test whether the callout works in a trigger at all I chose to make an "in between steps trigger" just to test the functionality, therefore in all newly inserted rows would be put the same longtitude and latitude details as these the "endPointString" variable would have a fixed String value for the moment.
The thing is that when I use below trigger which uses above "parsing classes" and try to insert test data, I get a different error :)

Can you please help?
Appreciate your help,
Milan


The error: Line: 36, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updGPStest: execution of BeforeInsert caused by: System.CalloutException: Callout from triggers are currently not supported. Class.getGPS.getGPSdata: line 23, column 1 Trigger.updGPStest: line 11, column 1: []​

Data to insert:
-----------------------------
List<Branch__c> brList = new List<Branch__c> {
    new Branch__c(Account__c = '0010Y00000EhCbzQAF', City__c='Kladno', Name__c='Kladno_BULK_TEST1', Postal_Code__c='272 01', Street__c='Vrchlického', Street_No1__c='2409', Street_No2__c='9'),
    new Branch__c(Account__c = '0010Y00000EhCbzQAF', City__c='Kladno', Name__c='Kladno_BULK_TEST2', Postal_Code__c='272 01', Street__c='Vrchlického', Street_No1__c='2409', Street_No2__c='9'),
    new Branch__c(Account__c = '0010Y00000EhCbzQAF', City__c='Kladno', Name__c='Kladno_BULK_TEST3', Postal_Code__c='272 01', Street__c='Vrchlického', Street_No1__c='2409', Street_No2__c='9')
};
// Bulk insert all contacts with one DML call

insert brList;

My current trigger:
-------------------------------

 trigger updGPStest on Branch__c (before insert, before update) {
     
    List<Branch__c> addrString = new List<Branch__c>();
    getGPS gps = new getGPS();
    
    for(Branch__c br1 : Trigger.New) {
    

        addrString = [SELECT Concatenate_Address__c FROM Branch__c WHERE Id IN :Trigger.New];
        
        gps.getGPSdata();

        
        
        br1.Location_GPS__latitude__s = gps.getLat();
        br1.Location_GPS__longitude__s = gps.getLng();
        
        
         //gps.setEndPointStr('&addrString&');
        //gps.setEndPointStr('http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01');
        //br1.Test_Column__c = br1.Concatenate_Address__c;
        

    }
}


web callout classes used:

//class no.1
--------------------
public class getGPS {
    
    String endPointString = 'https://maps.googleapis.com/maps/api/geocode/json?address=Žerotínova 1664/57, Praha, 130 00&key=AIzaSyDpkHWwId9J1mMCqu9mirXPEwpM3XTs0GU';
    double lng;
    double lat;
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    
                       
}

//class no.2
--------------------

public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}
 
Hi all,

In the developer console I am trying to run below code in order to get geolocation data parsed from JSON string:

getGPS gps = new getGPS();
gps.getGPSdata();
gps.getLng();
gps.getLat();

Execution of "gps.getGPSdata();" returns "System.JSONException: Unexpected character  ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]" error.
Therefore "gps.getLng();" and "gps.getLat();" don't return anything.
Please see below classes - can anyone advise on what is causing this error as I guess this have worked before.
Appreciate your help.

//class no.1
--------------------

public class getGPS {
    
    String endPointString = 'https://maps.googleapis.com/maps/api/geocode/json?address=Žerotínova 1664/57, Praha, 130 00&key=AIzaSyDpkHWwId9J1mMCqu9mirXPEwpM3XTs0GU';
    double lng;
    double lat;
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    
                       
}

//class no.2
--------------------


public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}



 
I have two classes below used for retrieving data using a web call out - this worked when I ran below code in the developer console:
getGPS gps = new getGPS();
gps.getLng();
gps.getLat();

In Log I got longtitude and latitude whci is NOT HAPPENNING NOW FOR SOME REASON.
Can anyone shed a bit of light into this as this is giving me a headache, this ceased to work and I dont know why.

Appreciate your help, Milan

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class getGPS {
    
    String endPointString = 'http://maps.googleapis.com/maps/api/geocode/json?address='Šafaříkova 785/1, 120 00  Praha, Vinohrady';
    double lng;
    double lat;
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    
                       
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hi,

I have a problem with a non-functioning trigger.
I have custom object Branch__c showing fields like street, street number, city, postal code, etc.
Field Concatenate_Address__c is a formula field which concatenates all adress details and makes up a String used as an argument for getGPS() function which makes a web service call.
Example of the string (Concatenate_Address__c): 'http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01'
In my trigger I used gps.setEndPointStr('&addrString&'); to construct a supplying argument for the getGPS() function in order to return latitude and longitude details as per trigger and mentioned class code below.
The desired outcome is a latitude and longitude details update for each row once address details are entered.
It does not work, I tried to supply "concrete" details (like Example of the string - commented out in the trigger) but it did not work anyway, I guess there must be a problem using the gps.getLat(); and gps.getLng(); functions in the trigger.
Can you please advise how to amend the trigger in order to get desired GPS details updated?

Really appreciate your help.
Milan


my non-functioning trigger
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
trigger updGPStest on Branch__c (before insert, before update) {
     
    List<Branch__c> addrString = new List<Branch__c>();
    getGPS gps = new getGPS();
    
    for(Branch__c br1 : Trigger.New) {
    

        addrString = [SELECT Concatenate_Address__c FROM Branch__c WHERE Id IN :Trigger.New];
        
        gps.setEndPointStr('&addrString&');
        
        br1.Location_GPS__latitude__s = gps.getLat();
        br1.Location_GPS__longitude__s = gps.getLng();
        
        
        
        //gps.setEndPointStr('http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01');
        //br1.Test_Column__c = br1.Concatenate_Address__c;
        

    }
}


class getGPS:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class getGPS {
    
    //String endPointString = 'http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01';
    String endPointString;
    double lng;
    double lat;
    
    public void setEndPointStr(String input) {
        
       this.endPointString = input;
        
    }    
    
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    

    

                       
}

class googleAddress
​-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}

​-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Hello,

I need some advice on how to write a bulk trigger - I have custom object Branch__c with address details like street, street number, city, postal code etc. and I added a "Test_Coumn__c" in which I want to store these address values as a concatenated String.
I have created a list for each field I want to concatenate (if you can help if another data structure apart of multiple Lists can be used, it will be appreciated).
What I dont know is how to concatenate these multiple list address columns in one and how to put concatenated String (update column) to column Test_Column__c...I need to use this address string later as an argument to function which calls a web service getting latitude and longtitude details. 
Many thanks for advice on this.

Milan

MY TRIGGER:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 trigger updGPStest on Branch__c (before insert, before update) {
  
    List<Branch__c> brStreet = new List<Branch__c>();
    List<Branch__c> brStreetNo1 = new List<Branch__c>();
    List<Branch__c> brStreetNo2  = new List<Branch__c>();
    List<Branch__c> brCity = new List<Branch__c>();
    List<Branch__c> brPostalCode = new List<Branch__c>();
    
    List<Branch__c> addrString   = new List<Branch__c>();
    
    
    for(Branch__c br1 : Trigger.New) {

        brStreet = [SELECT Street__c from Branch__c WHERE Id IN :Trigger.New];
        brStreetNo1 = [SELECT Street_No1__c from Branch__c WHERE Id IN :Trigger.New];
        brStreetNo2 = [SELECT Street_No2__c from Branch__c WHERE Id IN :Trigger.New];
        brCity= [SELECT City__c from Branch__c WHERE Id IN :Trigger.New];
        brPostalCode = [SELECT Postal_Code__c from Branch__c WHERE Id IN :Trigger.New];
        
       // - THIS DOES NOT WORK :
        addrString = brStreet + brStreetNo1;
        
  
      

    }
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello,

I have ran below code:

DateTime today = Datetime.now();
System.debug(today);

What I get is date and time in GMT and I need Centrl European Time (CET) - in other word GMT plus 1 hour.
Can anyone advise, please?

Many thanks,
Milan
Hi all,

lets say it's Monday (I have solved this by using particular "Monday" date using datetime field) 10:00 am and I need to check whether this time falls into opening hours which does in below case.
Any suggestion of how to do that? Get actual time and somehow compare whether this falls in between opening and closing hours?
Can this be done by a single SOQL query? 

Opening Hours: 2017-01-02T07:30:00.000+0000
Closing Hours: 2017-01-02T19:30:00.000+0000

Appreciate your help on this.
Milan

 
Hi all,

I need to insert datetime using below code:

Opening_Hours__c oh = new Opening_Hours__c(Name='3', Open__c=2016-12-27T08:00:00Z);
insert oh;

I get this error: "unexpected token: "2016-12-27T08:00:00Z"

Can you please advise on what I am doing wrong?
How can I make a distinction in case of "AM" and "PM"?

Open__c is a field of datewtime type. Thanks a lot.
Hi all,

I have following visualforce page:

<apex:page standardController="Shop__c" extensions="myControllerExtension1" >
<apex:form >
<apex:pageBlock title="My shop" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Shop Info" columns="2">


<apex:inputField value="{!Shop__c.Account__c}"/>
<apex:inputField value="{!Shop__c.Name}" />
<apex:inputField value="{!Shop__c.Street__c}"/>
<apex:inputField value="{!Shop__c.Street_No1__c}"/>
<apex:inputField value="{!Shop__c.Street_No2__c}"/>
<apex:inputField value="{!Shop__c.Postal_Code__c}"/>
<apex:inputField value="{!Shop__c.City__c}"/> <apex:inputField value="{!Shop__c.Open_Hours_Id__c}"/>

<apex:pageBlockSection title="Shop Info" columns="2">
</apex:pageBlock>
</apex:form>
</apex:page>

I also have a geolocation field called GPS__c however cannot add it to the visualforce pge the same way as those above - <apex:inputField value="{!Shop__c.GPS__c}"/> - but I am getting an error "Unsupported type: common.api.soap.wsdl.Location used in expression: Shop__c.GPS__c" when trying to save it.
What I need is to get geolocation data (latitude, longtitude) filled automatically  when I enter address data like Street, Street_no1, Postal Code etc. and also view the geolocation field, in other words when I enter address details I want to get the longtitude and latitude fields filled automatically in appropriate fields.
I have already managed to get longtitude and latitude data using JSON,please see below..however not sure how to complete the task described above. Really appreciate help on this.
Thanks a lot, Milan 

Getting longtitude and latitude using JSON:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class JSONpokus2 {
    
    String endPointString = 'http://maps.googleapis.com/maps/api/geocode/json?address=Nuselská 23, 140 00, Praha 4';
    double lng;
    double lat;
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void parseJSONResponse() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }                      
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Running this code in anonymous window:
-------------------------------------------------------------------------
JSONpokus2 jp2 = new JSONpokus2();
jp2.parseJSONResponse();
system.debug('Geolocation1: '+jp2.getLng());
system.debug('Geolocation2: '+jp2.getLat());
-------------------------------------------------------------------------
Hello,

I have a custom object "Shop__c". When I enter address details to appropriate fields, once these are entered I need t latitude and longtitude details (geolocation) to be filled automatically.
Longtitude and Latitude data are placed in a variable in separate class.
Can anyone advise what would be the best to achieve this?
Appreciate your help,
Milan
 
Hello,

I have a datetime field in which I need to insert date and time - 5th December 2016 7:30 AM.
I tried below code but I guess the datetime format is invalid as I get an error: Line: 5, Column: 23
unexpected token: '2016-12-05'
Anyone knows a valid date format, does it depend on my current location? 
Appreciate your help.

Milan

try {

   Opening_Hours__c openHours = [select Name, Day_Of_Week__c from Opening_Hours__c where Name = '1' AND Day_Of_Week__c ='Monday'];

   openHours.Open__c = 2016-12-05 07:30 AM;

   update openHours;

    } 

catch(Exception e) {
    System.debug('An unexpected error has occurred: ' + e.getMessage());
}
Hello,
I have this URL which generates JSON output:
https://maps.googleapis.com/maps/api/geocode/json?address= Nuselská 23, 140 00, Praha 4 key=AIzaSyC2Hu3fh2L7MIN_UaBqgBtM-QvI-SPcGYg
I get data in JSON format using above URL and what I need is to get geolocation data (latitude and longtitude) and place these in a variabĺe.
Could anyoune please share a code how to do that.
I just need to place the URL in a code and get required geolocoation details without any "in between" step of copying/pasting JSON output format.
Appreciate your help,
Milan
Hello,
I need to visualize google map service data in Salesforce base don longtitude and latitude using google map service and given API key - from what I understand till now I need a Java script embeded in a visualforce page using api key from google.
Could anyone share any code to embed into a visualforce page (I already have the API key foem google)?
Also I would need advice on how to get longtitude and latitrude data from google map service using address details.
Your help will be much appreciated.
Many thanks,
Milan
Hi all,

I have a custom object "Shop" with address details - street name, street number 1, street number 2, postal code and city.
Along with these address details which are supposed to be entered manually or loaded from an extrenal data source there is also a custom field(s) "Geolocation" - what I need is Latitude and Longtitude details retrieved by using address details via Google Map Service.
Don't know how to retrieve these data.
Morever when all address details are entered the latitude and longtitude details should be filled automatically and saved at the same time along with all address and other details.
Sounds like a workflow rule or maybe before trigger with a class containing "mechanism" of retrieving data from Google Map Service?
Not sure how to do this - help on this will be much appreciated.
Milan
Hello,

1.) I have an "Account" standard object which is in master-detail relationship with custom object "Shop" where I added custom field "Account" which is of "Master-Detail" field linked to the Account Object.
I am not sure how to "connect" these objects - should I put an ID of particular Account record in custom field "Account" of Master Detail type which is part of custom object "Shop"? How would 'I get the ID of particular "Account" record?


2.) I have also created a custom object "Opening_Hours" which is linked to custom object "Store"  as I have added custom field to the "Store" object which is called "Open_Hours_Id" and is linked via lookup to custom object "Opening_Hours". The "primary key" for particular opening hours is of type text so "Opening_Hours" has an "ID record" of type text.
The question is how to insert "Opening_Hours" object's "ID record" to the custom field "Open_Hours_Id" of custom object "Store"_

Appreciate your help,
Milan
Hello,

I have created a custom object "Branch" which is in master-detail realtionship with standard "Account" object.
One Account can have multiple Branches in various addresses. The address data of a branch contain its name, street, street numbers(s), postal code, city. There is also a geolocation field (I would appreciate advice on format of the geolocation field as well - "Degrees, Minutes, Seconds" or "Decimal" - I have created "Degrees, Minutes, Seconds" with 15 decimal places.)
What I need is the geolocation field automatically after all necessary address details are filled - so the first thing is to get the geolocation data - longtitude and latitude  probably using google map service? In other words I need to "translate" address details via google map service (or similar) and retrieve geolocation data. Moreover I need to have this geolocation details filled automatically with address data for each row, would this be possible with workflow or before trigger?
Last thing I need is to embed a google map in Account layout showing "points" where branches are located according to their geolocation data - I need these branches in different colours according to opening times - the colour will be determined on a value of particular variable which determines whether the branch is closed or open.

Hello,

I have "Contract" object and "User" object - they are connected as this by a "primary" key which is "Name" + " " + "Surname" (formula field type).
The "Contract" object has a date field "enddate" when the contract ends and also picklist field "OwnerExpirationNotice" which shows how many days in advance before the end date an e-mail must be sent to given contractor.
At the moment the picklist field only has a value of 30 and there are also null values, in case there is a null value, these rows should be excluded.
I need something like this:

if "enddate" minus "OwnerExpirationNotice" = today(), sent an e-mail to given address (for values where picklist values of "OwnerExpirationNotice" are not null).
Is a Workflow the real choice? Is that a problem that "OwnerExpirationNotice" is a picklist field?

Really appreciate your help on this.
Milan

 

Hello,

I have a question regarding using UPSERT in data loader.
I have an object "Contract" (standard object) with field "RESOURCE__C" and I need to upsert data from other object - lets call it "object B" (custom object) where the same "RESOURCE__C" field is present and "Contract" and "Object B" are related via this field (I checked this by using V-lookup in Excel to verify this). "RESOURCE__C" is a kind of primary key (new to Salesforce, sorry for teminology..)
Just to mention - "RESOURCE__C" in both objects ("Contract" and "object B) are of data type Lookup(User). User = standard object.
When I press "UPSERT" in data loader this step is followed by Step 2 where I choose object "Contract" from the list and choose .csv file with "object B" data. Aterwards initialization suceeds and we get into the stage where I get an issue - "Step 2a" - I get a message saying "There are no external ID fields defined on the Contract object. The Id field  will be used for matching". The "Id" field relating to the Contract Object appears greyed out and no other selection is possible. However there is no field named "Id" on the "Contract" object (I guess it is a kind of default field name...).
So my question is how to "say" to the data loader that the External Id field is called "RESOURCE__C" .

I appreciate any help on this matter.
Kind regards,
Milan

Hi all,

I am trying to use this JSON parsing in a trigger.
The purpose of the trigger is to insert latitude and longtitude data to custom object "Branch__c" once data like address, city etc. are inserted so geolocation details are inserted automatically after the trigger is fired.
The point is to gather address details from Branch__c custom object and construct a String to be put in "endPointString" variable.
I am doing this by using a formula field where I want to concatenate all necessary details. 
In order to test whether the callout works in a trigger at all I chose to make an "in between steps trigger" just to test the functionality, therefore in all newly inserted rows would be put the same longtitude and latitude details as these the "endPointString" variable would have a fixed String value for the moment.
The thing is that when I use below trigger which uses above "parsing classes" and try to insert test data, I get a different error :)

Can you please help?
Appreciate your help,
Milan


The error: Line: 36, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updGPStest: execution of BeforeInsert caused by: System.CalloutException: Callout from triggers are currently not supported. Class.getGPS.getGPSdata: line 23, column 1 Trigger.updGPStest: line 11, column 1: []​

Data to insert:
-----------------------------
List<Branch__c> brList = new List<Branch__c> {
    new Branch__c(Account__c = '0010Y00000EhCbzQAF', City__c='Kladno', Name__c='Kladno_BULK_TEST1', Postal_Code__c='272 01', Street__c='Vrchlického', Street_No1__c='2409', Street_No2__c='9'),
    new Branch__c(Account__c = '0010Y00000EhCbzQAF', City__c='Kladno', Name__c='Kladno_BULK_TEST2', Postal_Code__c='272 01', Street__c='Vrchlického', Street_No1__c='2409', Street_No2__c='9'),
    new Branch__c(Account__c = '0010Y00000EhCbzQAF', City__c='Kladno', Name__c='Kladno_BULK_TEST3', Postal_Code__c='272 01', Street__c='Vrchlického', Street_No1__c='2409', Street_No2__c='9')
};
// Bulk insert all contacts with one DML call

insert brList;

My current trigger:
-------------------------------

 trigger updGPStest on Branch__c (before insert, before update) {
     
    List<Branch__c> addrString = new List<Branch__c>();
    getGPS gps = new getGPS();
    
    for(Branch__c br1 : Trigger.New) {
    

        addrString = [SELECT Concatenate_Address__c FROM Branch__c WHERE Id IN :Trigger.New];
        
        gps.getGPSdata();

        
        
        br1.Location_GPS__latitude__s = gps.getLat();
        br1.Location_GPS__longitude__s = gps.getLng();
        
        
         //gps.setEndPointStr('&addrString&');
        //gps.setEndPointStr('http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01');
        //br1.Test_Column__c = br1.Concatenate_Address__c;
        

    }
}


web callout classes used:

//class no.1
--------------------
public class getGPS {
    
    String endPointString = 'https://maps.googleapis.com/maps/api/geocode/json?address=Žerotínova 1664/57, Praha, 130 00&key=AIzaSyDpkHWwId9J1mMCqu9mirXPEwpM3XTs0GU';
    double lng;
    double lat;
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    
                       
}

//class no.2
--------------------

public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}
 
Hi all,

In the developer console I am trying to run below code in order to get geolocation data parsed from JSON string:

getGPS gps = new getGPS();
gps.getGPSdata();
gps.getLng();
gps.getLat();

Execution of "gps.getGPSdata();" returns "System.JSONException: Unexpected character  ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]" error.
Therefore "gps.getLng();" and "gps.getLat();" don't return anything.
Please see below classes - can anyone advise on what is causing this error as I guess this have worked before.
Appreciate your help.

//class no.1
--------------------

public class getGPS {
    
    String endPointString = 'https://maps.googleapis.com/maps/api/geocode/json?address=Žerotínova 1664/57, Praha, 130 00&key=AIzaSyDpkHWwId9J1mMCqu9mirXPEwpM3XTs0GU';
    double lng;
    double lat;
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    
                       
}

//class no.2
--------------------


public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}



 
I have two classes below used for retrieving data using a web call out - this worked when I ran below code in the developer console:
getGPS gps = new getGPS();
gps.getLng();
gps.getLat();

In Log I got longtitude and latitude whci is NOT HAPPENNING NOW FOR SOME REASON.
Can anyone shed a bit of light into this as this is giving me a headache, this ceased to work and I dont know why.

Appreciate your help, Milan

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class getGPS {
    
    String endPointString = 'http://maps.googleapis.com/maps/api/geocode/json?address='Šafaříkova 785/1, 120 00  Praha, Vinohrady';
    double lng;
    double lat;
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    
                       
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hi,

I have a problem with a non-functioning trigger.
I have custom object Branch__c showing fields like street, street number, city, postal code, etc.
Field Concatenate_Address__c is a formula field which concatenates all adress details and makes up a String used as an argument for getGPS() function which makes a web service call.
Example of the string (Concatenate_Address__c): 'http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01'
In my trigger I used gps.setEndPointStr('&addrString&'); to construct a supplying argument for the getGPS() function in order to return latitude and longitude details as per trigger and mentioned class code below.
The desired outcome is a latitude and longitude details update for each row once address details are entered.
It does not work, I tried to supply "concrete" details (like Example of the string - commented out in the trigger) but it did not work anyway, I guess there must be a problem using the gps.getLat(); and gps.getLng(); functions in the trigger.
Can you please advise how to amend the trigger in order to get desired GPS details updated?

Really appreciate your help.
Milan


my non-functioning trigger
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
trigger updGPStest on Branch__c (before insert, before update) {
     
    List<Branch__c> addrString = new List<Branch__c>();
    getGPS gps = new getGPS();
    
    for(Branch__c br1 : Trigger.New) {
    

        addrString = [SELECT Concatenate_Address__c FROM Branch__c WHERE Id IN :Trigger.New];
        
        gps.setEndPointStr('&addrString&');
        
        br1.Location_GPS__latitude__s = gps.getLat();
        br1.Location_GPS__longitude__s = gps.getLng();
        
        
        
        //gps.setEndPointStr('http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01');
        //br1.Test_Column__c = br1.Concatenate_Address__c;
        

    }
}


class getGPS:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class getGPS {
    
    //String endPointString = 'http://maps.googleapis.com/maps/api/geocode/json?address=Černokostelecká /, Říčany, 251 01';
    String endPointString;
    double lng;
    double lat;
    
    public void setEndPointStr(String input) {
        
       this.endPointString = input;
        
    }    
    
    
    public double getLng() {
        return lng;
        }
    
    public double getLat() {
        return lat;
        }
    
  

      public void getGPSdata() {
          Http httpProtocol = new Http();
          HttpRequest request = new HttpRequest();
          String endpoint = endPointString;
          request.setEndPoint(endpoint);
          request.setMethod('GET');
          HttpResponse response = httpProtocol.send(request); 
          String jsonString = response.getBody();
          googleAddress addr = googleAddress.parse(jsonString);
          
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
          
          this.lng=lng;
          this.lat=lat;

      }
    

    

                       
}

class googleAddress
​-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class googleAddress {

    public class Address_components {
        public String long_name;
        public String short_name;
        public List<String> types;
    }

    public class Geometry {
        public Location location;
        public String location_type;
        public Viewport viewport;
    }

    public List<Results> results;
    public String status;
    public Location firstLoc;

    public class Results {
        public List<Address_components> address_components;
        public String formatted_address;
        public Geometry geometry;
        public Boolean partial_match;
        public String place_id;
        public List<String> types;
    }

    public class Viewport {
        public Location northeast;
        public Location southwest;
    }

    public class Location {
        public Double lat;
        public Double lng;
    }

    
    public static googleAddress parse(String json) {
        
        googleAddress returnAddr;
        
        returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
        if (!returnAddr.results.isEmpty()){
            returnAddr.firstLoc = returnAddr.results[0].geometry.location;
        }
        return returnAddr; 
        
        
    }
}

​-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Hello,

I need some advice on how to write a bulk trigger - I have custom object Branch__c with address details like street, street number, city, postal code etc. and I added a "Test_Coumn__c" in which I want to store these address values as a concatenated String.
I have created a list for each field I want to concatenate (if you can help if another data structure apart of multiple Lists can be used, it will be appreciated).
What I dont know is how to concatenate these multiple list address columns in one and how to put concatenated String (update column) to column Test_Column__c...I need to use this address string later as an argument to function which calls a web service getting latitude and longtitude details. 
Many thanks for advice on this.

Milan

MY TRIGGER:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 trigger updGPStest on Branch__c (before insert, before update) {
  
    List<Branch__c> brStreet = new List<Branch__c>();
    List<Branch__c> brStreetNo1 = new List<Branch__c>();
    List<Branch__c> brStreetNo2  = new List<Branch__c>();
    List<Branch__c> brCity = new List<Branch__c>();
    List<Branch__c> brPostalCode = new List<Branch__c>();
    
    List<Branch__c> addrString   = new List<Branch__c>();
    
    
    for(Branch__c br1 : Trigger.New) {

        brStreet = [SELECT Street__c from Branch__c WHERE Id IN :Trigger.New];
        brStreetNo1 = [SELECT Street_No1__c from Branch__c WHERE Id IN :Trigger.New];
        brStreetNo2 = [SELECT Street_No2__c from Branch__c WHERE Id IN :Trigger.New];
        brCity= [SELECT City__c from Branch__c WHERE Id IN :Trigger.New];
        brPostalCode = [SELECT Postal_Code__c from Branch__c WHERE Id IN :Trigger.New];
        
       // - THIS DOES NOT WORK :
        addrString = brStreet + brStreetNo1;
        
  
      

    }
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello,

I have ran below code:

DateTime today = Datetime.now();
System.debug(today);

What I get is date and time in GMT and I need Centrl European Time (CET) - in other word GMT plus 1 hour.
Can anyone advise, please?

Many thanks,
Milan
Hi all,

lets say it's Monday (I have solved this by using particular "Monday" date using datetime field) 10:00 am and I need to check whether this time falls into opening hours which does in below case.
Any suggestion of how to do that? Get actual time and somehow compare whether this falls in between opening and closing hours?
Can this be done by a single SOQL query? 

Opening Hours: 2017-01-02T07:30:00.000+0000
Closing Hours: 2017-01-02T19:30:00.000+0000

Appreciate your help on this.
Milan

 
Hi all,

I need to insert datetime using below code:

Opening_Hours__c oh = new Opening_Hours__c(Name='3', Open__c=2016-12-27T08:00:00Z);
insert oh;

I get this error: "unexpected token: "2016-12-27T08:00:00Z"

Can you please advise on what I am doing wrong?
How can I make a distinction in case of "AM" and "PM"?

Open__c is a field of datewtime type. Thanks a lot.
Hello,

I have a custom object "Shop__c". When I enter address details to appropriate fields, once these are entered I need t latitude and longtitude details (geolocation) to be filled automatically.
Longtitude and Latitude data are placed in a variable in separate class.
Can anyone advise what would be the best to achieve this?
Appreciate your help,
Milan
 
Hello,
I have this URL which generates JSON output:
https://maps.googleapis.com/maps/api/geocode/json?address= Nuselská 23, 140 00, Praha 4 key=AIzaSyC2Hu3fh2L7MIN_UaBqgBtM-QvI-SPcGYg
I get data in JSON format using above URL and what I need is to get geolocation data (latitude and longtitude) and place these in a variabĺe.
Could anyoune please share a code how to do that.
I just need to place the URL in a code and get required geolocoation details without any "in between" step of copying/pasting JSON output format.
Appreciate your help,
Milan

Hello,

I have a question regarding using UPSERT in data loader.
I have an object "Contract" (standard object) with field "RESOURCE__C" and I need to upsert data from other object - lets call it "object B" (custom object) where the same "RESOURCE__C" field is present and "Contract" and "Object B" are related via this field (I checked this by using V-lookup in Excel to verify this). "RESOURCE__C" is a kind of primary key (new to Salesforce, sorry for teminology..)
Just to mention - "RESOURCE__C" in both objects ("Contract" and "object B) are of data type Lookup(User). User = standard object.
When I press "UPSERT" in data loader this step is followed by Step 2 where I choose object "Contract" from the list and choose .csv file with "object B" data. Aterwards initialization suceeds and we get into the stage where I get an issue - "Step 2a" - I get a message saying "There are no external ID fields defined on the Contract object. The Id field  will be used for matching". The "Id" field relating to the Contract Object appears greyed out and no other selection is possible. However there is no field named "Id" on the "Contract" object (I guess it is a kind of default field name...).
So my question is how to "say" to the data loader that the External Id field is called "RESOURCE__C" .

I appreciate any help on this matter.
Kind regards,
Milan