You need to sign in to do that
Don't have an account?

Generics in an Apex Class?
I'm working on some functionality that alters sharing rule on custom objects. I'm looking to create general methods like:
CreateReadonlyShare(recordId, userId, object) where the calling code injects the object into the method. Is is possible to create a generic in Apex? I can't seem to find anything other than sObjects which might work here, but I'm still curious.
Thanks.
Check the docs under Dynamic Apex and Dynamic SOQL for full details. That being said, you would indeed use SObject to manipulate records whose data type is unknown until runtime. With your example method you'd like to create below, for example, you would do the following:
Of course, just like the API, if a given row already exists, it is treated as an update instead of an insert.