+ Start a Discussion
Btuitasi1Btuitasi1 

How to map form to specific record criteria

I have a visualforce page with a 2 repeaters: 
- 1 that shows an record that has an "Active" checkbox as "True" (Topic cObject)
- 1 that shows comments on the above (they are related by a master-detail relationship)

I have a form on the page that allows users to comment on the "Active" topic. How do I make it so that records created from the form automatically lookup to the topic with the "Active" checkbox marked? 

Here is my controller so far:
public with sharing class challengeDiscuss {
    // declare the instance
    public Challenge_Comment__c commentObj {get; set;}
     
    // Constructor of the class
    public challengeDiscuss(){
        commentObj = new Challenge_Comment__c();
    }
     public void saveComments(){
        // insert or update comments - depends on your requirement
        try{
            insert commentObj;
        }catch(Exception ex){
            System.debug('#### Error while inserting comments #### ' + ex.getMessage());
        }

}

    public List<Challenge__c> getRecentChallenge1()
    {
        return [SELECT Id, Name, CreatedDate, Description__c FROM Challenge__c WHERE Active__c = true order by createdDate desc Limit 1];
    }
    public List<Challenge_Comment__c> getRecentComments10()
    {
        return [SELECT Id, Name, CreatedDate, Comment__c FROM Challenge_Comment__c WHERE Challenge__r.Active__c = true order by createdDate desc, CreatedDate desc ];
    }
 
}
Also, my records don't seem to be submitting.

Any helo is much appreciated. 

Thanks!
 
ShashankShashank (Salesforce Developers) 
You may want to consider using a wrapper class: https://developer.salesforce.com/page/Wrapper_Class