1

If i have a class as shown below-

 public class ClassName{
        String field1{get;set;}
        String field2{get;set;} 
 }

Is there a way to get the fieldname of the above class in apex code. I need to get field1 and field2 programmatically. I found it is possible in java as per this link Is there something equivalent in salesforce?

5
  • 2
    No. You could add your vote to this 5 year old idea here Apex Reflection.
    – Keith C
    Oct 14 '14 at 10:02
  • @Akash developer.salesforce.com/forums/… once refer this link
    – Sathya
    Oct 14 '14 at 10:35
  • @Sathya Your link relates to the special case of SObjects - really information about the database schema and also some information used by the UI - rather than the general ability to find out about the fields etc of an ordinary Apex class.
    – Keith C
    Oct 14 '14 at 11:11
  • @satya Ya i am asking about normal apex class not the Objects Oct 14 '14 at 11:17
  • @KeithC Thanks for the reply , hope they add this feature in the upcoming release Oct 14 '14 at 11:21
2

As Keith C replied - it's not possible to get such information in apex but as a workaround you can use Tooling API or implement the following steps: 1. instantiate object 2. serialize to JSON 3. take all fields via JSON parser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.