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
OutsiderOutsider 

bulk insert

I got error "too many rows" when I run below trigger.  May I know how to make this trigger insert more than 1000 records

 

    List<CampaignMember> NewCampaignMemberList = new List<CampaignMember>();//New Added
    if(ReadyFlag){
        Map<Id, Contact> ContactById = new Map<Id, Contact>([SELECT Id, AccountId FROM Contact
                     WHERE (Account.Member_Status__c = 'Opt-in' AND Account.Is_Member_Created_Last_Week__c = 'Y')]);
        Map<Id, CampaignMember> CampaignMemberById = new Map<Id, CampaignMember>([SELECT Id, CampaignId, ContactId FROM CampaignMember WHERE ContactId in :ContactById.keySet()]);
        for(Id conId : ContactById.keyset()){
            Boolean newflag = true;
            for(id cmId : CampaignMemberById.keyset()){
               if(CampaignMemberById.get(cmid).Campaign.Name == 'Welcome Message' &&
                  CampaignMemberById.get(cmid).Member__c == ContactById.get(conid).AccountId){
                  newflag = false;
               }//end if
            }//end for
            if (newflag){
            NewCampaignMemberList .add(new CampaignMember(CampaignId='70190000000DRhy', ContactId=ContactById.get(conid).Id, Status = 'Selected',
                            Contact_Tool__c='Email', Member__c=ContactById.get(conid).AccountId));

            }//end if
        }//end for
    }//end if
    insert NewCampaignMemberList;//New Added
}

jkucerajkucera

Which API version are you using?  19.0 should be able to handle lists up to ~1mil or so.

 

If you continue to hit other limits, you might want to transition the trigger to batch apex + schedule apex to make it a cron job instead of a synchronous operation.

OutsiderOutsider

how do I check which version of API?

jkucerajkucera

Click on Edit for that tirgger/class and then click Version.