+ Start a Discussion
HqSeOHqSeO 

Is there any DML operation within those line of codes?

Hello,

I would to know the community opinion if there is any DML operation occurring within the for loop:
FOR LOOP:

//Build the share for each project and each member
for(Id projectId :membersByProjectIds.keySet())
{
    if(Schema.Project__c.sObjectType != projectId.getSobjectType())
        continue;

    //Get the list of members for this project
    Set<Id> memberIds = membersByProjectIds.get(projectId);

    if(memberIds != null && memberIds.size() > 0)
    {
        //Iterate the list of members
        for(Id memberId :memberIds)
        {
            //Test for ID injection
            if(Schema.User.sObjectType != memberId.getSobjectType() && Schema.Group.sObjectType != memberId.getSobjectType())
                continue;

            //Create a share permission record using manager
            Sobject sob = SharePermissionManager.createShareRecord(ConstantHelper.PROJECT_SHARE_OBJECT_NAME, projectId, memberId, permissionAccess, ConstantHelper.PROJECT_SHARE_REASON);

            //Control the result
            if(sob != null)
            {
                //Add the record to the result list
                projectShareList.put(i, sob);
                i++;
            }
        }
    }
}


------------------------------------------------------------------------------------------------------------
UNDERLYING METHOD:

public static SObject createShareRecord(String objectName, Id parentId, Id userId, String accessLevel, String rowCause)
{
    //Control parameter
    if(String.isBlank(objectName) || parentId == null || userId == null || String.isBlank(rowCause) || String.isBlank(accessLevel))
        return null;
    
    //Test the accesslevel
    if(!accesslevel.equals(ConstantHelper.SHARE_ACCESS_LEVEL_READ) && !accesslevel.equals(ConstantHelper.SHARE_ACCESS_LEVEL_EDIT))
        return null;

    Schema.SObjectType shareType = Schema.getGlobalDescribe().get(objectName);

    //Control the return type
    if(shareType == null)
        return null;

    //Instantiate the Share record
    SObject shareRecord = shareType.newSObject();

    //Set each field of the Share record
    shareRecord.put(ConstantHelper.SHARE_PARENTID_COLUMN, parentId);
    shareRecord.put(ConstantHelper.SHARE_USERORGROUPID, userId);

    //Set the accessLevel
    shareRecord.put(ConstantHelper.SHARE_ACCESSLEVEL_COLUMN, accessLevel);
    shareRecord.put(ConstantHelper.SHARE_ROWCAUSE_COLUMN, rowCause);
    
    //Return the record
    return shareRecord;
}

Thanks devs :)
Sylvain​
Nayana KNayana K
There is no DML happening in this code. 
HqSeOHqSeO
I m sorry I have nothing against you, thanks for your answer, but according to SF, there is a DML for loop whithin those lines, anyone else?
Niket SFNiket SF
I am not sure about DML but "Schema.SObjectType shareType = Schema.getGlobalDescribe().get(objectName);" is global describer call in For loop for sure.