Skip to main content
added 416 characters in body
Source Link
David Reed
  • 93.7k
  • 14
  • 90
  • 166

When you use JSON.deserializeUntyped(data), you need to perform type casting to tell the Apex compiler what kind of object you're working with or you'll get errors because the type Object has no property baseVolume (e.g.).

One way to accomplish this would be:

for (Object obj : meta.keyset()){
    Data d = (DataMap<String, Object>)meta.get(obj);

    System.debug(d.baseVolumeget('baseVolume');)
}

This converts the untyped Object instance into a Map, whose get method you can use to obtain properties. (Unfortunately, you can't cast directly to a Data instance from a Map; please pardon my oversight).

If you do want to work with class instances rather than untyped Maps, you could also deserialize into a Map<String, Data>, which would have a keySet you could then iterate over.

When you use JSON.deserializeUntyped(data), you need to perform type casting to tell the Apex compiler what kind of object you're working with or you'll get errors because the type Object has no property baseVolume (e.g.).

One way to accomplish this would be:

for (Object obj : meta.keyset()){
    Data d = (Data)meta.get(obj);

    System.debug(d.baseVolume);
}

When you use JSON.deserializeUntyped(data), you need to perform type casting to tell the Apex compiler what kind of object you're working with or you'll get errors because the type Object has no property baseVolume (e.g.).

One way to accomplish this would be:

for (Object obj : meta.keyset()){
    Data d = (Map<String, Object>)meta.get(obj);

    System.debug(d.get('baseVolume'))
}

This converts the untyped Object instance into a Map, whose get method you can use to obtain properties. (Unfortunately, you can't cast directly to a Data instance from a Map; please pardon my oversight).

If you do want to work with class instances rather than untyped Maps, you could also deserialize into a Map<String, Data>, which would have a keySet you could then iterate over.

Source Link
David Reed
  • 93.7k
  • 14
  • 90
  • 166

When you use JSON.deserializeUntyped(data), you need to perform type casting to tell the Apex compiler what kind of object you're working with or you'll get errors because the type Object has no property baseVolume (e.g.).

One way to accomplish this would be:

for (Object obj : meta.keyset()){
    Data d = (Data)meta.get(obj);

    System.debug(d.baseVolume);
}