• ishu
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I have a trigger which occurs on update or insert on the account object. Upon deploying the trigger i kept hitting governer limits so I tried to utilize IN clauses for my soql queries instead of the = statements which I used to write.

 

In changing my code to be more efficient I am now getting an unexpected error from a Sets list.  I thought that Sets were to hvae only unique values in them? so when I query the Set in my soql statement how is it that I'm getting the error that it is returning more than one result?  Here are the pertenant pieces of my code if you need more let me know:

 

 

//Created SETS to hold unique values for recordTypeId's, AccountId's and parentId's

Set<Id> recTypeIds = new Set<Id>();

Set<Id> accIds = new Set<Id>();

Set<id> prntIds = new Set<id>();

 

//Iterate through trigger.new and assign accountId, parentId and

//recordType id to their respective SETS

for(Account acc : Trigger.new){

 

accIds.add(acc.id);

 

prntIds.add(acc.ParentId);

 

recTypeIds.add(acc.RecordTypeId);

}

 

then later on in the code I make an assignment from a SOQL query, this following line is where I get the error:

 

 

//New instance of RecordType to be used to populate the record type field

//on the customer lookup object

RecordType rType;

rType = [select name from RecordType where id IN :recTypeIds];

 

 The way I interprate the error is that there are duplicate RecordTypeId's in the recTypeId's data Set.  I'm not sure how this can be the case however?  In my first snippet of code, are dupes pushed into my recTypeIds set?  I thought it would be rejected or atleast throw me an error.

 

Thanks to all who view and respond. 

 

 

Message Edited by astro on 03-10-2009 05:05 PM
Message Edited by astro on 03-10-2009 05:21 PM
  • March 11, 2009
  • Like
  • 0