function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GTEGTE 

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

Tanvir AnsariTanvir Ansari

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.

GTEGTE

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?

Tanvir AnsariTanvir Ansari
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
Tanvir AnsariTanvir Ansari

Did it work?

GTEGTE

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

Tanvir AnsariTanvir Ansari

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.

Tanvir AnsariTanvir Ansari
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
Tanvir AnsariTanvir Ansari
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.
GTEGTE

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?

Tanvir AnsariTanvir Ansari

Not sure what you are saying. You do not need Master Detail relation here. You have a related list, that means you have created lookup relation and that is what is needed.

 

The solution given works for you, as long as you will add a rollup summary field and create validation rule based on change in picklist value on status

Tanvir AnsariTanvir Ansari
You can email me or call me as I can not really understand the whole issue. Do you want to do data cleansing?
GTEGTE

Thanks.

 

I need a Master - Detail relationship field in my object to create a Rollup field

Tanvir AnsariTanvir Ansari
Why? TO create Rollup you do not need Master Detail relation.

You already must be having a lookup field on the Product which is linked to Sales Opportunity. That is what you will use.
Tanvir AnsariTanvir Ansari
I sent you my phone number through private message, if you want you can call me and I can walk you through
Tanvir AnsariTanvir Ansari

My bad, my mistake, really appologize for this. Yes the mAster Detail is needed for roll up field. I created the objects long ago and I run all my test on that, and I really missed checking that I had created that relation.

 

Let me think.