Salesforce: Creating a User Form using VisualFocre - salesforce

I have below requirement to Create a VF page.
I created a custom object called DormsApplicants__c There are several fields but for the purposes of the example we will use only one field called First_name__c.
My main need is to create a VF page that will be available to people outside the organization (i.e. customers) who can enter data into the form and then create a record in the custom object DormsApplicants__c. For this purpose I created a website (SITE.COM) and then created a VF page (called TEST) I defined this page (TEST) as a home page on the site.
This is my page:
<apex:page standardController="DormsApplicants__c" sidebar="false">
<apex:form id="theForm">
<apex:pageBlock title="TEST">
<apex:inputText title="TEXTBOX1" label="TEXTBOX2" value="{!DormsApplicants__c.First_name__c}"/>
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
Image A1 - This is what users see outside the organization.
When the user tries to click "save" he gets the following error:
Image B1 - error on save
Of course no record is created. I'd love to hear what the problem is?

Related

Apex:repeat two time

I have a visualforce page with the standardController to a custom object.
I want to get all orders (Orders__c) from an event (Event__c). I started by the offer (Offer__c)
Offer is in master-detail with the event and the event is in master-detail with the orders.
I have tried two following codes:
<apex:page standardController="Caterer_Offer__c" sidebar="false" showHeader="false" >
<apex:repeat var="events" value="{!Caterer_Offer__c.Event__r}">
{!events.Name}
<apex:repeat var="orders" value="{!events.Orders__r}">
<!-- {!orders.Name}-->
</apex:repeat>
</apex:repeat>
At this the error-message in the developer console is:
"Aggregate Relationship is used in an unsupported complex expression containing 'Event__r.orders__r'"
And...then I have trief to save the event and use a new variable to "repeat" all orders. I get no error message, but a error in Salesforce
<apex:page standardController="Caterer_Offer__c" sidebar="false" showHeader="false" >
<apex:repeat var="events" value="{!Caterer_Offer__c.Event__r}">
{!events.Name}
<apex:variable var="e" value="{!events}"/>
<apex:repeat var="orders" value="{!e.Orders__r}">
<!-- {!orders.Name}-->
</apex:repeat>
</apex:repeat>
Error-message: SObject row was retrieved via SOQL without querying the
requested field: Event__c.Orders__r
I cannot explain it and work on it since a few hours....
A standardcontroller's record will only contain the fields referenced in the visualforce page you're using it on. You may need to use a custom controller and extend features of standard controller in these cases. The standard controller addFields() method allows you to extend this to the fields you need in your apex code.
I could find a similar solution here.
I'm not sure from your question which object is the Parent record and which is the child, but my answer is going to be based on Caterer_Offer__c being the parent of Event__c and Event__c being the parent of Order__c, so that you can loop through all Orders for an Event for a Catered Offer which is what I think you want to do.
In short what you are trying to do cannot be done in the way you are trying it is because you are in essence trying to perform a child aggregate query that is two levels deep. In essence you are trying to do:
[SELECT Name, (SELECT Name, (SELECT Name FROM Orders__r) FROM Events__r) FROM Caterer_Offer__c];
However salesforce only allows aggregate child queries one level deep, not more. So you have to add an extension that would have code to probably lazy-load the Orders on an event of some sort with a partial page re-render on a link click or button click. In that case you would make the Visualforce page for the Caterer_Offer__c and child Events__c, then load the child Orders from some user action that calls the extension with a element using the id of the selected Event.
But for the error you specifically asked about it would have been:
<apex:page standardController="Caterer_Offer__c" sidebar="false" showHeader="false" >
<apex:repeat var="event" value="{!Caterer_Offer__c.Events__r}">
{!event.Name}
<apex:repeat var="order" value="{!event.Orders__r}">
{!order.Name}
</apex:repeat>
</apex:repeat>
</apex:page>
But again that's not possible because of the aforementioned single depth child aggregation query limitation in salesforce

How to add a visualforce page to the end of existing page according to a condition?

Suppose we have a custom salesforce controller and a custom visualforce page for it. at the end of the visualforce page I like to evaluate a public member variable of the controller and if it is true I like to add the contents of another visualforce page (e.g. apex/test) to the first page.
<apex:page controller="mycontroller">
...........
my tags and page contents comes here
...........
{!if(my_member_variable == true, attach contents of "apex/test" page to end of this page, "do nothing")}
</apex:page>
How can I do that?
In simple words, I am searching for a command similar to include() on PHP for visualforce.
Thanks,
Sounds like you want to use an apex:include along with its rendered attribute.
<apex:page controller="mycontroller">
<!-- ... -->
<apex:include pageName="TheNameOfTheIncludedPage" rendered="{!my_member_variable}"/>
</apex:page>
Incidentally. The salesforce.stackExchange.com is a great place to ask Salesforce specific questions.

How to display page for testing component with sObject?

I'm new to Salesforce/Apex and I need to be able to test a component I am working on in a separate page.
Here is the scenario. I have the following test page:
<apex:page sidebar="false" showHeader="false" standardController="Contact">
<div id="wrapper" style="max-width:980px;">
<c:djEmailTemplate_MainComponent sObject="{!Contact}" theContactId="{!Contact.Id}"/>
</div>
</apex:page>
I can display the page by adding /apex/testpage to the url after the project name.
What I don't know how to do is to include data to satisfy the parameters (sObject, theContactId) that are needed to populate values in the component.
Can anyone explain how I can do this?
Thanks in advance.
Your test page uses the Contact object as its standard controller, so in most cases you would want to specify a Contact record for the page/controller to operate on. You can use any existing Contact record in your org, or create a new one (specifically you'll want to grab the ID of the record) and then append the ID to the URL you're using like so: /apex/testpage?id=003xxxxxxxxxxxx. This will provide the page and controller a record to pass to the VF component.

Salesforce Sites Calendar Not displaying

I have recently started playing around with sites and created a basic page.
<apex:page controller="newController">
<apex:form >
<apex:pageBlock title="Welcome {!$User.FirstName}"></apex:pageBlock>
<apex:pageBlock mode="edit">
<apex:pageBlockSection title="Travel Details" >
<apex:inputField value="{!Booking.StartDateTime__c}"></apex:inputField>
<apex:inputText value="{!Booking.EndDateTime__c}"></apex:inputText>
<apex:inputField value="{!Booking.StartLocation__c}"></apex:inputField>
<apex:inputField value="{!Booking.EndLocation__c}"></apex:inputField>
</apex:pageBlockSection>
</apex:form>
These are the two fields that I display - one problem though, when a user clicks on the field the calendar fails to popup, they are just acting as a normal textbox.
I have searched on the web and checked user and field level permissions and everything seems to be fine. They are of the datatype datetime.
So does anyone know how I can get this calendar to display?
EDIT: I have made the code remedies suggested but unfortunately had no luck. The inputfield now displays the current date time next to the input box(as in salesforce) but still no calendar popup. I have also built the controller. Possibly a javascript issue?
Any help much appreciated,
Cheers
You need to define a standard controller and wrap your inputfield in a form in order to get the calendar to pop up, the code should look like this
<apex:page standardController="Booking__c">
<apex:form >
<apex:inputfield value="{!Booking__c.StartDateTime__c}"/>
<apex:inputfield value="{!Booking__c.EndDateTime__c}"/>
</apex:form>
</apex:page>
Try inputText instead:
Note: Read-only fields, and fields for certain Salesforce objects with complex automatic behavior such as Event.StartDateTime and Event.EndDateTime, don't render as editable when using <apex:inputField>. Use a different input component such as <apex:inputText> instead.
Source: apex:inputField (Salesforce.com)
I figured it out, if anyone comes across the same issue you need to activate the site.
Anyway thanks for all the responses.

Automatically update Visualforce page every time an item from a drop list is picked

I have a visualforce/apex functionality that exports & emails a PDF for commission agreements to be signed. Commission agreements are types of Contracts.
The visualforce page itself is pretty simple, it has a "email to:" field as well a drop list called "Contract Project Title" (project title is a custom field). This drop list is populated via my apex controller with Contracts that have Commission Agreements as the record type.
What I want to do is that whenever a user selects a contract from the drop list, have the apex page be updated with details of the Contract, so that they would be certain that they chose the correct Contract without having to go to its page and look at the details. It would be best if that happened without having to click a button, but thats not a necessary functionality.
You want to use an <apex:actionSupport> tag along with your picklist:
<apex:selectList value="{!someVar}">
<apex:selectOptions value="{!options}"/>
<apex:actionSupport action="{!LoadContact}" rerender="theContactInfo" event="onchange"/>
</apex:selectList>
<apex:outputPanel id="theContactInfo">
<!-- Display your contact info here -->
</apex:outputPanel>
LoadContact is an action in your controller which loads the details for the contact selected in the drop down.

Resources