2017-02-23 16 views
0

나는 다음과 같은 배치를 실행하고 나는 루프에 대한 내부 쿼리를 만드는 중이라서, 여기에 쿼리입니다 :세일즈 포스 배치 주지사 제한

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

배치는 조직의 모든 사용자에 루핑 및 도착 해당 권한 집합 및 그가 할당 된 공용 그룹 및 큐와 해당 사용자의 이름과 ID를 수집 한 다음 해당 정보를 ConsolidatedUser라는 사용자 지정 개체에 채 웁니다.

아직 많은 양의 배치를 실행하지 않았습니다 총재 한도에 도달했는지 확인하고 귀하의 의견을 듣고 싶습니다. 지금 당장 일괄 처리가 올바르게 작동합니다. 일괄 처리의 트랜잭션 당 허용되는 smql 쿼리 수를 묻는다면 충돌이 발생하지 않도록 할 수 있습니다. 여기 내 코드이며 도움을 주셔서 감사합니다.

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 

    }  

} 
+0

답을 찾았습니까? –

답변

0

이것은 당신이 SOQL 총재 제한에 대해 알아야 할 모든 설명 :

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

을 기본적으로 트랜잭션 당 SOQL 총재 제한 그것은 넣어하는 것은 좋은 방법이 아닙니다 (100)

입니다 루프 내에서 SOQL 쿼리.

https://developer.salesforce.com/page/Apex_Code_Best_Practices

+0

답장을 보내 주셔서 감사합니다. SOQL 쿼리에 대한 두 가지 유형의 제한이 있습니다. 100 및 200 개의 검색어를 사용하면이 배치의 한도가 어느 것이 될지 물어볼 수 있습니까? 고맙습니다. – Sam

+0

@ arun-kumar가 대답에 언급했듯이, 200은 배치 트랜잭션의 한도입니다. – Steve

1

배치 에이펙스는 비동기 에이펙스 간주됩니다, 그래서 "발행 SOQL 쿼리의 총 수는"귀하의 경우 제한이 제한은 배치의 하나의 실행을위한 200 될 것입니다 : 대안에 대해 다음을 참조하십시오 .

사용자 루프에서 SOQL을 제거하는 것이 좋습니다. List for 사용자 내의 목록에있는 사용자 ID를 수집하여 for 루프를 작성한 다음 단일 SOQL 쿼리를 작성하여 사용자 ID 목록을 사용하여 GroupMember 목록을 가져옵니다.

다음은 관련 링크입니다. https://help.salesforce.com/articleView?id=000176644&language=en_US&type=1