function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ANJALIRAJIANJALIRAJI 

Update the Document Id to User object field.

Hi,

I need to update the document id to user object by matching document name and empolyeeNumber.

 

When I execute the below code, it should get the document id and update the same to the Signature_DocumentID__c by matching the document name and employeeNumber. This code is working for single operation. But not working for bulk operation. It’s crossing the SOQL query limitation.

 

Please give me some guidance to correct this problem.

 

List<Document> data=[select id,Name from Document where FOLDERID = '00lL0000000TB89'];
for (integer i=0;i<data.size();i++) { 
List<User> userdata = [select Signature_DocumentID__c from User where EmployeeNumber=:data[i].name ]; 
    if(userdata.size()>0) { 
        
            userdata[0].Signature_DocumentID__c = data[i].id; 
           update userdata;
}
}

craigmhcraigmh

It has to be bulkified. I'd suggest getting the list of Document records, creating a Map with the Name/Id values, then selecting a full list of User records based on the Name keySet, and assigning the IDs in a loop using the Map.