How to determine if case owner is queue with specific developer name





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}






up vote
2
down vote

favorite












I have a problem with selecting specific custom queue in apex code.



For example I have:



        Case c = (Case) controller.getRecord();
String queueName = c.Owner.Name;

if (queueName != 'ATM_queue') {
//DO SOMETHING
}


Thanks for any advice.










share|improve this question




























    up vote
    2
    down vote

    favorite












    I have a problem with selecting specific custom queue in apex code.



    For example I have:



            Case c = (Case) controller.getRecord();
    String queueName = c.Owner.Name;

    if (queueName != 'ATM_queue') {
    //DO SOMETHING
    }


    Thanks for any advice.










    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a problem with selecting specific custom queue in apex code.



      For example I have:



              Case c = (Case) controller.getRecord();
      String queueName = c.Owner.Name;

      if (queueName != 'ATM_queue') {
      //DO SOMETHING
      }


      Thanks for any advice.










      share|improve this question













      I have a problem with selecting specific custom queue in apex code.



      For example I have:



              Case c = (Case) controller.getRecord();
      String queueName = c.Owner.Name;

      if (queueName != 'ATM_queue') {
      //DO SOMETHING
      }


      Thanks for any advice.







      apex queue






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 14:03









      David

      548




      548






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          8
          down vote



          accepted










          There's no direct relationship between Owner and DeveloperName, because it is a Name object. If you really want to check by developer name, you'll have to query for it:



          if(c.ownerid.getsobjecttype() == Group.SobjectType) {
          Group queue = [select developername from group where id = :c.ownerid];
          if(Queue.DeveloperName == 'atm_queue') {


          As an alternative, you could also create a formula field to return the value, something like owner:queue.developername, and then you can check that value instead.






          share|improve this answer





















          • +1 for formula field as it saves queries, Downside(Only 20 object references on a case and that can be bit tricky)
            – Pranay Jaiswal
            Nov 19 at 15:05


















          up vote
          1
          down vote













          I'm not sure if you specifically need Developer Name or if you can use friendly name instead, but the Owner.Name field is populated when the Owner is a queue - but it uses the display name. So if your queue is called "ATM Queue" then the Owner.Name will be ATM Queue and your if statement would be:



          if(queueName != 'ATM Queue'){
          // Do Something
          }


          Additionally, to make sure that the owner IS a queue before you assign the queueName string, you should do a Owner Check to see if the Owner is a User or a queue, like this:



          String queueName;
          String ownerId;
          Case c = (Case) controller.getRecord();
          ownerId = c.OwnerId;
          if(String.valueOf(ownerId).startsWith('00G')){
          queueName = c.Owner.Name;
          }

          if (queueName != 'ATM Queue') {
          //DO SOMETHING
          }





          share|improve this answer

















          • 4




            if(c.OwnerId.getSobjectType() == Group.SobjectType) is more self-documenting instead of relying on the key prefix.
            – sfdcfox
            Nov 19 at 14:54










          • I actually didn't even know that you could use .getSObjectType() in that context, that's very good information, thanks!
            – Morgan Marchese
            Nov 19 at 14:56











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "459"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239851%2fhow-to-determine-if-case-owner-is-queue-with-specific-developer-name%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          8
          down vote



          accepted










          There's no direct relationship between Owner and DeveloperName, because it is a Name object. If you really want to check by developer name, you'll have to query for it:



          if(c.ownerid.getsobjecttype() == Group.SobjectType) {
          Group queue = [select developername from group where id = :c.ownerid];
          if(Queue.DeveloperName == 'atm_queue') {


          As an alternative, you could also create a formula field to return the value, something like owner:queue.developername, and then you can check that value instead.






          share|improve this answer





















          • +1 for formula field as it saves queries, Downside(Only 20 object references on a case and that can be bit tricky)
            – Pranay Jaiswal
            Nov 19 at 15:05















          up vote
          8
          down vote



          accepted










          There's no direct relationship between Owner and DeveloperName, because it is a Name object. If you really want to check by developer name, you'll have to query for it:



          if(c.ownerid.getsobjecttype() == Group.SobjectType) {
          Group queue = [select developername from group where id = :c.ownerid];
          if(Queue.DeveloperName == 'atm_queue') {


          As an alternative, you could also create a formula field to return the value, something like owner:queue.developername, and then you can check that value instead.






          share|improve this answer





















          • +1 for formula field as it saves queries, Downside(Only 20 object references on a case and that can be bit tricky)
            – Pranay Jaiswal
            Nov 19 at 15:05













          up vote
          8
          down vote



          accepted







          up vote
          8
          down vote



          accepted






          There's no direct relationship between Owner and DeveloperName, because it is a Name object. If you really want to check by developer name, you'll have to query for it:



          if(c.ownerid.getsobjecttype() == Group.SobjectType) {
          Group queue = [select developername from group where id = :c.ownerid];
          if(Queue.DeveloperName == 'atm_queue') {


          As an alternative, you could also create a formula field to return the value, something like owner:queue.developername, and then you can check that value instead.






          share|improve this answer












          There's no direct relationship between Owner and DeveloperName, because it is a Name object. If you really want to check by developer name, you'll have to query for it:



          if(c.ownerid.getsobjecttype() == Group.SobjectType) {
          Group queue = [select developername from group where id = :c.ownerid];
          if(Queue.DeveloperName == 'atm_queue') {


          As an alternative, you could also create a formula field to return the value, something like owner:queue.developername, and then you can check that value instead.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 14:53









          sfdcfox

          242k10185412




          242k10185412












          • +1 for formula field as it saves queries, Downside(Only 20 object references on a case and that can be bit tricky)
            – Pranay Jaiswal
            Nov 19 at 15:05


















          • +1 for formula field as it saves queries, Downside(Only 20 object references on a case and that can be bit tricky)
            – Pranay Jaiswal
            Nov 19 at 15:05
















          +1 for formula field as it saves queries, Downside(Only 20 object references on a case and that can be bit tricky)
          – Pranay Jaiswal
          Nov 19 at 15:05




          +1 for formula field as it saves queries, Downside(Only 20 object references on a case and that can be bit tricky)
          – Pranay Jaiswal
          Nov 19 at 15:05












          up vote
          1
          down vote













          I'm not sure if you specifically need Developer Name or if you can use friendly name instead, but the Owner.Name field is populated when the Owner is a queue - but it uses the display name. So if your queue is called "ATM Queue" then the Owner.Name will be ATM Queue and your if statement would be:



          if(queueName != 'ATM Queue'){
          // Do Something
          }


          Additionally, to make sure that the owner IS a queue before you assign the queueName string, you should do a Owner Check to see if the Owner is a User or a queue, like this:



          String queueName;
          String ownerId;
          Case c = (Case) controller.getRecord();
          ownerId = c.OwnerId;
          if(String.valueOf(ownerId).startsWith('00G')){
          queueName = c.Owner.Name;
          }

          if (queueName != 'ATM Queue') {
          //DO SOMETHING
          }





          share|improve this answer

















          • 4




            if(c.OwnerId.getSobjectType() == Group.SobjectType) is more self-documenting instead of relying on the key prefix.
            – sfdcfox
            Nov 19 at 14:54










          • I actually didn't even know that you could use .getSObjectType() in that context, that's very good information, thanks!
            – Morgan Marchese
            Nov 19 at 14:56















          up vote
          1
          down vote













          I'm not sure if you specifically need Developer Name or if you can use friendly name instead, but the Owner.Name field is populated when the Owner is a queue - but it uses the display name. So if your queue is called "ATM Queue" then the Owner.Name will be ATM Queue and your if statement would be:



          if(queueName != 'ATM Queue'){
          // Do Something
          }


          Additionally, to make sure that the owner IS a queue before you assign the queueName string, you should do a Owner Check to see if the Owner is a User or a queue, like this:



          String queueName;
          String ownerId;
          Case c = (Case) controller.getRecord();
          ownerId = c.OwnerId;
          if(String.valueOf(ownerId).startsWith('00G')){
          queueName = c.Owner.Name;
          }

          if (queueName != 'ATM Queue') {
          //DO SOMETHING
          }





          share|improve this answer

















          • 4




            if(c.OwnerId.getSobjectType() == Group.SobjectType) is more self-documenting instead of relying on the key prefix.
            – sfdcfox
            Nov 19 at 14:54










          • I actually didn't even know that you could use .getSObjectType() in that context, that's very good information, thanks!
            – Morgan Marchese
            Nov 19 at 14:56













          up vote
          1
          down vote










          up vote
          1
          down vote









          I'm not sure if you specifically need Developer Name or if you can use friendly name instead, but the Owner.Name field is populated when the Owner is a queue - but it uses the display name. So if your queue is called "ATM Queue" then the Owner.Name will be ATM Queue and your if statement would be:



          if(queueName != 'ATM Queue'){
          // Do Something
          }


          Additionally, to make sure that the owner IS a queue before you assign the queueName string, you should do a Owner Check to see if the Owner is a User or a queue, like this:



          String queueName;
          String ownerId;
          Case c = (Case) controller.getRecord();
          ownerId = c.OwnerId;
          if(String.valueOf(ownerId).startsWith('00G')){
          queueName = c.Owner.Name;
          }

          if (queueName != 'ATM Queue') {
          //DO SOMETHING
          }





          share|improve this answer












          I'm not sure if you specifically need Developer Name or if you can use friendly name instead, but the Owner.Name field is populated when the Owner is a queue - but it uses the display name. So if your queue is called "ATM Queue" then the Owner.Name will be ATM Queue and your if statement would be:



          if(queueName != 'ATM Queue'){
          // Do Something
          }


          Additionally, to make sure that the owner IS a queue before you assign the queueName string, you should do a Owner Check to see if the Owner is a User or a queue, like this:



          String queueName;
          String ownerId;
          Case c = (Case) controller.getRecord();
          ownerId = c.OwnerId;
          if(String.valueOf(ownerId).startsWith('00G')){
          queueName = c.Owner.Name;
          }

          if (queueName != 'ATM Queue') {
          //DO SOMETHING
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 14:52









          Morgan Marchese

          1,428426




          1,428426








          • 4




            if(c.OwnerId.getSobjectType() == Group.SobjectType) is more self-documenting instead of relying on the key prefix.
            – sfdcfox
            Nov 19 at 14:54










          • I actually didn't even know that you could use .getSObjectType() in that context, that's very good information, thanks!
            – Morgan Marchese
            Nov 19 at 14:56














          • 4




            if(c.OwnerId.getSobjectType() == Group.SobjectType) is more self-documenting instead of relying on the key prefix.
            – sfdcfox
            Nov 19 at 14:54










          • I actually didn't even know that you could use .getSObjectType() in that context, that's very good information, thanks!
            – Morgan Marchese
            Nov 19 at 14:56








          4




          4




          if(c.OwnerId.getSobjectType() == Group.SobjectType) is more self-documenting instead of relying on the key prefix.
          – sfdcfox
          Nov 19 at 14:54




          if(c.OwnerId.getSobjectType() == Group.SobjectType) is more self-documenting instead of relying on the key prefix.
          – sfdcfox
          Nov 19 at 14:54












          I actually didn't even know that you could use .getSObjectType() in that context, that's very good information, thanks!
          – Morgan Marchese
          Nov 19 at 14:56




          I actually didn't even know that you could use .getSObjectType() in that context, that's very good information, thanks!
          – Morgan Marchese
          Nov 19 at 14:56


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239851%2fhow-to-determine-if-case-owner-is-queue-with-specific-developer-name%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Aardman Animations

          Are they similar matrix

          “minimization” problem in Euclidean space related to orthonormal basis