SOQL AggregateResult Query throws error: System.ListException: Row with null Id at index: 0

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





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







up vote
3
down vote

favorite












Background



I have this Apex SOQL query:



 myMap = new Map<Id, AggregateResult>([SELECT OpportunityLineItemId, 
MIN(ScheduleDate) Starts
FROM OpportunityLineItemSchedule
WHERE OpportunityLineItemId IN :opportunityLineItemMap.keySet()
AND ScheduleDate != NULL
GROUP BY OpportunityLineItemId]);


Which throws this error:




System.ListException: Row with null Id at index: 0




Questions



  1. Why?

  2. What am I doing wrong?

  3. How can I fix it?









share|improve this question



























    up vote
    3
    down vote

    favorite












    Background



    I have this Apex SOQL query:



     myMap = new Map<Id, AggregateResult>([SELECT OpportunityLineItemId, 
    MIN(ScheduleDate) Starts
    FROM OpportunityLineItemSchedule
    WHERE OpportunityLineItemId IN :opportunityLineItemMap.keySet()
    AND ScheduleDate != NULL
    GROUP BY OpportunityLineItemId]);


    Which throws this error:




    System.ListException: Row with null Id at index: 0




    Questions



    1. Why?

    2. What am I doing wrong?

    3. How can I fix it?









    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      Background



      I have this Apex SOQL query:



       myMap = new Map<Id, AggregateResult>([SELECT OpportunityLineItemId, 
      MIN(ScheduleDate) Starts
      FROM OpportunityLineItemSchedule
      WHERE OpportunityLineItemId IN :opportunityLineItemMap.keySet()
      AND ScheduleDate != NULL
      GROUP BY OpportunityLineItemId]);


      Which throws this error:




      System.ListException: Row with null Id at index: 0




      Questions



      1. Why?

      2. What am I doing wrong?

      3. How can I fix it?









      share|improve this question













      Background



      I have this Apex SOQL query:



       myMap = new Map<Id, AggregateResult>([SELECT OpportunityLineItemId, 
      MIN(ScheduleDate) Starts
      FROM OpportunityLineItemSchedule
      WHERE OpportunityLineItemId IN :opportunityLineItemMap.keySet()
      AND ScheduleDate != NULL
      GROUP BY OpportunityLineItemId]);


      Which throws this error:




      System.ListException: Row with null Id at index: 0




      Questions



      1. Why?

      2. What am I doing wrong?

      3. How can I fix it?






      apex soql map aggregate aggregateresult






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 32 mins ago









      Robs

      1,169323




      1,169323




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          You need to alias some field to Id in order for the Map<Id, SObject>(List<SObject>) constructor to work.



          SELECT
          OpportunityLineItemId Id,
          MIN(ScheduleDate) Starts
          FROM OpportunityLineItemSchedule
          WHERE ...
          GROUP BY OpportunityLineItemId


          As your query is currently written, a given AggregateResult will only allow you to get three "fields":



          • expr0

          • OpportujnityLineItemId

          • Starts





          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f233285%2fsoql-aggregateresult-query-throws-error-system-listexception-row-with-null-id%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote













            You need to alias some field to Id in order for the Map<Id, SObject>(List<SObject>) constructor to work.



            SELECT
            OpportunityLineItemId Id,
            MIN(ScheduleDate) Starts
            FROM OpportunityLineItemSchedule
            WHERE ...
            GROUP BY OpportunityLineItemId


            As your query is currently written, a given AggregateResult will only allow you to get three "fields":



            • expr0

            • OpportujnityLineItemId

            • Starts





            share|improve this answer


























              up vote
              3
              down vote













              You need to alias some field to Id in order for the Map<Id, SObject>(List<SObject>) constructor to work.



              SELECT
              OpportunityLineItemId Id,
              MIN(ScheduleDate) Starts
              FROM OpportunityLineItemSchedule
              WHERE ...
              GROUP BY OpportunityLineItemId


              As your query is currently written, a given AggregateResult will only allow you to get three "fields":



              • expr0

              • OpportujnityLineItemId

              • Starts





              share|improve this answer
























                up vote
                3
                down vote










                up vote
                3
                down vote









                You need to alias some field to Id in order for the Map<Id, SObject>(List<SObject>) constructor to work.



                SELECT
                OpportunityLineItemId Id,
                MIN(ScheduleDate) Starts
                FROM OpportunityLineItemSchedule
                WHERE ...
                GROUP BY OpportunityLineItemId


                As your query is currently written, a given AggregateResult will only allow you to get three "fields":



                • expr0

                • OpportujnityLineItemId

                • Starts





                share|improve this answer














                You need to alias some field to Id in order for the Map<Id, SObject>(List<SObject>) constructor to work.



                SELECT
                OpportunityLineItemId Id,
                MIN(ScheduleDate) Starts
                FROM OpportunityLineItemSchedule
                WHERE ...
                GROUP BY OpportunityLineItemId


                As your query is currently written, a given AggregateResult will only allow you to get three "fields":



                • expr0

                • OpportujnityLineItemId

                • Starts






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 11 mins ago

























                answered 22 mins ago









                Adrian Larson♦

                100k19107225




                100k19107225



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f233285%2fsoql-aggregateresult-query-throws-error-system-listexception-row-with-null-id%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    What does second last employer means? [closed]

                    One-line joke