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
Rohith Kumar 98Rohith Kumar 98 

How to assign records to queue in Apex?

There is a requirement like

If the payment amount >2000 USD, save the records with “Pending Approval” status and assign this to a queue “Payment Order Pending Approval”

How to do that in Apex?
 
if(paymentAmount > 2000 && status == 'Pending Approval'){
//What to do?
}

 
Best Answer chosen by Rohith Kumar 98
Rohith Kumar 98Rohith Kumar 98
Bro the requirement here is to assign the pending approval to a Queue, I found the solution.
 
ID queueId = [SELECT Queue.Id FROM queuesobject WHERE queue.name='Payment Order Pending Approval'].Queue.Id;
paymentOrder.OwnerId = queueId;

 

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Rohith Kumar 98,
Here i am assuming that PaymentOrder__c is a custome object which has fields paymentAmount,status.
 
-> Create a List which contains only pending payment object which has paymentAmount >2000 and status == 'Pending Approval'.
List<PaymentOrder__c> PendingPaymentOrdList = new List<PaymentOrder__c>(); 
        
        if(PaymentOrder__c.paymentAmount > 2000 && PaymentOrder__c.status == 'Pending Approval'){
            PendingPaymentOrdList.add(PaymentOrder__c);
        }

If you find this helpful please mark it as a best answer.
Thanks And Regards,
Suraj Tripathi.
Rohith Kumar 98Rohith Kumar 98
Bro the requirement here is to assign the pending approval to a Queue, I found the solution.
 
ID queueId = [SELECT Queue.Id FROM queuesobject WHERE queue.name='Payment Order Pending Approval'].Queue.Id;
paymentOrder.OwnerId = queueId;

 
This was selected as the best answer