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
Susan Love 2Susan Love 2 

Change Code

We have existing code in our org which had been written when we had one product, we now have three other products.  We require this code to be changed to include these other three products, code below:

List renewalProductList = [SELECT Id, Name, Descripton, ProductCode FROM Product2 WHERE ProductCode = 'SUBS-R'];

Can anybody help me change this code to enable it to recognise the other three products.

Thanks
Susan
 
Lokeswara ReddyLokeswara Reddy
Hi Susan,

1. Define a list and add all product codes ( Better if you do it using custom settings so that product codes can be added/removed without a change in code)
List<String> productCodeList = new List<String>();

2. Add all your products to the list ( if your approach is custom settings, then get the values from custom settings and add them in the list
productCodeList.add('SUBS-R');
productCodeList.add('SUBS-S');
productCodeList.add('SUBS-T');

3. Update your query to pass this list as an argument to fileter the resulst
 
List renewalProductList = [SELECT Id, Name, Descripton, ProductCode FROM Product2 WHERE ProductCode IN:productCodeList];

Regards
Lokesh
 
Susan Love 2Susan Love 2
Thanks Lokesh for your reply.  That worked although its putting a list of all the products on the contract rather than the specific renewal product would this code work if for example SUBS-R (renewal product) = SUBS-I (Initial Product), or would that require totally new code?

Susan