Skip to main content
Shraddha Gupta perguntou em #Apex
 

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 = System.now().addDays(-30);                            

            List<Contact> contactsToInsertFromZoominfo = new List<Contact>();

            for(Contact contactToInsert : System.Trigger.new){

                if (contactToInsert.LeadSource == 'Zoominfo'){

                    contactsToInsertFromZoominfo.add(contactToInsert);

                }

            }

            //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.

Thanks!

 

 
1 resposta
  1. 19 de jan. de 2021, 18:26
    Hi Shraddha,

    Greetings!

    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.

    Reference:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm

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

    Warm Regards,

    Shirisha Pathuri
0/9000