You need to sign in to do that
Don't have an account?
Ronan O'Neill 6
I want to add a new value to a List<Account>
Hi,
I created a List<Account> which takes the result of a database query. Later in the code I want to update two of the values in this List with new values. The values should be of type Double, but I seem to be only allowed add them to the List if I cast them as type Account.
Unfortunately I then get an error "Invalid conversion from runtime type Decimal to Account".
Class variable
public static List<Account> contactLatLng {get;set;};
In Constructor
contactLatLng = Database.query(queryContact);
In Class Method
if(status =='OK') {
List<Object> results = (List<Object>) ((Map<String, Object>)JSON.deserializeUntyped(response)).get('results');
Map<String, Object> geometry = (Map<String, Object>) ((Map<String, Object>) results.get(0)).get('geometry');
Map<String, Object> location = (Map<String, Object>) geometry.get('location');
Account lat = (Account)(location.get('lat'));
Account lng = (Account)location.get('lng');
contactLatLng.set(0, lat);
contactLatLng.set(1, lng);
So whats the best way to have the values from the database query updateable. Could I swap them to a List of a different type to make it easier?
Thanks,
I created a List<Account> which takes the result of a database query. Later in the code I want to update two of the values in this List with new values. The values should be of type Double, but I seem to be only allowed add them to the List if I cast them as type Account.
Unfortunately I then get an error "Invalid conversion from runtime type Decimal to Account".
Class variable
public static List<Account> contactLatLng {get;set;};
In Constructor
contactLatLng = Database.query(queryContact);
In Class Method
if(status =='OK') {
List<Object> results = (List<Object>) ((Map<String, Object>)JSON.deserializeUntyped(response)).get('results');
Map<String, Object> geometry = (Map<String, Object>) ((Map<String, Object>) results.get(0)).get('geometry');
Map<String, Object> location = (Map<String, Object>) geometry.get('location');
Account lat = (Account)(location.get('lat'));
Account lng = (Account)location.get('lng');
contactLatLng.set(0, lat);
contactLatLng.set(1, lng);
So whats the best way to have the values from the database query updateable. Could I swap them to a List of a different type to make it easier?
Thanks,
They values you are trying to insert in List<Account> - are you trying to update acocunts or trying to create new acocunts and insert in the list?
I thought the easiest way was to update the Latitude and Longitude values in the List I had saved the Account to.
But I might try saving the new co-ords to seperate fields to be used if they aren't null some. The hard part is getting the values from controller to javascript.