Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
What happens if the Product record is deleted? Won't that result in an invalid child record? –  Peter Knolle Apr 24 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 at 11:19
    
+1 Nice! Thanks for adding that. :) –  Peter Knolle Apr 24 at 11:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.