Skip to main content
Hello Friends

I have a question where I have a map with Key as Name of properties of Object with values and I want to iterate over collection and assign value to relevant property i.e.

I have a custom object with 4 properties, First, Second, Third and Forth

Now I also have a Map<string, string> Values which has data as 

<First, 10>

<Second,20>

<Third, 30>

<Forth, 40>

Now I want a way to iterate over all the Keys in MAP and assign the value of corrosponding property of the object from value from MAP.

for(string keyValue : Map.GetKeys())

{

Object.Proeprty_Name = Map.Get(keyValue);

}

 
2 answers
  1. Apr 15, 2020, 4:59 PM
    Hi

    I used following method to set values

     public static void UpdateObjectProperty(sObject objBaseObject, string BeforePropertyName, string AfterPropertyName, object PropertyValue, ROIHelper.METRIC_TIME TimeOfMetric)

        {

            try

            {

                if(objBaseObject!=null)

                {

                    if(TimeOfMetric == ROIHelper.METRIC_TIME.BEFORE)

                    {

                        if(BeforePropertyName!=null && BeforePropertyName.length() >0)

                        {

                            objBaseObject.put(BeforePropertyName, PropertyValue);

                        }

                    }

                    if(TimeOfMetric == ROIHelper.METRIC_TIME.AFTER)

                    {

                        if(AfterPropertyName!=null && AfterPropertyName.length() >0)

                        {

                            objBaseObject.put(AfterPropertyName, PropertyValue);

                        }

                    }

                }

            }

            catch(exception exp)

            {

                ROIHelper.ExceptionHandler(exp);

                throw exp;

            }

        }
0/9000