You need to sign in to do that
Don't have an account?
N>Help with Field Mapping Error
Good day everyone I have some question in salesforce. Suppose i've created a map example:
map<String,String> testVariable = new map<String,String> // where the map key is an api key of a certain object field and map value is a possible field value;
Now what I want is to create an object through looping the map.Ex.
Account acctVariable = new Account();
for(String variable1 : testVariable.keyset()){
acctVariable.variable1 = 'sample data';
}
But an error say that "Invalid field variable1". What will I do in order for the system to detect that variable1 is a variable and not an object field ?This is just a part of the whole code. Please help .thank you.
map<String,String> testVariable = new map<String,String> // where the map key is an api key of a certain object field and map value is a possible field value;
Now what I want is to create an object through looping the map.Ex.
Account acctVariable = new Account();
for(String variable1 : testVariable.keyset()){
acctVariable.variable1 = 'sample data';
}
But an error say that "Invalid field variable1". What will I do in order for the system to detect that variable1 is a variable and not an object field ?This is just a part of the whole code. Please help .thank you.
Let me know if this helps.
As per your code you have consructed a map with key as string and value as string .I am sure how you are constructing the map .
Secondly you are iterating with keyset and creating account and assigning the value to account field .
As Ajay said is correct you can assign from the amp to Account Name or any other field you need .
But if you will create insnace of account outside the loop then finally it will assign only only last map value to Account .
So try like below .create Account instance inside the loop and add to alist .
Let me know if any issue .