You need to sign in to do that
Don't have an account?
SKT
How to get Parent Ids of User
I have a requirement to get all the Project Ids of Resource under User Detail page.
Below is my Object Schema:
Parent: Project (Field: ProjectId)
Child: Timecard (Field: Project__c, Resource_Name__c)
Now, if the Resource Name under timecard matches with User Name, the Project Ids from that timecard should be stored on User detail page separated by a semicolon.
Below is my logic that I have achieved so far:
Now when i execute the above logic, Project Ids under User record is getting updated with some random Project IDs but not from the timecard where the User name is matching. Instead of pulling all the project Ids that the resource is working under, I am seeing some random project ids
Is there anyway that I can update user records with the exact project ids that matches resource name with user name in timecard under a project?
Below is my Object Schema:
Parent: Project (Field: ProjectId)
Child: Timecard (Field: Project__c, Resource_Name__c)
Now, if the Resource Name under timecard matches with User Name, the Project Ids from that timecard should be stored on User detail page separated by a semicolon.
Below is my logic that I have achieved so far:
list<user> user = [SELECT name from User where isactive = true]; list<string> str = new list<string>(); for(user u1 : user){ str.add(u1.name); } List <Timecard__c> timecard = [ SELECT ID,Project__c,resource_name__c FROM Timecard__c Where Resource_name__c = :str and Project__c != null and Resource_Name__c != null]; set<string> allProsset = new set<string>(); for (Timecard__c timecards : timecard) { allProsset.add(timecards.Project__c); } list<string>allProsList = new list<string>(allProsset); list<User> userupdates = new list<user>(); for(User us : user){ us.Project_Ids__c = String.join(allProsList,';'); userupdates.add(us); } update userupdates;
Now when i execute the above logic, Project Ids under User record is getting updated with some random Project IDs but not from the timecard where the User name is matching. Instead of pulling all the project Ids that the resource is working under, I am seeing some random project ids
Is there anyway that I can update user records with the exact project ids that matches resource name with user name in timecard under a project?
Batch Class:
To Execute the above batch :
We run the batch class based on the user count... So below the batch will pick 10 users per execution.
Run the below code in Dev Console or in Workbench.
Thanks,
Maharajan.C
All Answers
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Try the below code:
Thanks,
Maharajan.C
@Maharajan,
The issue here is that, under a project, there will be multiple timecard records filled by a resource. So, is there anyway we can remove duplicate project Ids from the Project Ids that we are passing to User object?
Please suggest
Thanks,
Maharajan.C
Yeah i got this update resolved..but when i run it for users for this year, I am able to update the users but when I tried to do it for users created in last year and so on, i am seeing the error as "System.LimitException: Too many query rows: 50001".
But I have hardly 200 users but the issue seems to be from timecard query. Is there anyway that I can overcome this error? If i limit the timecard soql, i might miss few records for users.
Please suggest
Batch Class:
To Execute the above batch :
We run the batch class based on the user count... So below the batch will pick 10 users per execution.
Run the below code in Dev Console or in Workbench.
Thanks,
Maharajan.C
Could you please let me know what could be the reason behind this and could you suggest how to overcome this error?
Thanks!
I think it's seems your org has more inactive picklist values. it's crossing the Salesforce Limit i think.
So your team have to perform the clean up activities on inactive picklist values across the objects.
Otherwise you can incresase the limit but it's recommended by Salesforce. Read the below article fully then take the decision.
https://help.salesforce.com/articleView?id=release-notes.rn_forcecom_fields_inactive_picklists.htm&release=230&type=5 (https://help.salesforce.com/articleView?id=release-notes.rn_forcecom_fields_inactive_picklists.htm&release=230&type=5)
https://help.salesforce.com/articleView?id=release-notes.rn_forcecom_fields_inactive_picklist.htm&type=5&release=232 (https://help.salesforce.com/articleView?id=release-notes.rn_forcecom_fields_inactive_picklist.htm&type=5&release=232)
I hopy my answers helped you... Can you please mark the best answer to close this thread...
Thanks,
Maharajan.C