4

I'm looking out for a way to make the relationship between Order and Contract, 1-1, The relationship between both, is optional, but still, I'm unsure if I need to add a custom field to Contract that points to the corresponding order, of if there is a way to declarative restrict the relation, and also allowing for a direct query without the nested sub query in SOQL.

Any Idea?

6

Yes, You can do that using standard Salesforce Functionality

  1. Create a Field on Order Named as Contract_Unqiue__c and make it as unique field.
  2. Create a WF rule on Order and when the order is created , copy the ContractID to the field Contract_Unique__c

Thats it done.

WHen a new order is created for that contract, it will allow you to save it, and if you try to add another order it throw Unique field constraint exception. Thus this allows you to only have 1-1 Relationship ie 1 contract should have atmost 1 order.

  • That is what I thought, but I wanted to Avoid the Custom Field, I thought there was a way to restrict them to 1-1 similar to the PersonAccount or something. Thanks – ekiim Dec 12 '18 at 20:06
  • Person Accounts are very special objects and and there isnt away to make it via custom SF – Pranay Jaiswal Dec 12 '18 at 20:07

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.