0

I have a requirement to use contact to create a new case. I have created a new page using case.contactID input field. On pressing a command button, the contact selected should be passed to new VF page so that that can be used to create a New case. But I am currently stuck passing the selected value even to the controller(Null is passed). I am new to VF and Apex. Please advise how to do it, then I will need to pass the value to anther page. Below are my Apex class And VF code.

VF Page Code:

<apex:page controller="Create_case" tabStyle="Case">
<apex:form >
    <apex:pageBlock title="New Case">
        <apex:pageBlockSection columns="1">
            <!--Enter the text to be passed: <apex:inputText value="{!strText}"/>-->
            <apex:inputfield value="{!c.contactID}" label="Search Contact" id="conselected"/> 
            <!--<apex:actionsupport event="onchange" action="{!conselected}" />-->
            <apex:commandButton value=" Go " action="{!callcasetabsearch}" id="abc"/>

        </apex:pageBlockSection>
            <apex:commandButton value=" Add New Contact " action="{!callcasetabnewcon}"/>
    </apex:pageBlock>
</apex:form>

Controller Code:

public class Create_case {
public case c {get;set;}
public id conselected {get;set;}
public contact con{get;set;}

public string conId {get;set;}

public Create_case () {
case c= new case();
}

public PageReference callcasetabsearch() {  
 system.debug('Button method called');
 Id conID= conselected;
    contact con= new contact();
if(conID!= null) {
con=[Select firstname from contact where id=:conID];
}
system.debug('value of contact id is:'+ conID);
 //if(c.ContactId != null) {

//con=[Select firstname from contact where id=:c.ContactId];
//strText= con.firstname;
//pageReference pr = Page.assign_1_Case_search; 
  //  pr.getParameters().put('str', strText);
    //pr.getParameters().put('msg','success');
    //pr.setRedirect(false);
    //return pr;
    //}
    //else
    return null;

}

}

  • Where is the "callcasetabnewcon" method in your code? It's not in the code you are showing. Also, how/where is the vf page being displayed? – CommonCoreTawan Oct 28 '19 at 11:15
  • I removed that for simplicity here and to avoid confusion. If the user does not select contact or find contact in the lookup, they can create a new contact. That is another functionality for the page. – Aditya Oct 28 '19 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.