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
Jay reddyJay reddy 

Need help on Custom Setting Logic

Hello,

I have a requirement where we have Subscription products and in that some should be sold for definite time period [3 months] and the rest of the products from the similar category can be sold for any time period. For this I have created a CUSTOM SETTING for the products which should be sold for definite time period [3 months] but seems my logic is incorrect and throwing the same second error [see below in the code] for the products which are in CUSTOM SETTING. They do have different error.
 
Set<String> ExcludeSubProdIds = new Map<String, Product2> ([Select Name,ProductCode from Product2 WHERE  ProductCode IN: SubscriptionProducts__c.getAll().keySet()]).keySet();

for(Quotelineitem qli:QLIList){
if(qli.Product_Code__c.contains('SUB')) {
             if(ExcludeSubProdIds.contains(qli.Product_Code__c) && (qli.Number_of_Terms__c !=3 || decimavalue!=0) ){
             qli.adderror('Error. Please check dates');
             }  else if(!ExcludeSubProdIds.contains(qli.Product_Code__c) && (qli.Number_of_Terms__c==  0 ||decimavalue!=0))  {
             qli.adderror('Term Periods must be in whole months (for SUB products) and whole years  products.');
         }
             }
             }

 
Ashish KeshariAshish Keshari
Hi Girish,
Can you please share snap of your Custom Settings and also wondering, why not use Custom Metadata Types instead of Custom Settings ?
Jay reddyJay reddy

Hello Ashish,

Here it is...Setting Type is LIST User-added image
 
Ashish KeshariAshish Keshari
Hi Girish,
I did not look at the logic but what I am seeing you are adding "qli.adderror()" in both if and elseif condition. I would suggest to put System.debug and see the flow and test it out. thanks.