Illegal assignment from Id to ListHow can I efficiently generate a Set<Id> from a List<SObject> structure?Error: Compile Error: Illegal assignment from String to SOBJECT:AccountHow to assign string to date type in apex codeVisualforce controller, save values from a listHow to get multiple values of ContentDocument.LatestPublishedVersionIdContent cannot be displayed: Illegal assignment from List<QuoteLineItem> to List<QuoteLineItem>getting text within a string (similar to merge fields)Dynamic Field Query error from non sys admin users: unexpected token: 'from': ()Salesforce List of Sobject with group byIllegal Integer but only after thresholdEmailMessage.ToAddress - Illegal assignment: from list to string

What's the difference between "ricochet" and "bounce"?

How to avoid making self and former employee look bad when reporting on fixing former employee's work?

Expl3 and recent xparse on overleaf: No expl3 loader detected

What's the 2-minute timer on mobile Deutsche Bahn tickets?

Why doesn't a particle exert force on itself?

Using mean length and mean weight to calculate mean BMI?

My perfect evil overlord plan... or is it?

Fuzzy vector logos from InDesign to Acrobat PDF

Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?

Are wands in any sort of book going to be too much like Harry Potter?

Do these creatures from the Tomb of Annihilation campaign speak Common?

Why are thrust reversers not used down to taxi speeds?

A♭ major 9th chord in Bach is unexpectedly dissonant/jazzy

Identity of a supposed anonymous referee revealed through "Description" of the report

Add elements inside Array conditionally in JavaScript

What is the Ancient One's mistake?

How do I give a darkroom course without negatives from the attendees?

What should I use to get rid of some kind of weed in my onions

Why is there a cap on 401k contributions?

Learning how to read schematics, questions about fractional voltage in schematic

"I can't place her": How do Russian speakers express this idea colloquially?

Did Ham the Chimp follow commands, or did he just randomly push levers?

Exactly which act of bravery are Luke and Han awarded a medal for?

Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1



Illegal assignment from Id to List


How can I efficiently generate a Set<Id> from a List<SObject> structure?Error: Compile Error: Illegal assignment from String to SOBJECT:AccountHow to assign string to date type in apex codeVisualforce controller, save values from a listHow to get multiple values of ContentDocument.LatestPublishedVersionIdContent cannot be displayed: Illegal assignment from List<QuoteLineItem> to List<QuoteLineItem>getting text within a string (similar to merge fields)Dynamic Field Query error from non sys admin users: unexpected token: 'from': ()Salesforce List of Sobject with group byIllegal Integer but only after thresholdEmailMessage.ToAddress - Illegal assignment: from list to string






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








1















I have a real quick question.



Usually when I want to get a list of IDs as a List i'll do something like:



List<String> voterIds = [select ID, from Vote__c where suggestion__c =: recordId].ID;


But for some reason when I try to do it this time I am getting an "Illegal assignment from Id to List"



Can anyone provide some insight into this? I'll be happy to supply code if necessary, thanks in advance!










share|improve this question

















  • 1





    i think you are looking for this:- salesforce.stackexchange.com/questions/8910/…

    – sanket kumar
    5 hours ago

















1















I have a real quick question.



Usually when I want to get a list of IDs as a List i'll do something like:



List<String> voterIds = [select ID, from Vote__c where suggestion__c =: recordId].ID;


But for some reason when I try to do it this time I am getting an "Illegal assignment from Id to List"



Can anyone provide some insight into this? I'll be happy to supply code if necessary, thanks in advance!










share|improve this question

















  • 1





    i think you are looking for this:- salesforce.stackexchange.com/questions/8910/…

    – sanket kumar
    5 hours ago













1












1








1








I have a real quick question.



Usually when I want to get a list of IDs as a List i'll do something like:



List<String> voterIds = [select ID, from Vote__c where suggestion__c =: recordId].ID;


But for some reason when I try to do it this time I am getting an "Illegal assignment from Id to List"



Can anyone provide some insight into this? I'll be happy to supply code if necessary, thanks in advance!










share|improve this question














I have a real quick question.



Usually when I want to get a list of IDs as a List i'll do something like:



List<String> voterIds = [select ID, from Vote__c where suggestion__c =: recordId].ID;


But for some reason when I try to do it this time I am getting an "Illegal assignment from Id to List"



Can anyone provide some insight into this? I'll be happy to supply code if necessary, thanks in advance!







apex soql list salesforce-id string






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 5 hours ago









Daniel RetaleatoDaniel Retaleato

212




212







  • 1





    i think you are looking for this:- salesforce.stackexchange.com/questions/8910/…

    – sanket kumar
    5 hours ago












  • 1





    i think you are looking for this:- salesforce.stackexchange.com/questions/8910/…

    – sanket kumar
    5 hours ago







1




1





i think you are looking for this:- salesforce.stackexchange.com/questions/8910/…

– sanket kumar
5 hours ago





i think you are looking for this:- salesforce.stackexchange.com/questions/8910/…

– sanket kumar
5 hours ago










2 Answers
2






active

oldest

votes


















3














The current syntax you have is incorrect. You dereference a field when you know that your query will return only one record. This is what seems to be the case here where you are dereferencing the ID field and thus it is always assumed that there is one record returned from the query, which you are trying to assign to a List, resulting in the error.



The correct syntax here should be as:



Id voterId = [select ID from Vote__c where suggestion__c =: recordId LIMIT 1].ID;


If you want to get the List of ids, then you should have something as below (there are other approaches too) and then get the Id of the records:



List<Vote__c> voterIds = [select ID from Vote__c where suggestion__c =: recordId];
List<Id> idList = new List<Id>();
for(Vote__c v : voterIds)
idList.add(v.Id);






share|improve this answer
































    3














    As it says, you're trying to assign an Id (a scalar value) to a collection. You need a loop for this:



    Id[] voterIds = new Id[0];
    for(Vote__c record: [SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId])
    voterIds.add(record.Id);



    Or, my favorite choice for getting a list of ID values, using a Map to get the values all at once:



    Set<Id> voterIds = new Map<Id, Vote__c>([
    SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId
    ]).keySet();





    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%2f261483%2fillegal-assignment-from-id-to-list%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









      3














      The current syntax you have is incorrect. You dereference a field when you know that your query will return only one record. This is what seems to be the case here where you are dereferencing the ID field and thus it is always assumed that there is one record returned from the query, which you are trying to assign to a List, resulting in the error.



      The correct syntax here should be as:



      Id voterId = [select ID from Vote__c where suggestion__c =: recordId LIMIT 1].ID;


      If you want to get the List of ids, then you should have something as below (there are other approaches too) and then get the Id of the records:



      List<Vote__c> voterIds = [select ID from Vote__c where suggestion__c =: recordId];
      List<Id> idList = new List<Id>();
      for(Vote__c v : voterIds)
      idList.add(v.Id);






      share|improve this answer





























        3














        The current syntax you have is incorrect. You dereference a field when you know that your query will return only one record. This is what seems to be the case here where you are dereferencing the ID field and thus it is always assumed that there is one record returned from the query, which you are trying to assign to a List, resulting in the error.



        The correct syntax here should be as:



        Id voterId = [select ID from Vote__c where suggestion__c =: recordId LIMIT 1].ID;


        If you want to get the List of ids, then you should have something as below (there are other approaches too) and then get the Id of the records:



        List<Vote__c> voterIds = [select ID from Vote__c where suggestion__c =: recordId];
        List<Id> idList = new List<Id>();
        for(Vote__c v : voterIds)
        idList.add(v.Id);






        share|improve this answer



























          3












          3








          3







          The current syntax you have is incorrect. You dereference a field when you know that your query will return only one record. This is what seems to be the case here where you are dereferencing the ID field and thus it is always assumed that there is one record returned from the query, which you are trying to assign to a List, resulting in the error.



          The correct syntax here should be as:



          Id voterId = [select ID from Vote__c where suggestion__c =: recordId LIMIT 1].ID;


          If you want to get the List of ids, then you should have something as below (there are other approaches too) and then get the Id of the records:



          List<Vote__c> voterIds = [select ID from Vote__c where suggestion__c =: recordId];
          List<Id> idList = new List<Id>();
          for(Vote__c v : voterIds)
          idList.add(v.Id);






          share|improve this answer















          The current syntax you have is incorrect. You dereference a field when you know that your query will return only one record. This is what seems to be the case here where you are dereferencing the ID field and thus it is always assumed that there is one record returned from the query, which you are trying to assign to a List, resulting in the error.



          The correct syntax here should be as:



          Id voterId = [select ID from Vote__c where suggestion__c =: recordId LIMIT 1].ID;


          If you want to get the List of ids, then you should have something as below (there are other approaches too) and then get the Id of the records:



          List<Vote__c> voterIds = [select ID from Vote__c where suggestion__c =: recordId];
          List<Id> idList = new List<Id>();
          for(Vote__c v : voterIds)
          idList.add(v.Id);







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 hours ago

























          answered 5 hours ago









          Jayant DasJayant Das

          20k21331




          20k21331























              3














              As it says, you're trying to assign an Id (a scalar value) to a collection. You need a loop for this:



              Id[] voterIds = new Id[0];
              for(Vote__c record: [SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId])
              voterIds.add(record.Id);



              Or, my favorite choice for getting a list of ID values, using a Map to get the values all at once:



              Set<Id> voterIds = new Map<Id, Vote__c>([
              SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId
              ]).keySet();





              share|improve this answer



























                3














                As it says, you're trying to assign an Id (a scalar value) to a collection. You need a loop for this:



                Id[] voterIds = new Id[0];
                for(Vote__c record: [SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId])
                voterIds.add(record.Id);



                Or, my favorite choice for getting a list of ID values, using a Map to get the values all at once:



                Set<Id> voterIds = new Map<Id, Vote__c>([
                SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId
                ]).keySet();





                share|improve this answer

























                  3












                  3








                  3







                  As it says, you're trying to assign an Id (a scalar value) to a collection. You need a loop for this:



                  Id[] voterIds = new Id[0];
                  for(Vote__c record: [SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId])
                  voterIds.add(record.Id);



                  Or, my favorite choice for getting a list of ID values, using a Map to get the values all at once:



                  Set<Id> voterIds = new Map<Id, Vote__c>([
                  SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId
                  ]).keySet();





                  share|improve this answer













                  As it says, you're trying to assign an Id (a scalar value) to a collection. You need a loop for this:



                  Id[] voterIds = new Id[0];
                  for(Vote__c record: [SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId])
                  voterIds.add(record.Id);



                  Or, my favorite choice for getting a list of ID values, using a Map to get the values all at once:



                  Set<Id> voterIds = new Map<Id, Vote__c>([
                  SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId
                  ]).keySet();






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 5 hours ago









                  sfdcfoxsfdcfox

                  269k13215464




                  269k13215464



























                      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%2f261483%2fillegal-assignment-from-id-to-list%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

                      Siegen Nawigatsjuun

                      Log på Navigationsmenu

                      Log på Navigationsmenu