+ 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/)
Alessia BrookAlessia Brook
Download Screensync Pro Apk (https://apkmodpro.co/screensync-pro-mod/)
Alessia BrookAlessia Brook
steve Jrsteve Jr
swapcoder.com is an online website that allows you to generate Instagram fonts (https://www.swapcoder.com) for bio that you can copy and paste into your Instagram bio. 
steve Jrsteve Jr

check out more than 100+ Instagram fonts (https://www.fontgenerator.co/)for your Instagram bio, names and comment to make your Instagram profile looks cool
Alessia BrookAlessia Brook
Download Arrow Go Mod Apk (https://apkmodpro.co/arrow-go-mod-apk/) to become a fighting legend. Also, download Magicians Apprentice Mod Apk (https://apkmodpro.co/magicians-apprentice-mod-apk/) to do magical war. Similarly, download Stick Hero Fighter Mod Apk (https://apkmodpro.co/stick-hero-fighter-mod-apk/) to become a dragon warrior.
Djpunjab DownloadDjpunjab Download
I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.

Pagalworld Download (https://pagalworldownload.online/)
Mr Jatt  (https://mrjatt.buzz)
Mp3 Song (https://mp3songs.live)
Djpunjab Download (https://dj-punjab.live)
webmusic webwebmusic web
Very nice information know more about webmusic (http://webmusicweb.in/)
Tricksvile ConceptTricksvile Concept
So happy that at last I stumbled upon this post, commenting from:
Tricksvile.com (https://www.tricksvile.com/vinkle-mod-apk/) For Mackiestdon.com
On tricksvile.com you can download your mod apk like: On mackiestdon.com, you can learn how to:
Peter Parker 44Peter Parker 44
Very amazing forum site. I am glad I visited this site. You can download Happy Birthday Wishes in Hindi (https://prowhatsappstatus.com/happy-birthday-wishes-in-hindi/) from this site. Also, you will get Attitude Status in Hindi (https://prowhatsappstatus.com/attitude-status-in-hindi/) for WhatsApp too.
Peter Parker 44Peter Parker 44
Hey there, I visited your blog and loved it. You have many quality content on your blog. I also produce such quality content on My blog (https://apkmodpro.co/). Visit here Mod Apk (https://apkmodpro.co/).
Tricksvile ConceptTricksvile Concept
Hey there, I visited your blog and loved it. You have many quality content on your blog. I also produce such quality content on My Mod APK blog (https://www.tricksvile.com/) Visit here Illisiumart  Mod Apk (https://www.tricksvile.com/illisiumart-mod-apk/)
Angela JollyAngela Jolly
Visit Apkmodpro (https://apkmodpro.co/) for modded apps and games
Tricksvile ConceptTricksvile Concept
Download Abbasi Tv (https://www.tricksvile.com/abbasi-tv-apk-download/) from tricksvile.com
bdown bdownbdown bdown
Very nice information know more about Hind mp3 download (bdown.live)
Poonam DeswalPoonam Deswal
I’ve lived in both cities. Really depends on what you want. New York is a city that you immediately fall for. London is an affection that grows steadily on you over time.

New York is more fast-paced and far denser. It’s more obvious exactly what is open late until 4 a.m. and what isn’t.

London vs New York (https://reddit.myringtone.info/london-vs-new-york/)
Boss MobiBoss Mobi
Thank you very much for providing the information to me.
BossMobi (https://bossmobi.club/" target="_blank) Free Bollywood Mp3 Songs, Hindi Songs, Pop DJ Remix.