9

Trying to create a master-detail relationship between my custom object (detail) and the standard product object (master). Initially it said I couldn't create this because I needed to make sure all child records had a parent, but there were no child records as I had literally just created the object.

So I made it a lookup relationship, but the spec requires that the custom object MUST have a product type. So after creating the lookup and then going to change the "what to do if the lookup record is deleted?" to "don't allow deletion of the lookup record", I get the error message: "Cannot add a lookup relationship child with cascade or restrict options to Product2 (Related field: Domain)".

So what's going on here because I don't see why this can't be done?

11

I can't offer you any insight into why you cannot do this, you just can't unfortunately, it's a seemingly arbitrary limitation of the platform and the Product2 object. Unless someone who knows about the internals of the platform comes across this I doubt you'll ever get a definitive answer.

In terms of working around it though, the only way to achieve this is to create your lookup as a standard non-required Lookup and then enforce that the value of this lookup cannot be blank using a validation rule.

Your validation rule will look something like this:

ISBLANK(ProductId__c)

If the Product is deleted then this will result in the value of the field being cleared, as per the default 'Clear the value of this field.' behaviour, which will prevent you updating the child record until a valid lookup ID is entered.

If you want to change this behaviour you'll have to write a before delete trigger on Product2 with your desired logic.

  • What happens if the Product record is deleted? Won't that result in an invalid child record? – Peter Knolle Apr 24 '14 at 11:14
  • 1
    @PeterKnolle This will result in the value of the field being cleared, as per the default 'Clear the value of this field.' behaviour. If you want to change this behaviour you'll have to write a before delete trigger on Product2 with your desired logic. I've added this information into my answer. – Alex Tennant Apr 24 '14 at 11:19

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.