Salesforce Batch Governor Limit

0 votes

I am running the following batch and I am making a query inside of a for loop, here is the query:

lgm=[select Group.Name, group.type,group.id, group.ownerID from GroupMember where UserOrGroupId =: u.id];

The batch loops through every person in the org, obtaining their permission sets, as well as the public groups and queues to which they are allocated, as well as their name and id, and populating those details into a custom object named ConsolidatedUser.

I haven't yet tested the batch with a big number of records to see if the governor restrictions are reached, and I'd want your input. As it stands, the batch works ok. Can you tell me how many soql queries are allowed per transaction in a batch so that I don't run into any conflicts? Here is my code, and I appreciate your assistance.

global class TDTRMIS_GetUserDetails implements  Database.Batchable<sObject>, Database.Stateful {

global string UserPermissionSets='';
global string UserGroups='';
global string UserQueues='';
global integer i;

    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT Id, name, (select PermissionSet.Name, AssigneeId FROM PermissionSetAssignments)  from user' 
        );
    }

    global void execute(Database.BatchableContext bc, List<User> scope){
        // process each batch of records

                // process each batch of records

        List<ConsolidatedUser__c> lcu = new List<ConsolidatedUser__c>();
        list<GroupMember> lgm= new list<GroupMember>();
        for (User u : scope)
        {


            ConsolidatedUser__c cu= new ConsolidatedUser__c();
            lgm=[select Group.Name, group.type,group.id, group.ownerID from GroupMember where UserOrGroupId =: u.id];


            for(PermissionSetAssignment ps : u.PermissionSetAssignments)
                {
                UserPermissionSets=UserPermissionSets+ps.PermissionSet.name+'|';        
                }


            for(GroupMember gm : lgm)
            {

                 if(gm.group.type=='Regular' )
                 {
                 UserGroups=UserGroups+gm.group.Name+'|';
                 }

                 else if(gm.group.type=='Queue' )
                 {
                 UserQueues=UserQueues+gm.group.Name+'|';  
                 } 

            }  


            cu.PermSet__c=UserPermissionSets ;  
            cu.PublicGroupList__c=UserGroups;
            cu.QueueGroupList__c= UserQueues;
            cu.User_Lookup__c=u.id;    
            cu.name=u.name;
            lcu.add(cu);
        } 

    try{
    upsert lcu;
    }

    catch(exception e)
    {
    system.debug(e);
    }

    }  

    global void finish(Database.BatchableContext bc){

    //to be added later

    }    

}

Apr 1 in SalesForce by surbhi
• 3,810 points
56 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In SalesForce

0 votes
0 answers

Upsert Bulk vs Batch Upsert in Salesforce

I'm attempting to import a significant amount ...READ MORE

Apr 5 in SalesForce by surbhi
• 3,810 points
95 views
0 votes
0 answers

Salesforce Apex SingleEmailMessage with Template to User not contact

Im trying to send an email in ...READ MORE

Feb 28 in SalesForce by surbhi
• 3,810 points
1,522 views
0 votes
0 answers

Cannot login to Salesforce Sandbox via python API

I am using the python3.7.2 module simple-salesforce==0.74.2 and I ...READ MORE

Mar 1 in SalesForce by surbhi
• 3,810 points
481 views
0 votes
0 answers

Salesforce Test Class - System.NullPointerException: Attempt to de-reference a null object

Salesforce Test Class - Facing - System.NullPointerException: ...READ MORE

Mar 1 in SalesForce by surbhi
• 3,810 points
1,048 views
0 votes
0 answers

How to take test.salesforce.com while deployment as salesforce login url for api connection logic app?

In logic app i'm using salesforce connector after deployment ...READ MORE

Mar 1 in SalesForce by surbhi
• 3,810 points
396 views
0 votes
1 answer

Salesforce Test Class - System.NullPointerException: Attempt to de-reference a null object

Because testAccount.account is never set, it is ...READ MORE

answered Mar 2 in SalesForce by surbhi
• 3,810 points
835 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
2,016 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,050 points
357 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,050 points
237 views
0 votes
1 answer

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Training that covers all ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 260 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP