0

I am having trouble Saving data through Apex I send to Apex a dict that have different Data type such as {"id": 12345, "field_name":44}

now what I would like to do is

  1. send this data to Apex
  2. Get the specific lead via the Id
  3. update the fields

@AuraEnabled
public static void UW_SavedData(Map<String, Object> record){
    if(record != null){
        string currentId = record.id;
        Lead CurrentProp = [SELECT Id FROM Lead WHERE Id = :record.id];          
        }
    }

My apex look the following ..

my issue is that for :record.id I get the error Variable does not exist: id

Could you explain me what I am doing wrong ?

edited Code:

@AuraEnabled
public static void UW_SavedData(Lead record){
    if(record != null){
        Id currentId = record.get('Id');
        Lead CurrentProp = [SELECT Id FROM Lead WHERE Id = :currentId];          
        }
    }

2 Answers 2

2

As a map, you'd have to write:

Id currentId = (Id)record.get('Id'); 

Note that this is case sensitive. You might want to just pass in a record directly:

public static void UW_SavedData(Lead record){

This saves you the trouble of using Maps in Apex.

3
  • thx you, I edited my code have a look , but now I get an error Illegal assignment from Object to Id on the line Id currentId = record.ger('Id')
    – Ben2pop
    Commented Aug 12, 2021 at 15:15
  • Oh I got you, I do not use the Map thing .get
    – Ben2pop
    Commented Aug 12, 2021 at 15:17
  • 1
    @Ben2pop Yes, there should have been a "cast" to tell the compiler the data type we expect.
    – sfdcfox
    Commented Aug 12, 2021 at 15:18
2

Unlike JavaScript, to get the value from a key value pair i.e., a map in Apex, you will have to use the get method. For example:

record.get('Id')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .