+ Start a Discussion
James Kacerguis 5James Kacerguis 5 

Best way to get single Queue ID and assign as owner?

I currently have apex class in lightning component that is getting a specific Queue Id to assign as owner of the record the component is launched from.

This is the current  way I'm getting the id, but I'm guessing there is a better way to do this, any ideas?
Group marketingQueue = [SELECT id,Name FROM Group WHERE Type = 'Queue' and DeveloperNAME = 'MarketingProspectLeads'];
         	ID marketingQueueId = marketingQueue.id;
            //l.OwnerId = UserInfo.getUserId();
            system.debug('marketingQueue');
            l.OwnerId = marketingQueueId;

I just need to make sure this can't break so I'm assuming I should add some error checking or be doing this a different way.  Thanks in advance.  
Best Answer chosen by James Kacerguis 5
Sonali_takkeSonali_takke
Hi James,
If you don't require Name then you can modify your query as follows to reduce number of lines in code and add NULL check before assignment to avoid code break.
 
ID marketingQueueId = [SELECT id FROM Group WHERE Type = 'Queue' and DeveloperNAME = 'MarketingProspectLeads'].Id;

if(marketingQueueId != NULL) {
    l.OwnerId = marketingQueueId;
}

Kindly mark as resolved if you find this anser helpful. 

All Answers

anshul saini 7anshul saini 7
Hi James,
You can add 'Limit 1' in your query for for single id. as
Group marketingQueue = [SELECT id,Name FROM Group WHERE Type = 'Queue' and DeveloperNAME = 'MarketingProspectLeads' limit 1];
Sonali_takkeSonali_takke
Hi James,
If you don't require Name then you can modify your query as follows to reduce number of lines in code and add NULL check before assignment to avoid code break.
 
ID marketingQueueId = [SELECT id FROM Group WHERE Type = 'Queue' and DeveloperNAME = 'MarketingProspectLeads'].Id;

if(marketingQueueId != NULL) {
    l.OwnerId = marketingQueueId;
}

Kindly mark as resolved if you find this anser helpful. 
This was selected as the best answer
James Kacerguis 5James Kacerguis 5
Great, 
As this component is launched without any user input, I didn't know if there was something I should pass back to the controller to notify the user in case something didn't work.  Thanks for all the feedback. 
Akash Deb NathAkash Deb Nath
Hey, its really amazing blog I am very much interested. Thanks for the great article, Regards UP Ration Crad (https://www.godigitalzone.in/up-ration-card-list/)
helin jessihelin jessi
For new registration: Please go to the Apply Online section of this website and read the instructions carefully before proceeding.
http://student-login.xyz/
Alessia BrookAlessia Brook
Download PowerDirector Pro Apk (https://apkmodpro.co/powerdirector-pro-apk/) No Watermark. Get all the premium features free of cost. More Latest mod Apk (https://apkmodpro.co/) here
devin cafedevin cafe
 The Government of Ghana electronic payslip offers changed preferences of the old printed copy payslips; both with respect to the staff, and the administration. 

https://gogpayslip.site/
Pagal WorldPagal World
This is the best article i ever read on Pagalworld com pagalworld (https://pagalworld.to/) site not only this site i also prefer to visit:  Katmoviehd (https://katmoviehd.world/) movie downloading site where you will get another site is twitter video downloader (https://twittervideodownloader.me/) free tweet save online or download youtube thumbnail (https://youtubethumbnaildownloader.net/) or  convert 2mp3 (https://convert2mp3.me/) best online tubemate app (https://tubemate.asia/) enjoy all the services,
Alessia BrookAlessia Brook
Download Illisiumart Mod Apk (https://apkmodpro.co/illisiumart-mod-apk/). Get all the premium features free of cost. More Latest mod Apk (https://apkmodpro.co/) here
Roger KartRoger Kart
I faced the same problem and thanks for the answer. You can check my website on how I faced this. Amazon feedback Management (https://salesla.com) System
Pagla WorldPagla World
Yes is gree with this but pagalworld (https://pagalworld.nl/) is far batter for song website.
Alessia BrookAlessia Brook
Download Gif Guru Mod Apk (https://apkmodpro.co/gif-guru-mod-apk/)
Alessia BrookAlessia Brook
Download the latest Brochill Mod Apk (https://apkmodpro.co/brochill-mod-apk/)