• shravan gouri
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Sfdc Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hai All

I have an requirement that when i enter account name in text box click on submit it display all the related contact records 
Please check my code

public class conbyacc {
    public String accname{set;get;}
    public list<Account> acclist{set;get;}
    public list<Contact> conlist{set;get;}
    public set<Account> accids{set;get;}
    public list<Contact> getcons(){
        acclist.clear();
        conlist.clear();
        accids.clear();
        acclist=[select Id,name from Account where name=:accname];
        for(Integer i=0; i<acclist.size(); i++){
            accids.add(acclist[i].Id);  // Getting Error
        }
        conlist=[select name,accountid from Contact where accountid IN:accids];
        return conlist;
        
    }

}


Thanks In Advance
Sampath Palli