function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kevin DesaiKevin Desai 

Generic Wrapper Class

Can we have a generic Wrapper class for sObject?

digamber.prasaddigamber.prasad

Hi,

 

What do you mean by generic Wrapper class for sObject? Could you be please explain it along with your requirement?

 

Happy to help you!

 

Regards,

Digamber Prasad

Kevin DesaiKevin Desai

Hello!

 

So, I've got a page where I have a couple of Objects and users can select any of these objects. Based on the selection, a dynamic query gets fired and result records show up. The user can then check whichever records he wants and proceed. For this checking records thing, I've used a wrapper class. However, like I said the object selection and query is dynamic. So in the Wrapper class, I have used GET SET for sObject data type.

 

This perfectly works until I go to VF page to display the records in a PageBlockSection. Here, fields except ID don't fit in ... The error says something like " XYZ is not the field of sObject".

 

I know the above explanation is pretty perplexing but I hope you get the point.

 

--Kevin

Force.com Certified Developer

digamber.prasaddigamber.prasad

Hi,

 

I can get what you want to achieve through this.

 

In your wrapper class, why don't you create a string field, which will store ID of your record and probably you can get rid off this issue.

 

Please let me know if you have any question around this solution.

 

Happy to help you!

 

Regards,

Digamber Prasad

Kevin DesaiKevin Desai

I am afraid @digamberlucky but I dont really follow the solution you suggested. I am passing the instance of whichever the object selected to the wrapper class for further processing.

 

Below is a sample loop. Here the instance is for Case. Initially I had sObject here.

 

 for(Case s : Database.Query(theQ))
        {
            system.debug('THE S:-'+s);
            wrapperClass wc = new wrapperClass(s);
            system.debug('THE WC:-'+wc);
            theResultList.add(wc);
        }