+ Start a Discussion
Ronan O'Neill 6Ronan 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,
 
SonamSonam (Salesforce Developers) 
A list>Account> can only hold records of the type Account.

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?

 
Ronan O'Neill 6Ronan O'Neill 6
Neither, I'm using the custom Latitude and Longitude fields of Account as the centre point of a google map. What I want is to be able to update the centre point of the map while keeping the rest of the info from the account such as name.

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.