Reply
GTE
Newbie
GTE
Posts: 5
0

Related Object Required

Hello

 

I have a "Main Object" (Sales Opportunity) and a "Related" object (Product).

 

Is there a way to setup my main object so that if "Sales Opportunity" status is set to "Prepare Quotation" the object must have a Product related to it?

 

Thanks

Regular Contributor
Tanvir Ansari
Posts: 41
0

Re: Related Object Required

[ Edited ]

Sales Opportunity should have a lookup field for Product. And on the Sales Opportunity status field do a validation rule which checks if the value of picklist is "Prepare Quotation"and the  then the lookup field is"Blank", throw error.

GTE
Newbie
GTE
Posts: 5
0

Re: Related Object Required

Thanks. This will do if I have at least 1 product. How about if I must require at least "X" product to be related? Can I have something that counts the number of products related and then work the validation rule from there?

Regular Contributor
Tanvir Ansari
Posts: 41
0

Re: Related Object Required

Grrrrr.... got it. I got confused .....So create a Roll Up Summary field which does count of the PRODUCTS and store it. Create a validation rule that says the count is not 0 when the status is "prepare Quotation", I think this will work
Regular Contributor
Tanvir Ansari
Posts: 41
0

Re: Related Object Required

Did it work?

GTE
Newbie
GTE
Posts: 5
0

Re: Related Object Required

Let me explain a bit more.  Imagine we sell luxury cars. So for every sales oportunity we need to incluide at least a few products (car model, leather seats, hifi sound system, etc). So I will always need to add more than one product. 

 

If it were just the one product, your idea would do. But for several I need to go and look how many product items are liked to this Sales Oportunity and then count them up.

 

Thanks

Regular Contributor
Tanvir Ansari
Posts: 41
0

Re: Related Object Required

I understood that, so what is the issue?

 

As said earlier, create a rollup summary field on the Sales Opportunity which basically does store count of related records of "product"

 

In the validation rule, when ever you change status to the "Request Quote" , do a check for the count and see if it is > 0. If it is then you are fine, else throw error.

Regular Contributor
Tanvir Ansari
Posts: 41
0

Re: Related Object Required

I think your data model is not correct if this solution does not work. Please show me the object model because I am able to do it
Regular Contributor
Tanvir Ansari
Posts: 41
0

Re: Related Object Required

If you want I can give access to my developer org and you can check it working. I did this for Job Application object & Review.

Job Application can have multiple reviews, so it is 1 to many relation. There is a status field of picklist which has values "Hired", rejected, ...so on so forth. I created a roll up summary field called "Count of Reviews" which counts how many related child records of review exist. I wrote a validation rule

AND(Number_of_Reviews__c = 0, ISPICKVAL( Status__c , 'Hired') )

What this does is, it checks if the picklist value is "Hired" and the number of reviews is 0, then it throws error saying, you have to have atleast 1 review before you can Hire.
GTE
Newbie
GTE
Posts: 5
0

Re: Related Object Required

Thanks. This looks pretty much what I need. However, I already have my Oporunity object with a large number of records and not all of them have "products" linked to them, so I cannot creat the Master-Detail relationship.

 

I there a way around the loop? If i relate at least one "product" record to each Oportunity will I be able to do it?