+ Start a Discussion
Steven Wellman 28Steven Wellman 28 

Help bulkifying a trigger

How would you bulkify this trigger? I have a SOQL query in a loop and understand that to be a no no. Appreciate any help.
trigger CreateOnboardings on Zuora__SubscriptionRatePlan__c (before insert) {

	for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){

		Account myAccount = [SELECT Id, OwnerId, Name, Local_Listings__c, Reviews__c, LMEL__c, Social_Ads__c, Social_Posting__c, SEO__c, Website_Product__c FROM Account WHERE Id = :mysub.Zuora__Account__c LIMIT 1];

		// Local Marketing Essentials Lite
		if (mysub.Name.contains('Local Marketing Essentials Lite')){
		/*	Onboarding__c onb = new Onboarding__c();
			onb.Account__c = ________;
			onb.Name = 'Local Marketing Essentials Lite + ' + ________;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = ________;*/
			myAccount.LMEL__c = true;
		}

		// Marketing Essentials Pro
		if (mysub.Name.contains('Marketing Essentials Pro')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Local Listings + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Local_Listings__c = true;

			insert onb;
		}

		// Local Listings
		if (mysub.Name.contains('Local Listings Pro')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Local Listings + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Local_Listings__c = true;

			insert onb;
		}

		// Engage
		if (mysub.Name.contains('Engage')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Engage + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMBQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Engage__c = true;

			insert onb;
		}

		// Reviews
		if (mysub.Name.contains('Reviews')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Reviews + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkM6QAK';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Reviews__c = true;

			insert onb;
		}

		// SEO
		if (mysub.Name.contains('SEO')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'SEO + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMVQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.SEO__c = true;

			insert onb;
		}

		// Social Ads
		if (mysub.Name.contains('Social Ads')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Social Ads + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMLQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Social_Ads__c = true;

			insert onb;
		}

		// Social Posting
		if (mysub.Name.contains('Social Posting')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Social Posting + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMQQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Social_Posting__c = true;

			insert onb;
		}

		// Website
		if (mysub.Name.contains('Website')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Website + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMGQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Website_Product__c = true;

			insert onb;
		}
		update myAccount;
	}

}

 
Best Answer chosen by Steven Wellman 28
AshishkAshishk
trigger CreateOnboardings on Zuora__SubscriptionRatePlan__c (before insert) {
    
    List<Onboarding__c> onBoardingListToInsert = new List<Onboarding__c>();
    set<id> setAccIds=new set<id>();
    for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){
        if(mysub.Zuora__Account__c!=null)
            setAccIds.add(mysub.Zuora__Account__c);
    }
	List<Account> lstAccountsToUpdate=new List<Account>();
	Map<id,Account> mapAccounts=new Map<id,Account> ([SELECT Id, OwnerId, Name, Local_Listings__c, Reviews__c, LMEL__c, Social_Ads__c, Social_Posting__c, SEO__c, Website_Product__c FROM Account WHERE Id in :setAccIds]);
  

    for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){
		if(mapAccounts.containsKey(mysub.Zuora__Account__c)){
			Account myAccount=mapAccounts.get(mysub.Zuora__Account__c);
			// Local Marketing Essentials Lite
			if (mysub.Name.contains('Local Marketing Essentials Lite')){
			/*    Onboarding__c onb = new Onboarding__c();
				onb.Account__c = ________;
				onb.Name = 'Local Marketing Essentials Lite + ' + ________;
				onb.RecordTypeId = '0121I000000Fk7BQAS';
				onb.Sales_Rep__c = ________;*/
				myAccount.LMEL__c = true;
			}

			// Marketing Essentials Pro
			if (mysub.Name.contains('Marketing Essentials Pro')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Local Listings + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000Fk7BQAS';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Local_Listings__c = true;
			 
				onBoardingListToInsert.add(onb);
			}

			// Local Listings
			if (mysub.Name.contains('Local Listings Pro')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Local Listings + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000Fk7BQAS';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Local_Listings__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Engage
			if (mysub.Name.contains('Engage')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Engage + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMBQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Engage__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Reviews
			if (mysub.Name.contains('Reviews')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Reviews + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkM6QAK';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Reviews__c = true;

				onBoardingListToInsert.add(onb);
			}

			// SEO
			if (mysub.Name.contains('SEO')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'SEO + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMVQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.SEO__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Social Ads
			if (mysub.Name.contains('Social Ads')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Social Ads + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMLQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Social_Ads__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Social Posting
			if (mysub.Name.contains('Social Posting')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Social Posting + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMQQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Social_Posting__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Website
			if (mysub.Name.contains('Website')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Website + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMGQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Website_Product__c = true;

				onBoardingListToInsert.add(onb);
			}
			lstAccountsToUpdate.add(myAccount);
		}
	}
    
      if(onBoardingListToInsert.size()>0){
          insert onBoardingListToInsert;
      }

		if(lstAccountsToUpdate.size()>0){
          update lstAccountsToUpdate;
      }	
}

Try this, hope works.

All Answers

Raj VakatiRaj Vakati
try this
 
trigger CreateOnboardings on Zuora__SubscriptionRatePlan__c (before insert) {

	for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){

		Account myAccount = [SELECT Id, OwnerId, Name, Local_Listings__c, Reviews__c, LMEL__c, Social_Ads__c, Social_Posting__c, SEO__c, Website_Product__c FROM Account WHERE Id = :mysub.Zuora__Account__c LIMIT 1];
List<Onboarding__c> onbList = new List<Onboarding__c>();
		// Local Marketing Essentials Lite
		if (mysub.Name.contains('Local Marketing Essentials Lite')){
		/*	Onboarding__c onb = new Onboarding__c();
			onb.Account__c = ________;
			onb.Name = 'Local Marketing Essentials Lite + ' + ________;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = ________;*/
			myAccount.LMEL__c = true;
		}

		// Marketing Essentials Pro
		if (mysub.Name.contains('Marketing Essentials Pro')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Local Listings + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Local_Listings__c = true;
onbList.add(onb);
			}

		// Local Listings
		if (mysub.Name.contains('Local Listings Pro')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Local Listings + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Local_Listings__c = true;
onbList.add(onb);

		}

		// Engage
		if (mysub.Name.contains('Engage')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Engage + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMBQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Engage__c = true;
onbList.add(onb);

		}

		// Reviews
		if (mysub.Name.contains('Reviews')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Reviews + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkM6QAK';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Reviews__c = true;

		onbList.add(onb);
	}

		// SEO
		if (mysub.Name.contains('SEO')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'SEO + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMVQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.SEO__c = true;
onbList.add(onb);

		}

		// Social Ads
		if (mysub.Name.contains('Social Ads')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Social Ads + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMLQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Social_Ads__c = true;
onbList.add(onb);
		}

		// Social Posting
		if (mysub.Name.contains('Social Posting')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Social Posting + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMQQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Social_Posting__c = true;
onbList.add(onb);
		}

		// Website
		if (mysub.Name.contains('Website')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Website + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMGQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Website_Product__c = true;
onbList.add(onb);
		}
		
		insert onbList ;
		update myAccount;
	}

}

 
Steven Wellman 28Steven Wellman 28
What about the Soql query in the loop?
Ajay K DubediAjay K Dubedi
Hi Steven,
Please try this code:


trigger CreateOnboardings on Zuora__SubscriptionRatePlan__c (before insert) {
    
    List<Onboarding__c> onbList = new List<Onboarding__c>();
    set<id> Accid=new set<id>();
    for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){
        if(mysub.Zuora__Account__c!=null)
            Accid.add(mysub.Zuora__Account__c);
    }
   Account myAccount = [SELECT Id, OwnerId, Name, Local_Listings__c, Reviews__c, LMEL__c, Social_Ads__c, Social_Posting__c, SEO__c, Website_Product__c FROM Account WHERE Id in :Accid LIMIT 1];

    for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){
        // Local Marketing Essentials Lite
        if (mysub.Name.contains('Local Marketing Essentials Lite')){
        /*    Onboarding__c onb = new Onboarding__c();
            onb.Account__c = ________;
            onb.Name = 'Local Marketing Essentials Lite + ' + ________;
            onb.RecordTypeId = '0121I000000Fk7BQAS';
            onb.Sales_Rep__c = ________;*/
            myAccount.LMEL__c = true;
        }

        // Marketing Essentials Pro
        if (mysub.Name.contains('Marketing Essentials Pro')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'Local Listings + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000Fk7BQAS';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.Local_Listings__c = true;
         
            onbList.add(onb);
        }

        // Local Listings
        if (mysub.Name.contains('Local Listings Pro')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'Local Listings + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000Fk7BQAS';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.Local_Listings__c = true;

            onbList.add(onb);
        }

        // Engage
        if (mysub.Name.contains('Engage')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'Engage + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000FkMBQA0';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.Engage__c = true;

            onbList.add(onb);
        }

        // Reviews
        if (mysub.Name.contains('Reviews')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'Reviews + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000FkM6QAK';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.Reviews__c = true;

            onbList.add(onb);
        }

        // SEO
        if (mysub.Name.contains('SEO')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'SEO + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000FkMVQA0';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.SEO__c = true;

            onbList.add(onb);
        }

        // Social Ads
        if (mysub.Name.contains('Social Ads')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'Social Ads + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000FkMLQA0';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.Social_Ads__c = true;

            onbList.add(onb);
        }

        // Social Posting
        if (mysub.Name.contains('Social Posting')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'Social Posting + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000FkMQQA0';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.Social_Posting__c = true;

            onbList.add(onb);
        }

        // Website
        if (mysub.Name.contains('Website')){
            Onboarding__c onb = new Onboarding__c();
            onb.Account__c = myAccount.Id;
            onb.Name = 'Website + ' + myAccount.Name;
            onb.RecordTypeId = '0121I000000FkMGQA0';
            onb.Sales_Rep__c = myAccount.OwnerId;
            onb.Status__c = 'Not Started';
            myAccount.Website_Product__c = true;

            onbList.add(onb);
        }
        
    }
    update myAccount;
      if(onbList.size()>0){
          insert onbList;
      }

}



I hope this will help you.

Thank You
Ajay Dubedi
AshishkAshishk
trigger CreateOnboardings on Zuora__SubscriptionRatePlan__c (before insert) {
    
    List<Onboarding__c> onBoardingListToInsert = new List<Onboarding__c>();
    set<id> setAccIds=new set<id>();
    for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){
        if(mysub.Zuora__Account__c!=null)
            setAccIds.add(mysub.Zuora__Account__c);
    }
	List<Account> lstAccountsToUpdate=new List<Account>();
	Map<id,Account> mapAccounts=new Map<id,Account> ([SELECT Id, OwnerId, Name, Local_Listings__c, Reviews__c, LMEL__c, Social_Ads__c, Social_Posting__c, SEO__c, Website_Product__c FROM Account WHERE Id in :setAccIds]);
  

    for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){
		if(mapAccounts.containsKey(mysub.Zuora__Account__c)){
			Account myAccount=mapAccounts.get(mysub.Zuora__Account__c);
			// Local Marketing Essentials Lite
			if (mysub.Name.contains('Local Marketing Essentials Lite')){
			/*    Onboarding__c onb = new Onboarding__c();
				onb.Account__c = ________;
				onb.Name = 'Local Marketing Essentials Lite + ' + ________;
				onb.RecordTypeId = '0121I000000Fk7BQAS';
				onb.Sales_Rep__c = ________;*/
				myAccount.LMEL__c = true;
			}

			// Marketing Essentials Pro
			if (mysub.Name.contains('Marketing Essentials Pro')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Local Listings + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000Fk7BQAS';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Local_Listings__c = true;
			 
				onBoardingListToInsert.add(onb);
			}

			// Local Listings
			if (mysub.Name.contains('Local Listings Pro')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Local Listings + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000Fk7BQAS';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Local_Listings__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Engage
			if (mysub.Name.contains('Engage')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Engage + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMBQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Engage__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Reviews
			if (mysub.Name.contains('Reviews')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Reviews + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkM6QAK';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Reviews__c = true;

				onBoardingListToInsert.add(onb);
			}

			// SEO
			if (mysub.Name.contains('SEO')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'SEO + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMVQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.SEO__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Social Ads
			if (mysub.Name.contains('Social Ads')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Social Ads + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMLQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Social_Ads__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Social Posting
			if (mysub.Name.contains('Social Posting')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Social Posting + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMQQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Social_Posting__c = true;

				onBoardingListToInsert.add(onb);
			}

			// Website
			if (mysub.Name.contains('Website')){
				Onboarding__c onb = new Onboarding__c();
				onb.Account__c = myAccount.Id;
				onb.Name = 'Website + ' + myAccount.Name;
				onb.RecordTypeId = '0121I000000FkMGQA0';
				onb.Sales_Rep__c = myAccount.OwnerId;
				onb.Status__c = 'Not Started';
				myAccount.Website_Product__c = true;

				onBoardingListToInsert.add(onb);
			}
			lstAccountsToUpdate.add(myAccount);
		}
	}
    
      if(onBoardingListToInsert.size()>0){
          insert onBoardingListToInsert;
      }

		if(lstAccountsToUpdate.size()>0){
          update lstAccountsToUpdate;
      }	
}

Try this, hope works.
This was selected as the best answer
Steven Wellman 28Steven Wellman 28
That worked! Thank you!