You need to sign in to do that
Don't have an account?
RestAPI Uer
Validation in trigger based on unique price on Quoteline item object
Hello All,
Let me explain the scenario in detail here. So I have one Quote record. For that they 10 line items. I am using the following three fields:
How to achieve this scenario? Is this possible through validation rule?
Thanks in advance
Let me explain the scenario in detail here. So I have one Quote record. For that they 10 line items. I am using the following three fields:
- Reference URN Number(Integer)
- Quantity(Number)
- Estimated Amount(Currency)
- same URN number, Quantity and Amount.
- Same URN number, Amount. But Quantity is unique
- Same URN number, Quantity but Amount is unique.
How to achieve this scenario? Is this possible through validation rule?
Thanks in advance
To do what you are after, I would:
Create a trigger on the Quote Line Item record.
On Insert or Update
Get the Quote Id from the parent record ( parentQuoteId = quoteLineItem.QuoteId)
Using that ID, do a SELECT statement of all QuoteLineItems where the QuoteId = parentQuoteId
Then loop the results to Set of Ids of the URN number. (sets are unique so duplicates will get eliminated)
Test the size of the Set against the Size of list of QuoteLineItems.
If the sizes aren't the same, then there are some duplication of URN numbers
//now the tricky bit.
create 1 x maps
where Map<String, QuoteLineItem> where string is a concatenated string consisting of the URN + Quantity + Amount.
Map.put<key, quotelineitem>
Test the size of the Map now
If the map size is smaller again, then we have duplication of the key, therefore the duplication of URN with Quantity with Amount.
Now at this point we can either
Throw an error. - This will stop the quotelineitem being saved in the first place.
OR
we can update a field on the quote record (check box - duplicate quote items ) which we then test in the validation rule.
At the last step, you could use a Set again, as noted they are unique, i only suggested a map as you may want some reference to the quotelineitem in your error message.
That is a random, off the top of my head idea.
Regards
Andrew