Getting AggregateResult variables from Execute Anonymous Window Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Community Moderator Election ResultsRun a standard set controller extension from execute anonymousCan I return entire record set when using the Execute Anonymous Window in Dev Console?Execute anonymous - switch projectsSOQL: Execute Anonymous and Query Editor returning different resultsAutomatic re-naming of bind variable in Execute Anonymous debug log - why did/does this happen?How SOQL For Loop instead of SOQL may solve System.LimitException: Too many query rows: 50001?Execute a schedulable class from execute anonymous windowAggregateResult looping over empty query?'Expecting colon' error in SOQL query when not using a variableRunning Batch in Execute Anonymous but throwing error: method does not exist or incorrect signature void format string from the type anon

Processing ADC conversion result: DMA vs Processor Registers

Has a Nobel Peace laureate ever been accused of war crimes?

When speaking, how do you change your mind mid-sentence?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

What's called a person who works as someone who puts products on shelves in stores?

Why do people think Winterfell crypts is the safest place for women, children & old people?

Is there an efficient way for synchronising audio events real-time with LEDs using an MCU?

My admission is revoked after accepting the admission offer

Co-worker works way more than he should

What was Apollo 13's "Little Jolt" after MECO?

TV series episode where humans nuke aliens before decrypting their message that states they come in peace

Why is arima in R one time step off?

How was Lagrange appointed professor of mathematics so early?

Writing a T-SQL stored procedure to receive 4 numbers and insert them into a table

Where to find documentation for `whois` command options?

Determinant of a matrix with 2 equal rows

What is a good proxy for government quality?

What is a 'Key' in computer science?

When I export an AI 300x60 art board it saves with bigger dimensions

Retract an already submitted Recommendation Letter (written for an undergrad student)

Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?

In search of the origins of term censor, I hit a dead end stuck with the greek term, to censor, λογοκρίνω

Bright yellow or light yellow?

Why aren't road bicycle wheels tiny?



Getting AggregateResult variables from Execute Anonymous Window



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Community Moderator Election ResultsRun a standard set controller extension from execute anonymousCan I return entire record set when using the Execute Anonymous Window in Dev Console?Execute anonymous - switch projectsSOQL: Execute Anonymous and Query Editor returning different resultsAutomatic re-naming of bind variable in Execute Anonymous debug log - why did/does this happen?How SOQL For Loop instead of SOQL may solve System.LimitException: Too many query rows: 50001?Execute a schedulable class from execute anonymous windowAggregateResult looping over empty query?'Expecting colon' error in SOQL query when not using a variableRunning Batch in Execute Anonymous but throwing error: method does not exist or incorrect signature void format string from the type anon



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I am trying to execute a block of code using the Execute Anonymous Window that is meant to delete some duplicated data, but I am getting this weird error about a variable not existing even though my debugging says otherwise.



Here is what I have:



List<AggregateResult> ars = [SELECT YTPQuiz__c quiz FROM YTPQuestion__c GROUP BY YTPQuiz__c HAVING Count(Id) > 1];
System.debug(ars);
for (AggregateResult ar : ars)
System.debug(ar.quiz);



In the for-loop you will see I simply print the quiz variable I assigned during the SOQL statement, but I get an error saying that this variable does not exist.



If I replace this debug line with System.debug(ar) the log print out a bunch of object like:



DEBUG|AggregateResult:quiz=a1XY0000000012
DEBUG|AggregateResult:quiz=a1XY0000000013
DEBUG|AggregateResult:quiz=a1XY0000000014
DEBUG|AggregateResult:quiz=a1XY0000000015


Yet, I can't access the quiz variable.



If I don't alias YTPQuiz__c as quiz then it will print out



DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000012
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000013
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000014
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000015


Yet, I get the error that ar.YTPQuiz__c variable doesn't exist. I even tried ar.expr0 and it said that variable doesn't exist.



I've done this exact same method of accessing AggregateResults in APEX classes and it works perfectly fine, but not this Anonymous Execution Window... What could possibly be wrong?










share|improve this question






















  • As far as I know you will need to use ar.get('quiz') to be able to get the data here. If you don't have aliases, then you use ar.get('expr0') and so on depending on the order of the field.

    – Jayant Das
    6 hours ago

















3















I am trying to execute a block of code using the Execute Anonymous Window that is meant to delete some duplicated data, but I am getting this weird error about a variable not existing even though my debugging says otherwise.



Here is what I have:



List<AggregateResult> ars = [SELECT YTPQuiz__c quiz FROM YTPQuestion__c GROUP BY YTPQuiz__c HAVING Count(Id) > 1];
System.debug(ars);
for (AggregateResult ar : ars)
System.debug(ar.quiz);



In the for-loop you will see I simply print the quiz variable I assigned during the SOQL statement, but I get an error saying that this variable does not exist.



If I replace this debug line with System.debug(ar) the log print out a bunch of object like:



DEBUG|AggregateResult:quiz=a1XY0000000012
DEBUG|AggregateResult:quiz=a1XY0000000013
DEBUG|AggregateResult:quiz=a1XY0000000014
DEBUG|AggregateResult:quiz=a1XY0000000015


Yet, I can't access the quiz variable.



If I don't alias YTPQuiz__c as quiz then it will print out



DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000012
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000013
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000014
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000015


Yet, I get the error that ar.YTPQuiz__c variable doesn't exist. I even tried ar.expr0 and it said that variable doesn't exist.



I've done this exact same method of accessing AggregateResults in APEX classes and it works perfectly fine, but not this Anonymous Execution Window... What could possibly be wrong?










share|improve this question






















  • As far as I know you will need to use ar.get('quiz') to be able to get the data here. If you don't have aliases, then you use ar.get('expr0') and so on depending on the order of the field.

    – Jayant Das
    6 hours ago













3












3








3








I am trying to execute a block of code using the Execute Anonymous Window that is meant to delete some duplicated data, but I am getting this weird error about a variable not existing even though my debugging says otherwise.



Here is what I have:



List<AggregateResult> ars = [SELECT YTPQuiz__c quiz FROM YTPQuestion__c GROUP BY YTPQuiz__c HAVING Count(Id) > 1];
System.debug(ars);
for (AggregateResult ar : ars)
System.debug(ar.quiz);



In the for-loop you will see I simply print the quiz variable I assigned during the SOQL statement, but I get an error saying that this variable does not exist.



If I replace this debug line with System.debug(ar) the log print out a bunch of object like:



DEBUG|AggregateResult:quiz=a1XY0000000012
DEBUG|AggregateResult:quiz=a1XY0000000013
DEBUG|AggregateResult:quiz=a1XY0000000014
DEBUG|AggregateResult:quiz=a1XY0000000015


Yet, I can't access the quiz variable.



If I don't alias YTPQuiz__c as quiz then it will print out



DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000012
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000013
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000014
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000015


Yet, I get the error that ar.YTPQuiz__c variable doesn't exist. I even tried ar.expr0 and it said that variable doesn't exist.



I've done this exact same method of accessing AggregateResults in APEX classes and it works perfectly fine, but not this Anonymous Execution Window... What could possibly be wrong?










share|improve this question














I am trying to execute a block of code using the Execute Anonymous Window that is meant to delete some duplicated data, but I am getting this weird error about a variable not existing even though my debugging says otherwise.



Here is what I have:



List<AggregateResult> ars = [SELECT YTPQuiz__c quiz FROM YTPQuestion__c GROUP BY YTPQuiz__c HAVING Count(Id) > 1];
System.debug(ars);
for (AggregateResult ar : ars)
System.debug(ar.quiz);



In the for-loop you will see I simply print the quiz variable I assigned during the SOQL statement, but I get an error saying that this variable does not exist.



If I replace this debug line with System.debug(ar) the log print out a bunch of object like:



DEBUG|AggregateResult:quiz=a1XY0000000012
DEBUG|AggregateResult:quiz=a1XY0000000013
DEBUG|AggregateResult:quiz=a1XY0000000014
DEBUG|AggregateResult:quiz=a1XY0000000015


Yet, I can't access the quiz variable.



If I don't alias YTPQuiz__c as quiz then it will print out



DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000012
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000013
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000014
DEBUG|AggregateResult:YTPQuiz__c=a1XY0000000015


Yet, I get the error that ar.YTPQuiz__c variable doesn't exist. I even tried ar.expr0 and it said that variable doesn't exist.



I've done this exact same method of accessing AggregateResults in APEX classes and it works perfectly fine, but not this Anonymous Execution Window... What could possibly be wrong?







soql execute-anonymous aggregateresult






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 6 hours ago









BlondeSwanBlondeSwan

34110




34110












  • As far as I know you will need to use ar.get('quiz') to be able to get the data here. If you don't have aliases, then you use ar.get('expr0') and so on depending on the order of the field.

    – Jayant Das
    6 hours ago

















  • As far as I know you will need to use ar.get('quiz') to be able to get the data here. If you don't have aliases, then you use ar.get('expr0') and so on depending on the order of the field.

    – Jayant Das
    6 hours ago
















As far as I know you will need to use ar.get('quiz') to be able to get the data here. If you don't have aliases, then you use ar.get('expr0') and so on depending on the order of the field.

– Jayant Das
6 hours ago





As far as I know you will need to use ar.get('quiz') to be able to get the data here. If you don't have aliases, then you use ar.get('expr0') and so on depending on the order of the field.

– Jayant Das
6 hours ago










2 Answers
2






active

oldest

votes


















2














If you alias the field, you then call .get('alias'). In your case, you would do something like:



for (AggregateResult aggregate : [
SELECT YTPQuiz__c quiz FROM YTPQuestion__c
GROUP BY YTPQuiz__c HAVING Count(Id) > 1
])
Id quizId = (Id)aggregate.get('quiz');






share|improve this answer






























    2














    You will need to utilize ar.get(alias-name) here based on the Working with SOQL Aggregate Functions documentation.



    So in your case it will be:



    ar.get('quiz');


    If you didn't have any aliasing, then you would have to use expri depending on the appearance of the field in the query.






    share|improve this answer























      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',
      autoActivateHeartbeat: false,
      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%2f258860%2fgetting-aggregateresult-variables-from-execute-anonymous-window%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









      2














      If you alias the field, you then call .get('alias'). In your case, you would do something like:



      for (AggregateResult aggregate : [
      SELECT YTPQuiz__c quiz FROM YTPQuestion__c
      GROUP BY YTPQuiz__c HAVING Count(Id) > 1
      ])
      Id quizId = (Id)aggregate.get('quiz');






      share|improve this answer



























        2














        If you alias the field, you then call .get('alias'). In your case, you would do something like:



        for (AggregateResult aggregate : [
        SELECT YTPQuiz__c quiz FROM YTPQuestion__c
        GROUP BY YTPQuiz__c HAVING Count(Id) > 1
        ])
        Id quizId = (Id)aggregate.get('quiz');






        share|improve this answer

























          2












          2








          2







          If you alias the field, you then call .get('alias'). In your case, you would do something like:



          for (AggregateResult aggregate : [
          SELECT YTPQuiz__c quiz FROM YTPQuestion__c
          GROUP BY YTPQuiz__c HAVING Count(Id) > 1
          ])
          Id quizId = (Id)aggregate.get('quiz');






          share|improve this answer













          If you alias the field, you then call .get('alias'). In your case, you would do something like:



          for (AggregateResult aggregate : [
          SELECT YTPQuiz__c quiz FROM YTPQuestion__c
          GROUP BY YTPQuiz__c HAVING Count(Id) > 1
          ])
          Id quizId = (Id)aggregate.get('quiz');







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 6 hours ago









          Adrian LarsonAdrian Larson

          111k19121259




          111k19121259























              2














              You will need to utilize ar.get(alias-name) here based on the Working with SOQL Aggregate Functions documentation.



              So in your case it will be:



              ar.get('quiz');


              If you didn't have any aliasing, then you would have to use expri depending on the appearance of the field in the query.






              share|improve this answer



























                2














                You will need to utilize ar.get(alias-name) here based on the Working with SOQL Aggregate Functions documentation.



                So in your case it will be:



                ar.get('quiz');


                If you didn't have any aliasing, then you would have to use expri depending on the appearance of the field in the query.






                share|improve this answer

























                  2












                  2








                  2







                  You will need to utilize ar.get(alias-name) here based on the Working with SOQL Aggregate Functions documentation.



                  So in your case it will be:



                  ar.get('quiz');


                  If you didn't have any aliasing, then you would have to use expri depending on the appearance of the field in the query.






                  share|improve this answer













                  You will need to utilize ar.get(alias-name) here based on the Working with SOQL Aggregate Functions documentation.



                  So in your case it will be:



                  ar.get('quiz');


                  If you didn't have any aliasing, then you would have to use expri depending on the appearance of the field in the query.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 6 hours ago









                  Jayant DasJayant Das

                  19k21331




                  19k21331



























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f258860%2fgetting-aggregateresult-variables-from-execute-anonymous-window%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

                      How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

                      Българска екзархия Съдържание История | Български екзарси | Вижте също | Външни препратки | Литература | Бележки | НавигацияУстав за управлението на българската екзархия. Цариград, 1870Слово на Ловешкия митрополит Иларион при откриването на Българския народен събор в Цариград на 23. II. 1870 г.Българската правда и гръцката кривда. От С. М. (= Софийски Мелетий). Цариград, 1872Предстоятели на Българската екзархияПодмененият ВеликденИнформационна агенция „Фокус“Димитър Ризов. Българите в техните исторически, етнографически и политически граници (Атлас съдържащ 40 карти). Berlin, Königliche Hoflithographie, Hof-Buch- und -Steindruckerei Wilhelm Greve, 1917Report of the International Commission to Inquire into the Causes and Conduct of the Balkan Wars

                      Category:Tremithousa Media in category "Tremithousa"Navigation menuUpload media34° 49′ 02.7″ N, 32° 26′ 37.32″ EOpenStreetMapGoogle EarthProximityramaReasonatorScholiaStatisticsWikiShootMe