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, 2022 in SalesForce by surbhi
• 3,820 points
595 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, 2022 in SalesForce by surbhi
• 3,820 points
449 views
0 votes
0 answers

What is governor limits in Salesforce?

What does the concept of "governor limits" ...READ MORE

Dec 19, 2023 in SalesForce by Saniya
• 3,360 points
263 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, 2022 in SalesForce by surbhi
• 3,820 points
3,003 views
0 votes
1 answer

Cannot login to Salesforce Sandbox via python API

Set domain='test' and generate a new token ...READ MORE

answered Mar 1, 2022 in SalesForce by CoolCoder
• 4,420 points
1,766 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, 2022 in SalesForce by surbhi
• 3,820 points
2,047 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, 2022 in SalesForce by surbhi
• 3,820 points
994 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
3,270 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,030 points
972 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,030 points
652 views
0 votes
2 answers

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

Hi @Vardhan, I took Edureka's Salesforce Online Training, ...READ MORE

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

edited Dec 22, 2021 by Soumya 683 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