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
degmodegmo 

Generate records based on criteria

Hello All,
On the Account object, I have a several fields that are used for defining a set of thresholds for Account records. There are a total of 12 such fields and a few examples of those fields are:  Account_Balance_Criteria__c, Account_Asset_Criteria__c, Account_Region_Criteria__c, etc.  I also have two custom objects:  Transaction__c and VIP_Member__cTransaction__c  has a lookup to the Account object and VIP_Member__c  has a master detail relationship to Transaction__cVIP_Member__c has two record types; Accepted VIP Members and Denied VIP Members.
 
My requirement is that when a user clicks on a button called 'Generate VIP Members' from a 'Transaction' record page, the system will evaluate all existing Account records based on the criteria fields of the 'Account' related to the 'Transaction' record.  It then creates a 'VIP Members' record for each Account that matches all the criteria defined.  If the user creates 'Generate VIP' again, the 'VIP Members' records will be overwritten. 

For example, let's say I have Transaction A that is related to Account A.  The only criteria field that is populated for Account A is Account Balance and it has a value of $1,000.  Let's also say Accounts B, C, and D have a Balance of $0 and Account E has a Balance of $1000.  In this scenario, a VIP Member record with the record type of 'Accepted VIP Members' will be created for Account E and three VIP Member records with the record type of 'Denied VIP Members' will be created; one each for Accounts B, C, and D.  For the 'Denied VIP Members', it is also necessary for me to keep track of the criteria that caused them to be denied.

 
I am looking for an opinion on the best design approach for this.  I know I have to build an Apex class but I want to make sure it's scalable and efficient.  My initial thoughts were to get a list of Accounts that meet the criteria and maintain two separate lists for 'accepted' and 'denied' and do the evaluation inside of a loop.  Any thoughts or comments will be appreciated.