Help with Query Illegal Assignment from a List to a List

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
2
down vote

favorite












I have a custom object Relationship_Owner__C with a lookup relationship to Contacts. I need to query all the contacts that belong to the relationship owner, and all the tasks assigned to the contact in order to get a count of unique subject lines.



When I tried to break it into two queries I got a SOQL 101 error. But now I seem to be stuck on making it work at all. Any help would be great.



trigger CountUniqueEmails on relationship_owner__c (before insert, before update) {

LIST<Task> taskList =[SELECT ID,
(SELECT Id,
Subject
FROM Tasks)
FROM Contact
WHERE New_Relationship_owner1__c IN :Trigger.New];
system.debug('Influencers found =:' + taskList.size());
//If the list size is greater than 0 get the tasks assigned to the influencers
If(taskList.size() !=0){
String subject = 'none';
Integer uniqueCount = 0;


New Code



trigger CountUniqueEmails on relationship_owner__c (after insert, after update)
Map contactMap = new Map([SELECT Id, New_Relationship_owner1__c
FROM Contact
WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);

List taskList = [SELECT Id, WhoId,Subject
FROM Task
WHERE WhoId IN :contactMap.keySet()];



Map> subjectLineMap = new Map>();



for(Task t: taskList) 
Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

if(!subjectLIneMap.containsKey(relationshipOwnerId))
subjectLineMap.put(relationshipOwnerId, new Set<String>());

subjectLineMap.get(relationshipOwnerId).add(t.Subject);
system.debug('unique subject count=' + subjectLineMap.size());












share|improve this question





























    up vote
    2
    down vote

    favorite












    I have a custom object Relationship_Owner__C with a lookup relationship to Contacts. I need to query all the contacts that belong to the relationship owner, and all the tasks assigned to the contact in order to get a count of unique subject lines.



    When I tried to break it into two queries I got a SOQL 101 error. But now I seem to be stuck on making it work at all. Any help would be great.



    trigger CountUniqueEmails on relationship_owner__c (before insert, before update) {

    LIST<Task> taskList =[SELECT ID,
    (SELECT Id,
    Subject
    FROM Tasks)
    FROM Contact
    WHERE New_Relationship_owner1__c IN :Trigger.New];
    system.debug('Influencers found =:' + taskList.size());
    //If the list size is greater than 0 get the tasks assigned to the influencers
    If(taskList.size() !=0){
    String subject = 'none';
    Integer uniqueCount = 0;


    New Code



    trigger CountUniqueEmails on relationship_owner__c (after insert, after update)
    Map contactMap = new Map([SELECT Id, New_Relationship_owner1__c
    FROM Contact
    WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);

    List taskList = [SELECT Id, WhoId,Subject
    FROM Task
    WHERE WhoId IN :contactMap.keySet()];



    Map> subjectLineMap = new Map>();



    for(Task t: taskList) 
    Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

    if(!subjectLIneMap.containsKey(relationshipOwnerId))
    subjectLineMap.put(relationshipOwnerId, new Set<String>());

    subjectLineMap.get(relationshipOwnerId).add(t.Subject);
    system.debug('unique subject count=' + subjectLineMap.size());












    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a custom object Relationship_Owner__C with a lookup relationship to Contacts. I need to query all the contacts that belong to the relationship owner, and all the tasks assigned to the contact in order to get a count of unique subject lines.



      When I tried to break it into two queries I got a SOQL 101 error. But now I seem to be stuck on making it work at all. Any help would be great.



      trigger CountUniqueEmails on relationship_owner__c (before insert, before update) {

      LIST<Task> taskList =[SELECT ID,
      (SELECT Id,
      Subject
      FROM Tasks)
      FROM Contact
      WHERE New_Relationship_owner1__c IN :Trigger.New];
      system.debug('Influencers found =:' + taskList.size());
      //If the list size is greater than 0 get the tasks assigned to the influencers
      If(taskList.size() !=0){
      String subject = 'none';
      Integer uniqueCount = 0;


      New Code



      trigger CountUniqueEmails on relationship_owner__c (after insert, after update)
      Map contactMap = new Map([SELECT Id, New_Relationship_owner1__c
      FROM Contact
      WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);

      List taskList = [SELECT Id, WhoId,Subject
      FROM Task
      WHERE WhoId IN :contactMap.keySet()];



      Map> subjectLineMap = new Map>();



      for(Task t: taskList) 
      Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

      if(!subjectLIneMap.containsKey(relationshipOwnerId))
      subjectLineMap.put(relationshipOwnerId, new Set<String>());

      subjectLineMap.get(relationshipOwnerId).add(t.Subject);
      system.debug('unique subject count=' + subjectLineMap.size());












      share|improve this question















      I have a custom object Relationship_Owner__C with a lookup relationship to Contacts. I need to query all the contacts that belong to the relationship owner, and all the tasks assigned to the contact in order to get a count of unique subject lines.



      When I tried to break it into two queries I got a SOQL 101 error. But now I seem to be stuck on making it work at all. Any help would be great.



      trigger CountUniqueEmails on relationship_owner__c (before insert, before update) {

      LIST<Task> taskList =[SELECT ID,
      (SELECT Id,
      Subject
      FROM Tasks)
      FROM Contact
      WHERE New_Relationship_owner1__c IN :Trigger.New];
      system.debug('Influencers found =:' + taskList.size());
      //If the list size is greater than 0 get the tasks assigned to the influencers
      If(taskList.size() !=0){
      String subject = 'none';
      Integer uniqueCount = 0;


      New Code



      trigger CountUniqueEmails on relationship_owner__c (after insert, after update)
      Map contactMap = new Map([SELECT Id, New_Relationship_owner1__c
      FROM Contact
      WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);

      List taskList = [SELECT Id, WhoId,Subject
      FROM Task
      WHERE WhoId IN :contactMap.keySet()];



      Map> subjectLineMap = new Map>();



      for(Task t: taskList) 
      Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

      if(!subjectLIneMap.containsKey(relationshipOwnerId))
      subjectLineMap.put(relationshipOwnerId, new Set<String>());

      subjectLineMap.get(relationshipOwnerId).add(t.Subject);
      system.debug('unique subject count=' + subjectLineMap.size());









      trigger soql learning






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 16 at 21:10

























      asked Aug 16 at 19:34









      Brooks Johnson

      717




      717




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          Direct Answer



          Your query's result type will be a List<sObject>, where sObject is the primary object in the query. In this case,



          SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact...


          the primary object is Contact. For that reason, the return value will be List<Contact>.



          Note also that you cannot use Trigger.new as a bind variable for an Id query. You can use Trigger.newMap.keySet(), because it's the right data type:



          SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()


          Another Approach



          If what you want, though, is the unique subject lines of Tasks attached to Contacts which have specific relationship owners, but you do not need them grouped by the individual Contact, you can break the query into two to go straight to the Task level. It would look something like this:



          Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);
          List<Task> taskList = [SELECT Id, WhoId, Subject FROM Task WHERE WhoId IN :contactMap.keySet()];
          Map<Id, Set> subjectLineMap = new Map<Id, Set>();


          Then you can iterate over those Tasks:



          for (Task t: taskList) 
          Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

          if (!subjectLineMap.containsKey(relationshipOwnerId))
          subjectLineMap.put(relationshipOwnerId, new Set<String>());


          subjectLineMap.get(relationshipOwnerId).add(t.Subject);



          Then your subjectLineMap ends up with one Set of the unique Subject lines, across all contacts, for each Relationship Owner. You can inspect the size of the set for an owner's Id to see how many unique subject lines there were (note that it's case sensitive).






          share|improve this answer





























            up vote
            2
            down vote













            you are querying FROM Contact so the list must be of type list'(Contact)'..



            if you want to check to see if any tasks are related to a contact you need to iterate over the list of contacts and see if tasks exists.



            for( Contact con : [SELECT ID,
            (SELECT Id,
            Subject
            FROM Tasks)
            FROM Contact
            WHERE New_Relationship_owner1__c IN :Trigger.New])

            if ( con.tasks.isEmpty() )

            // no tasks assigned to contact

            else

            // tasks exists for this contact







            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%2f229143%2fhelp-with-query-illegal-assignment-from-a-list-to-a-list%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              6
              down vote



              accepted










              Direct Answer



              Your query's result type will be a List<sObject>, where sObject is the primary object in the query. In this case,



              SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact...


              the primary object is Contact. For that reason, the return value will be List<Contact>.



              Note also that you cannot use Trigger.new as a bind variable for an Id query. You can use Trigger.newMap.keySet(), because it's the right data type:



              SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()


              Another Approach



              If what you want, though, is the unique subject lines of Tasks attached to Contacts which have specific relationship owners, but you do not need them grouped by the individual Contact, you can break the query into two to go straight to the Task level. It would look something like this:



              Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);
              List<Task> taskList = [SELECT Id, WhoId, Subject FROM Task WHERE WhoId IN :contactMap.keySet()];
              Map<Id, Set> subjectLineMap = new Map<Id, Set>();


              Then you can iterate over those Tasks:



              for (Task t: taskList) 
              Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

              if (!subjectLineMap.containsKey(relationshipOwnerId))
              subjectLineMap.put(relationshipOwnerId, new Set<String>());


              subjectLineMap.get(relationshipOwnerId).add(t.Subject);



              Then your subjectLineMap ends up with one Set of the unique Subject lines, across all contacts, for each Relationship Owner. You can inspect the size of the set for an owner's Id to see how many unique subject lines there were (note that it's case sensitive).






              share|improve this answer


























                up vote
                6
                down vote



                accepted










                Direct Answer



                Your query's result type will be a List<sObject>, where sObject is the primary object in the query. In this case,



                SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact...


                the primary object is Contact. For that reason, the return value will be List<Contact>.



                Note also that you cannot use Trigger.new as a bind variable for an Id query. You can use Trigger.newMap.keySet(), because it's the right data type:



                SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()


                Another Approach



                If what you want, though, is the unique subject lines of Tasks attached to Contacts which have specific relationship owners, but you do not need them grouped by the individual Contact, you can break the query into two to go straight to the Task level. It would look something like this:



                Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);
                List<Task> taskList = [SELECT Id, WhoId, Subject FROM Task WHERE WhoId IN :contactMap.keySet()];
                Map<Id, Set> subjectLineMap = new Map<Id, Set>();


                Then you can iterate over those Tasks:



                for (Task t: taskList) 
                Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

                if (!subjectLineMap.containsKey(relationshipOwnerId))
                subjectLineMap.put(relationshipOwnerId, new Set<String>());


                subjectLineMap.get(relationshipOwnerId).add(t.Subject);



                Then your subjectLineMap ends up with one Set of the unique Subject lines, across all contacts, for each Relationship Owner. You can inspect the size of the set for an owner's Id to see how many unique subject lines there were (note that it's case sensitive).






                share|improve this answer
























                  up vote
                  6
                  down vote



                  accepted







                  up vote
                  6
                  down vote



                  accepted






                  Direct Answer



                  Your query's result type will be a List<sObject>, where sObject is the primary object in the query. In this case,



                  SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact...


                  the primary object is Contact. For that reason, the return value will be List<Contact>.



                  Note also that you cannot use Trigger.new as a bind variable for an Id query. You can use Trigger.newMap.keySet(), because it's the right data type:



                  SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()


                  Another Approach



                  If what you want, though, is the unique subject lines of Tasks attached to Contacts which have specific relationship owners, but you do not need them grouped by the individual Contact, you can break the query into two to go straight to the Task level. It would look something like this:



                  Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);
                  List<Task> taskList = [SELECT Id, WhoId, Subject FROM Task WHERE WhoId IN :contactMap.keySet()];
                  Map<Id, Set> subjectLineMap = new Map<Id, Set>();


                  Then you can iterate over those Tasks:



                  for (Task t: taskList) 
                  Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

                  if (!subjectLineMap.containsKey(relationshipOwnerId))
                  subjectLineMap.put(relationshipOwnerId, new Set<String>());


                  subjectLineMap.get(relationshipOwnerId).add(t.Subject);



                  Then your subjectLineMap ends up with one Set of the unique Subject lines, across all contacts, for each Relationship Owner. You can inspect the size of the set for an owner's Id to see how many unique subject lines there were (note that it's case sensitive).






                  share|improve this answer














                  Direct Answer



                  Your query's result type will be a List<sObject>, where sObject is the primary object in the query. In this case,



                  SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact...


                  the primary object is Contact. For that reason, the return value will be List<Contact>.



                  Note also that you cannot use Trigger.new as a bind variable for an Id query. You can use Trigger.newMap.keySet(), because it's the right data type:



                  SELECT ID, (SELECT Id, Subject FROM Tasks) FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()


                  Another Approach



                  If what you want, though, is the unique subject lines of Tasks attached to Contacts which have specific relationship owners, but you do not need them grouped by the individual Contact, you can break the query into two to go straight to the Task level. It would look something like this:



                  Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id FROM Contact WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);
                  List<Task> taskList = [SELECT Id, WhoId, Subject FROM Task WHERE WhoId IN :contactMap.keySet()];
                  Map<Id, Set> subjectLineMap = new Map<Id, Set>();


                  Then you can iterate over those Tasks:



                  for (Task t: taskList) 
                  Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;

                  if (!subjectLineMap.containsKey(relationshipOwnerId))
                  subjectLineMap.put(relationshipOwnerId, new Set<String>());


                  subjectLineMap.get(relationshipOwnerId).add(t.Subject);



                  Then your subjectLineMap ends up with one Set of the unique Subject lines, across all contacts, for each Relationship Owner. You can inspect the size of the set for an owner's Id to see how many unique subject lines there were (note that it's case sensitive).







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 16 at 21:08

























                  answered Aug 16 at 20:07









                  David Reed

                  20.3k31640




                  20.3k31640






















                      up vote
                      2
                      down vote













                      you are querying FROM Contact so the list must be of type list'(Contact)'..



                      if you want to check to see if any tasks are related to a contact you need to iterate over the list of contacts and see if tasks exists.



                      for( Contact con : [SELECT ID,
                      (SELECT Id,
                      Subject
                      FROM Tasks)
                      FROM Contact
                      WHERE New_Relationship_owner1__c IN :Trigger.New])

                      if ( con.tasks.isEmpty() )

                      // no tasks assigned to contact

                      else

                      // tasks exists for this contact







                      share|improve this answer
























                        up vote
                        2
                        down vote













                        you are querying FROM Contact so the list must be of type list'(Contact)'..



                        if you want to check to see if any tasks are related to a contact you need to iterate over the list of contacts and see if tasks exists.



                        for( Contact con : [SELECT ID,
                        (SELECT Id,
                        Subject
                        FROM Tasks)
                        FROM Contact
                        WHERE New_Relationship_owner1__c IN :Trigger.New])

                        if ( con.tasks.isEmpty() )

                        // no tasks assigned to contact

                        else

                        // tasks exists for this contact







                        share|improve this answer






















                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          you are querying FROM Contact so the list must be of type list'(Contact)'..



                          if you want to check to see if any tasks are related to a contact you need to iterate over the list of contacts and see if tasks exists.



                          for( Contact con : [SELECT ID,
                          (SELECT Id,
                          Subject
                          FROM Tasks)
                          FROM Contact
                          WHERE New_Relationship_owner1__c IN :Trigger.New])

                          if ( con.tasks.isEmpty() )

                          // no tasks assigned to contact

                          else

                          // tasks exists for this contact







                          share|improve this answer












                          you are querying FROM Contact so the list must be of type list'(Contact)'..



                          if you want to check to see if any tasks are related to a contact you need to iterate over the list of contacts and see if tasks exists.



                          for( Contact con : [SELECT ID,
                          (SELECT Id,
                          Subject
                          FROM Tasks)
                          FROM Contact
                          WHERE New_Relationship_owner1__c IN :Trigger.New])

                          if ( con.tasks.isEmpty() )

                          // no tasks assigned to contact

                          else

                          // tasks exists for this contact








                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 16 at 19:40









                          Benjamin Pirih

                          1,696719




                          1,696719



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f229143%2fhelp-with-query-illegal-assignment-from-a-list-to-a-list%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Bahrain

                              Postfix configuration issue with fips on centos 7; mailgun relay