0 votes

I have created a simple form that creates a new record in a Case when submitted. I can populate the text/String fields ok but the "Contact" field is giving me trouble because it is a Lookup(Contact) field.

I have the Contact's ID that I want to use to populate this field with. (0000a000000XXXX)

This is my current code.

public class program_evaluation_con {

public Boolean submitDisabled { get; set; }
public String feedbackName { get; set; }
public PageReference thankyou = Page.thankyou;

Case feedback = new Case();
public program_evaluation_con() {
// on load disable submit
submitDisabled = false;


 public void preSubmitCase() {
    List<Case> feedback = [SELECT Id FROM Case 
        WHERE CaseNumber = :feedbackName];
    // if there are records, this would be true
    submitDisabled = feedback.size() == 1;

public PageReference submitCase() {
    //form submition function
    Contact feedbackContact = new Contact();
    //feedbackContact = 'Victor Mews';
 feedback.Description = 'test description ok';
 feedback.Subject = 'test subject ok';
 insert feedback;
 return thankyou;

1 Answer

0 votes
Best answer

Given the VF controller has a valid contactId, then creating a Case wouuld look like

public PageReference submitCase() {
    this.feedback = new Case(
       ContactId = ApexPages.currentPage().getParameters().get('contactid'),
       Description = '...',
       Subject = '..'
    insert this.feeback;
    return this.thankyou;

assuming that the URL for the page includes a contactid=003xxxxxxxxxxxxxxx

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.