0

I am trying to put in a query for a value that is entered in a field on the visual force page. When the submit button is selected it will go through and query the contact data and match the email address on that to the text field that we have created on the vf page. Once it has found a match it will update the contact id on the case record and insert the data.

public class attachController{
public case objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}

RecordType recordId = [SELECT Id FROM RecordType WHERE DeveloperName = 'Product_Case'];
Id recId = (recordId != null) ? recordId.Id : null;

Group queueId = [select Id from Group where Type = 'Queue' AND DeveloperNAME = 'Product_Support_Case_Queue' LIMIT 1];
Id ownerId = (queueId != null) ? queueId.Id : null;

//string recId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Product Case').getRecordTypeId();

public attachController(Apexpages.standardcontroller controller)
{
    objcase = (Case)controller.getRecord();
    myAttachment = new Attachment();
}
public PageReference submit(){
  List<Contact> contacts = [SELECT Id, Email FROM Contact];

    Contact con = [SELECT Id, Email FROM Contact];
    String conId = [SELECT Id, Email FROM Contact WHERE Email := con].Id;

    if (fileName != null){
        objcase.RecordTypeId = recId;
        objcase.ownerId = ownerId;
        objcase.contactID = conId;
        insert objcase;

        myAttachment = new Attachment();
        Integer i=0;
        myAttachment .clear();
        myAttachment.Body = fileBody;
        myAttachment.Name = fileName ;
        myAttachment.ParentId = objcase.id;            
        insert myAttachment;
    } else {
        objcase.RecordTypeId = recId;
        objcase.ownerId = ownerId;
        objcase.contactID = conId;
        insert objcase;

    }             
    pagereference pr = Page.thankYouForSubmittingYourProductCase;                          
    pr.setRedirect(true);
    return pr;
}}
1
  • note that Case objects have a standard field ContactId that references the contact so you might not need to query based on email (and there could be many Contacts w/ same email)
    – cropredy
    Commented May 22, 2019 at 19:01

1 Answer 1

0

On your VF page, you need to bind the input field with your controller or a member variable (and have a getter, setter).

so your vf page might look like this:

<apex:page standardController="Case">
    <apex:form>
     ......
        <apex:inputField value="{!con.Email }"/>
        <apex:commandButton action="{! submit }" value="Submit" />
     ........
    </apex:form>
</apex:page>

From there, create a member variable with setters and getters and update the submit method to query on that contact's email address

Here is a trailhead on VF forms: https://trailhead.salesforce.com/en/content/learn/modules/visualforce_fundamentals/visualforce_forms

Here is a trailhead on custom controllers: https://trailhead.salesforce.com/en/content/learn/modules/visualforce_fundamentals/visualforce_custom_controllers

3
  • Ohana, thanks for your response! I'm a little confused on this part: "From there, create a member variable with setters and getters and update the submit method to query on that contact's email address" I'm pretty new to development, so reading that is almost foreign to me. Are you able to elaborate? Commented May 21, 2019 at 22:37
  • Which part can I assist with? Commented May 21, 2019 at 22:38
  • How do I create a member variable with setters and getters? Commented May 22, 2019 at 4:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .