+ Start a Discussion
j_panchalj_panchal 

how to search that an attribute value exists in the list variable.

Hello,

 

i made a list object to get company details from an external API, the code is below - 

 

List<Company> lstCompanies = getCompanyById('36482'); 

 

//Company is a class in which some properties are defined and has method getCompanyById. 

 

now, the data returned from lstcompanies is like --  

 

" {Company:[Address=916 W College St, BusinessType=null, City=Florence, CompanyName=Bridge,  Contacts=(Contact:[FirstName=ABC, Gender=Male, LastName=Bridges, Title=Owner])} "

 

i need to get attribute values from the above list , but before that have to check that the attribute is present in the list or not. i.e. need to search whether an attribute is present in the list.

 

For eg.  if FirstName is present in lstCompanies then i have to get its value from the list , similarly for othe attributes.

So, is there any way this can be done, tried using Contains method but it works only for Set and can't find any method like get  for fetching the attribute value by passing their name. 

 

As it is a list of class that we made and not a custom object, hence can't figure out how to use SObject also. 

 

Please help.

 

Thanks in Advance.