Wednesday, August 19, 2015

Salesforce APEX: Class variable/property are access dynamically

1.      Class  description
public class mobile
{
  public string SMS{get;set;}
  public string calling{get;set;}

}
2.      your  code to pick property value dynamically  
     mobile m =new mobile();
     m.SMS='SMS Test';
     m.calling='My Calling';

     String serialized = JSON.serialize(m); // object convert JSON string
      Map<String, Object> parameters = new Map<String, Object>();
      parameters = (Map<String, Object>) JSON.deserializeUntyped(serialized);
     
    string   fieldvalue=parameters.get( 'SMS');
   string   fieldvalue2=parameters.get(‘calling’);

No comments:

Post a Comment