You need to sign in to do that
Don't have an account?
Anil Rao 17
Getting Queue ID & assigning to Lead Owner ID via Apex Code
I have 2 Queues - AsiaQ & EuropeQ. I have a Apex API that converts a Cart Custom Object record into a Lead record. The Lead record has a field callled Region which takes Asia or Europe. Based on the region selected, I want the Lead to be assigned to either AsiaQ or EuropeQ.
Below code works: I have hard coded the Q IDs.
ID QID;
Lead indLead = new Lead();
if (indLead.region__c == 'Asia')
QID = '00G46000000nsXy';
else
QID = '00G46000000nsY3';
indLead.ownerid = QID;
I dont want to hard code. I want to get the Q ID based on the region in the Lead record.
Below is the code. This is NOT working. Pl. help & suggest what mistake I am doing -
ID QID;
Lead indLead = new Lead();
QID = [select queue.id from QueuesObject where Queue.Name = :indLead.region__c limit 1];
indLead.ownerid = QID;
I have confirmed that :indLead.region__c has the correct value of Asia or Europe.
Below code works: I have hard coded the Q IDs.
ID QID;
Lead indLead = new Lead();
if (indLead.region__c == 'Asia')
QID = '00G46000000nsXy';
else
QID = '00G46000000nsY3';
indLead.ownerid = QID;
I dont want to hard code. I want to get the Q ID based on the region in the Lead record.
Below is the code. This is NOT working. Pl. help & suggest what mistake I am doing -
ID QID;
Lead indLead = new Lead();
QID = [select queue.id from QueuesObject where Queue.Name = :indLead.region__c limit 1];
indLead.ownerid = QID;
I have confirmed that :indLead.region__c has the correct value of Asia or Europe.
You can try below query to get queue Id
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya
All Answers
Replace your query with this it should work.
Group problemQ = [select Id from Group where Type = 'Queue' AND NAME = :indLead.region__c Limit 1];
You can try below query to get queue Id
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya