You need to sign in to do that
Don't have an account?

can we use soql query in set method
im just wan o control the dublicate in emails ids in the contacts in accoun so that i wan to use set method
can i write my query like this
set <contact> conids=[select id,email from contact where id=:accountid];
set <id> contactemail=new set<id>();
for(contact con:conids)
{
contactemail.add(con.id)
}
can i write like this
if any one knw help me in this
can i write my query like this
set <contact> conids=[select id,email from contact where id=:accountid];
set <id> contactemail=new set<id>();
for(contact con:conids)
{
contactemail.add(con.id)
}
can i write like this
if any one knw help me in this
Yes that will work but you have to use a more selective query to avoid governor limits.
Regards,
Ashish
Map<Id, Contact> contacts = new Map<Id, Contact>([SELECT id, email FROM Contact where AccountId=:accountId]);
contacts.KeySet() will contain the id's
set <contact> conids=[select id from contact where id!=:null]; // you can't use this. Becoz this ll return illegal assignment from list to set
you can you Andries way this is best way,
map<Id, Contact> contacts = new Map<Id, Contact>([SELECT id, email FROM Contact where AccountId=:accountId]);
contacts.KeySet() //this will contain the unique contacts id's
else you can use this
list<Contact> contacts = new list<Contact>([SELECT id, email FROM Contact where AccountId=:accountId]);
set<id> idval;
for(Contact c: contacts)
{
idval.add(c.id) //this will contain the unique contacts id's
}