You need to sign in to do that
Don't have an account?
Anilt
Case Record Creation With SOQL
Hi Everyone,
I want to insert a record in Case with fields Name, Email.
I'm confused how to write SOQL query for retrieving the account name (=case name) and Contact Email (=case email).
Please help me in writing a SOQL query for this.
Let me know if you need more explanation on this .
Hi,
Are you Creating case using trigger?
What is the senario.
Regards,
Manjunath
Hi Manjunath,
Thanks for your response.
Here is my code:
<apex:page StandardController="Case" Extensions="ONEN_CTRL_WebToCase" action="{!submitCase}">
<apex:form >
<table>
<tr>
<th>Your Name:</th>
<td><apex:inputText value="{!Case.Contact.LastName}"/></td>
</tr>
<tr>
<th>Your Email:</th>
<td><apex:inputText value="{!Case.Contact.Email}"/></td>
</tr>
<tr>
<td align="right">
<apex:outputLabel value="Reason for Contact" for="txtPostalCode" styleClass="label" /><br/>
</td>
<td>
<apex:selectlist value="{!Case.Description}" id="txtPostalCode" styleclass="select">
<apex:selectOptions value="{!reason4Contact}"/>
</apex:selectlist>
</td>
</tr>
<tr>
<td><apex:commandButton value="Save" action="{!save}"/></td>
</tr>
</table>
</apex:form>
</apex:page>
public class ONEN_CTRL_WebToCase {
Public Contact Contact {get; set;}
Public Case cas {get; set;}
public List<SelectOption> getReason4Contact() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Select a Topic','Select a Topic'));
return options;
}
public PageReference save() {
return null;
}
public PageReference submitCase() {
Map<string,string> postParameters = ApexPages.currentPage().getParameters();
Contact=new Contact();
if (!postParameters.isEmpty()) {
String reason4Con = ApexPages.currentPage().getParameters().get('reason4Con');
if (ApexPages.currentPage().getParameters().get('Last_Name')==null || ApexPages.currentPage().getParameters().get('Last_Name')=='') {
Contact.LastName = '[not provided]';
} else {
Contact.LastName = ApexPages.currentPage().getParameters().get('Last_Name');
}
Contact.Email = ApexPages.currentPage().getParameters().get('Email');
Insert Contact;
}
return null;
}
public ONEN_CTRL_WebToCase(ApexPages.StandardController controller) {
}
}
Here, I'm able to insert the Contact.
So here my scenario is to create the case by providing field values of case in url.
like ex: '/apex/CreateCase_URL' is the url of my VF Page
So I'll insert a record in case by providing values like '/apex/CreateCase_URL/Last_Name=xxxxx&Email=yyyyyyy' which inserts the record in case with those values (but here happening is that I'm able to insert only contact not the actual case object record).
Can you please let me know where am I doing wrong.
Thanks for your quick reply. I'll go through this and let you know for any further assistance.
Hi,
Your code will execute every time url is entered. (Am not sure you are doing that.).
I believe that you have add name and email custom field in your case object .
But I modified your code as follows. Just give the contact id in your URL
Ex : /apex/CreateCase_URL?cid='Your Contact rec id'
Controller Code goes as follows
Regards,
Manjunath
Hi Manjunath,
Thanks for your help. but as we are integrating the case fields with the client's html fields..we have no choice to go in another way rather than our way.
Please suggest whether it is possible to implement the things in my way, as I know I'm very close to the solution (I'm able to insert the contact record and not able to insert the case record).
I'm sorry to tell you the above things.
Hi
you are passing Contact Name and Email in the Url but where you are getting and inserting these values.
i didn't see can you post /apex/CreateCase_URL page code.
Hi,
Still am no clear with your requirement.
Based on my understanding.
Create a case object in your submitCase() function insert the Last_name and email to the case object as you do for contact (Fill all the required fields of the case object).
public PageReference submitCase()
{
Map<string,string> postParameters = ApexPages.currentPage().getParameters();
Contact=new Contact();
cas=new Case();
if (!postParameters.isEmpty())
{ String reason4Con = ApexPages.currentPage().getParameters().get('reason4Con');
if (ApexPages.currentPage().getParameters().get('Last_Name')==null || ApexPages.currentPage().getParameters().get('Last_Name')=='')
{
Contact.LastName = '[not provided]';
cas.LastName='[not provided]';
}
else {
Contact.LastName = ApexPages.currentPage().getParameters().get('Last_Name');
cas.LastName= ApexPages.currentPage().getParameters().get('Last_Name');
}
Contact.Email = ApexPages.currentPage().getParameters().get('Email');
cas.Email= ApexPages.currentPage().getParameters().get('Email');
Insert Contact;
insert cas;
} return null;
}
Regards,
Manjunath
Hi Mahender,
Please go through my code pasted in the above comments...!
@Manjunath: My client webpage has 3 fields (2 text fields, 1 picklist) which must be redirect to the Case fields (LastName, Email, Description).
Please go through my answers to your red marked questions.
cas=new Case(); //To have an Id of a case object.
cas.LastName='[not provided]'; // If customer has not entered text in this field..as it is a manditory field, it will error out.
else
cas.LastName= ApexPages.currentPage().getParameters().get('Last_Name'); //If Customer entered this..It will get the values from url of the current page.
cas.Email= ApexPages.currentPage().getParameters().get('Email'); //same as the Last_Name...but it is not manditory.
HI
Have you written below line.
Insert cas;
if you written even thought the case is not inserting then go and check it in the Developer Console.
Hi,
Those red lines are not question. Those are the things you need to do in your controller (make sure you add data to all the required fields of the case).
Regards,
Manjunath.