4

Background: We would like our managed package to create standard object records (Leads, Cases, Contacts) on behalf of the user, in Apex. Outside of dealing with the built-in required fields (e.g. LastName, Company for Leads), the code of course also has to contend with any custom required fields, unique fields, and validation rules that the customer may have installed on these objects.

Question: Should we (a) use techniques such as those discussed here and addressed in a github project here to handle required and unique fields? But then how to deal with validation rules that might cause inserts to fail? or (b) abandon the whole idea of creating records on behalf of the user without their input? or (c) ask the Admin to provide a list of field names and default values that the Apex code can use to create a proper, valid record of each type.

I'm thinking the only viable/user-friendly option is (b), but I'm really curious to hear from other ISV folks who have dealt with this problem. Thanks!

1 Answer 1

3

There are so many factors that can impact your ability as an ISV to create records via Apex that the support time you end up needing to deal with the errors probably outweighs the benefits.

If it is something you really need to offer, I would probably go down the route of using having a custom setting in your app that you populate on install of the package that would provide a field map of fields for each object you want to create dynamically and a default value for each field, so the admin in the target org can modify those to match their validation rules/workflows etc...and you would probably also need a custom setting to store defaults for each record e.g. default record types if they have them enabled, default accounts for Contacts etc...

2
  • "Custom setting with field map", brr... Wonder if you could specify in managed package a handful of fieldsets with "name you expect" and client org admins could modify their content / requiredness of the fields. Defaults I'd leave as is, that's their whole point, right?
    – eyescream
    Jun 6, 2013 at 21:16
  • Thanks to you both for your thoughts. I appreciate the feedback. We have decided to use a design that avoids the issue altogether and forces the user to create these records and provide appropriate values manually. Cheers! Jun 11, 2013 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .