1

A while back I wrote an Apex class to handle opportunity splits. I couldn’t use the Opportunity Splits object because there were splits on three different corporate levels (with one-to-many or many-to-many relationships and security on each level). I ended up creating five different custom objects to fulfill a bunch of different reporting requirements, and I used jQuery on the VisualForce page to update various values as the user enters the data. This system has worked well for five years.

However, for some reason I’ve recently started questioning my methodology for performing updates. Because the number of splits and the split recipients can change each time the opportunity is updated, I simply delete all of the associated records on three of the custom objects and replace them with newly created records. That way I don’t have to evaluate each record to see if it needs to be updated, deleted, or a new one created. There is no requirement for an audit trail.

Is this an acceptable methodology?

I apologize if this is the wrong forum to be asking such a broad question, but I figured that I could keep my question shorter by not having to explain the peculiar constraints of Salesforce — I might have chosen a different update strategy under other circumstances.

1
  • i've used a similar pattern when having to replace OpportunityLineItems - much simpler to just wipe the slate clean and rebuild. Testing is much easier – cropredy Mar 19 '19 at 0:45
0

The only real concern about this strategy is that a large number of edits could fill the recycle bin, and potentially bump out other records you'd prefer to have the option to retain. As long as you're hard-deleting the records (via the emptyRecycleBin methods), you'd eliminate the main concern, and you could probably merrily continue on using this technique. From a performance perspective, it would be better to update records than to insert/delete each time, but unless you're explicitly having performance issues, it doesn't really matter.

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.