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
Shraddha D GuptaShraddha D Gupta 

APEX Trigger to Flow/PB

Hi Team,

Could you please help me in migrating below Trigger to Flow/PB if that is possible -

trigger limitCreationsFromZoominfo on Contact (before insert) {
//This trigger limit to 25 the number of contacts that can be created from Zoominfo per person per month (#7692)
//We can detect that the Contact comes from Zoominfo because: LeadSource = "Zoominfo"
//We need to filter the existing contacts (for the count operation) using the fields: 
//  CreatedBy = <same user> 
//  CreatedDate = <in the last 30 days> 
//  LeadOrigin = "Zoominfo"
//  Users with roles "System Administrator", "Denodo Systems Integration" or "Operations Supervisor" should not be affected by this rule.
    Id profileId = UserInfo.getProfileId();
    String profileName=[Select Id, Name from Profile where Id=:profileId].Name; 
    if ( !profileName.contains('Operations Supervisor') && !profileName.contains('System Administrator') 
            && !profileName.contains('Denodo Systems Integration')){
            String userId = UserInfo.getUserId();
            Datetime limitDate =;                            
            List<Contact> contactsToInsertFromZoominfo = new List<Contact>();
            for(Contact contactToInsert :{
                if (contactToInsert.LeadSource == 'Zoominfo'){
            //if there are insertions from Zoominfo, check the limit
            if (contactsToInsertFromZoominfo.size() > 0) {
                List<AggregateResult> currentContactsZoominfo = [SELECT Count(Id) currentContacts FROM Contact 
                                      WHERE Lead_Origin__c ='Zoominfo' and CreatedDate >= :limitDate and CreatedById = :userId];
                for (Contact contactToInsert : contactsToInsertFromZoominfo) {
                    if ( (Integer.valueOf(currentContactsZoominfo.get(0).get('currentContacts')) + contactsToInsertFromZoominfo.size()) > 25 ){
                        contactToInsert.addError('You can not import more than 25 contacts from Zoominfo in 30 days.');                        

Basically, this trigger is to restrict specific profile to import contacts from Zoominfo to SFDC if number exceeds 25 in a month. 

Any help would be much appreciated.

ShirishaShirisha (Salesforce Developers) 
Hi Shraddha,


I don't think this is possible only with the Process builder or Flow alone.You might need to use an @Invocable method where you need to query the profile of the user who is creating the records and restrict as you do in the trigger.


Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri