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
Ceejay djoCeejay djo 

Creating A Record based on a Condition with Apex Class

I have these set of records (Master (Business Mix records) and Child (Payor Mix records) that are automatically created when a lead record is created and its corresponding RA (related object) are created.

Here is the code below:

My challenge is I need to add a condition to this code. Rather I want a condition that says if a lead field value, checkbox called  ( In_Office_Injections__c ) is selected and another lead field value (Lead_State__c) or Opportunity field value (State__c)  is NC, then only create records for NC (Master and Child records (Business Mix and Payor Mix) records).

If this condition does not hold, all records can be created as usual.

I need help from anyone out there who can modify this code to meet this criteria.

Thanks Thanks Thanks!



Map<ID, Business_Mix__c> raDfltIdToBizMix = new Map<ID, Business_Mix__c>();
        Map<Business_Mix__c, Integer> bizMixToIndex = new Map<Business_Mix__c, Integer>();
        for (Integer radi = 0; radi < bizMixDflts.size(); radi++) {
            RA_Default__c rad = bizMixDflts[radi];
            Business_Mix__c bizMixToInsert = new Business_Mix__c(
                Name = rad.Name,
                Tiered_Fee_Percent_95004__c = rad.Default_Tiered_Fee_Percent_95004__c,
                Tiered_Fee_Percent_95165__c = rad.Default_Tiered_Fee_Percent_95165__c,
                Type__c = rad.Type__c,
                Business_Mix_Percentage__c = 0
            );
            this.bizMixes.add(bizMixToInsert);
            raDfltIdToBizMix.put(rad.ID, bizMixToInsert);
            bizMixToIndex.put(bizMixToInsert, radi);
        }
        
        for (Integer bmi = 0; bmi < this.bizMixes.size(); bmi++) {
            this.bizMixPayorMixes.add(new Payor_Mix__c[0]);
            this.bizMixPayorMixWraps.add(new PayorMixWrap[0]);
        }
        
        for (RA_Default__c rad : payMixDflts) {
            Business_Mix__c parentBizMix = raDfltIdToBizMix.get(rad.Parent__c);
            Integer parentBizMixIndex = bizMixToIndex.get(parentBizMix);
            Payor_Mix__c payMixToInsert = new Payor_Mix__c(
                Name = rad.Name,    
                Units_95004__c = rad.Default_Units_95004__c,
                Units_95165__c = rad.Default_Units_95165__c,
                PayorType__c = rad.Type__c,
                Payor_Mix_Percentage__c = 0                    
            );
            this.bizMixPayorMixes[parentBizMixIndex].add(payMixToInsert);
            this.bizMixPayorMixWraps[parentBizMixIndex].add(new PayorMixWrap(payMixToInsert));
        }
        
        for (Payor_Mix__c[] pml : this.bizMixPayorMixes) {
            if (pml != null && pml.size() == 1) {
                pml[0].Payor_Mix_Percentage__c = 100;
            }
        }
    }


Ramu_SFDCRamu_SFDC
Add an if condition at the beginning of this class to see if the In_Office_Injections__c is checked and Lead_State__c (or) State__c is NC. Wrap the complete code within this if condition.