You need to sign in to do that
Don't have an account?
Rishabh Patel 1
Update Custom Object Field with List Results -Apex
I have made an @invocableMethod , And I grab some values like Queue ID and Record ID form my Custom Object (QueueDistroHelper__c) .
All I want to do is Get all users who are in the Queue (I grab the queue ID from custom field on the Custom object) . And then show all that users on a field called Queue_Members__c on same Custom object .
I am not able to add the results to custom field
Here is my code
So all I want to do is add the test.name to Queue_Members__c
All I want to do is Get all users who are in the Queue (I grab the queue ID from custom field on the Custom object) . And then show all that users on a field called Queue_Members__c on same Custom object .
I am not able to add the results to custom field
Here is my code
global class lookUpAccountAnnotation { public class inputValues{ @InvocableVariable(label='Queue ID' required=true) public string QueueId; @InvocableVariable(label='Record Id' required=true) public Id recordid; } @InvocableMethod public static void deletePackageLicense(List<inputValues> inputs){ for (inputValues i : inputs) { List<QueueDistroHelper__c> getcurrentobject = [SELECT Queue_Members__c FROM QueueDistroHelper__c WHERE Id=:i.recordid LIMIT 1]; List<User> users = [SELECT id,name FROM user WHERE id IN ( SELECT userOrGroupId FROM groupmember WHERE groupId = :i.QueueID ) AND isActive = true ORDER BY firstName]; for (User test : users ){ //Add User.name in Queue_Members__c } } } }
So all I want to do is add the test.name to Queue_Members__c
A small change needs to be done in the piece of code shared earlier
if(getCurrentObject != null && !getCurrentObject .isEmpty()) {
if(getCurrentObject[0].Queue_Members__c == null)
getCurrentObject[0].Queue_Members__c = ‘’;
getCurrentObject[0].Queue_Members__c =+ test.name;
}
Cheers!!!
All Answers
Add this piece of code in your loop and then update the record.
if(getCurrentObject.Queue_Members__c == null)
getCurrentObject.Queue_Members__c = ‘’;
getCurrentObject.Queue_Members__c =+ test.name;
Cheers!!!
if(getCurrentObject.Queue_Members__c == null)
getCurrentObject.Queue_Members__c = ‘’;
getCurrentObject.Queue_Members__c =+ test.name;
I got - Variable does not exist: Queue_Members__c
So I changed it to
for ( User test : users){
if(QueueDistroHelper__c.Queue_Members__c == null)
QueueDistroHelper__c.Queue_Members__c = '';
QueueDistroHelper__c.Queue_Members__c =+ test.name;
But now I get - A value cannot be stored to Queue_Members__c in type QueueDistroHelper__c
I dont know its not storing the value to that field. The field is a text box .
A small change needs to be done in the piece of code shared earlier
if(getCurrentObject != null && !getCurrentObject .isEmpty()) {
if(getCurrentObject[0].Queue_Members__c == null)
getCurrentObject[0].Queue_Members__c = ‘’;
getCurrentObject[0].Queue_Members__c =+ test.name;
}
Cheers!!!
Hey Syed , Thanks a lot for replying . Really appriciate it. This one didnt return any errors. But do you have any idea why the code is not returning anything. I mean the field is still not updating. I also tried to hard code the Queue ID and Record ID. But field is still blank .
Then I tried to limit both queries to 1 So that I get one user in a queue . But thats not working too .
Any help much appriciated .
Thanks
Have you added the update statement for the record ?
Cheers!!!