+ Start a Discussion
Vincent van Drunen LittelVincent van Drunen Littel 

Problems with a visualforce page

Hi I would like some help on this visual force page
what I need is to have a page that displays all contacts and their account next to each other.
with checkbox next to them to select them and add them as target (custom object) which has a trigger when contact is created a target is created with basic info. 
the controller is 
public class ContactsController {

    public String selectedContactsIds { get; set; }

    public PageReference addContact() {
        return null;
    }


    public List contacts {get; set;}
    Map contactMap {get; set;}
     public string selectedContactIds {get; set;}
    string parentContactId;
    public ContactsController() // CHANGE THIS (SelectConcorrenteController TO ConcorrenteController)
    {
        parentContactId = ApexPages.currentPage().getParameters().get('accId');
        contactMap = new Map([select Id, Name from Contact]);
        contacts = contactMap.Values();
    }
    
     public PageReference addTargets() {
        List contactIds = selectedContactIds.split(',');
        List Targets = new List();
        
        for (string s : contactIds)
        {
            Target__c Target = new Target__c(Target__c = parentContactId, Name = contactMap.get(s).Name); 
            Targets.add(target);
        }
        if (Targets.size() > 0)
        {
            insert Targets;
        }
        string strPageRef = '"javascript:window.close();"';
        return new PageReference(strPageRef);
    }
}
Visual force is



    
        
        
            
                
                    
                
                
               
            
            
        
    


When i added  it gives me the error 

SObject row was retrieved via SOQL without querying the requested field: Contact.Account 
 

When I added to Account.Name

contactMap = new Map([select Id, Name, Account.Name from Contact])
I received this error 
Expression value does not resolve to a field
Error is in expression '{!con.Account}' in component in page contactsvf

If anyone would know how to fix this??
 

Best Answer chosen by Vincent van Drunen Littel
Himanshu ParasharHimanshu Parashar
Hi Vincent,

You need to make it as 
 
{!con.Account.Name}
Thanks,
Himanshu
 

All Answers

Vincent van Drunen LittelVincent van Drunen Littel
resolved it actually.. 
with following codes
Now i would like to get help with leaving it nicely organized so its alphabetically organized and has a search button.. 
Thanks in advance for the help
public class ContactsController {

    public String selectedContactsIds { get; set; }

    public PageReference addContact() {
        return null;
    }


    public List contacts {get; set;}
    Map contactMap {get; set;}
     public string selectedContactIds {get; set;}
    string parentContactId;
    public ContactsController() // CHANGE THIS (SelectConcorrenteController TO ConcorrenteController)
    {
        parentContactId = ApexPages.currentPage().getParameters().get('accId');
        contactMap = new Map([select Id, Name, Account.Name from Contact]);
        contacts = contactMap.Values();
    }
    
     public PageReference addTargets() {
        List contactIds = selectedContactIds.split(',');
        List Targets = new List();
        
        for (string s : contactIds)
        {
            Target__c Target = new Target__c(Target__c = parentContactId, Name = contactMap.get(s).Name); 
            Targets.add(target);
        }
        if (Targets.size() > 0)
        {
            insert Targets;
        }
        string strPageRef = '"javascript:window.close();"';
        return new PageReference(strPageRef);
    }
}



    
        
        
            
                
                    
                
                
                
             
            
        
    
Himanshu ParasharHimanshu Parashar
Hi Vincent,

You need to make it as 
 
{!con.Account.Name}
Thanks,
Himanshu
 
This was selected as the best answer
Vincent van Drunen LittelVincent van Drunen Littel
for some reason my visual force didnt show in my previous comment.. but that was what i did Himanshu ! thanks!

Would you be able to help me with leaving it nicely organized so its alphabetically organized and has a search button..??
Vincent van Drunen LittelVincent van Drunen Littel
ops, forgot to say... when trying to press "add target" it doesnt add as supposed to do