function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sumant HegdeSumant Hegde 

Creating web form to insert records in custom objects

Hi All,

I have a requirment to create Web Form to get the details from new customer and update a custom object in salesforce platform. 

I have created a VF page and a custom controller which can do this. But I want that form (VF page) to be available to the customer who access our main website. i.e., Customer should navigate to this form from our main WEBSITE, not through salesforce.

How can I achieve that? 
Prashant Pandey07Prashant Pandey07
Hi Sumant,

What is the platform are you using for your main website..?

If the website platform is other than salesforce you do not directly create the records in salesforce..until your integrate both the platform.

Workaround:
You can create a public visualforce page and embed in your website and give access to your class visualforce and object to external users.
To do this you need a community or site license.

https://help.salesforce.com/articleView?id=users_license_types_sites.htm&type=5
--
Thanks,
Prashant
Sumant HegdeSumant Hegde
Hi Prashant,

Thanks for your suggestion. I have created a vf page and added it to a site that I have created to make a public vf page .

The issue is that if I open the public url, it is only showing the lables but not the text boxes. Does it have anything to do with permission?
Because when I open the vf page from salesforce then I am able to see those text boxes, but not on the public URL.

Below is the public URL I created to test this functionality.
https://webformtrial-developer-edition.na72.force.com/createCase

I am trying to make a form in this vf page and embed this public URL into my website, so that new users can use this link to register. 
Can you suggest me on this?

Thanks,
Sumant
Prashant Pandey07Prashant Pandey07
are you using <apex:inputfield> tag?

Did give field access to site guest user profile..

Also, can you show me your vf code..
--
Thanks,
Prashant
Sumant HegdeSumant Hegde
this is my vf code

<apex:page controller="SubmitCaseController">

    <h1>Register</h1>
    
    <apex:form >
        <apex:pageMessages />
        <table>
            <tr>
                <th>Issue Summary:</th>
                <td><apex:inputText required="true" value="{!c.Issue_Summary__c}"/></td>
            </tr>
            <tr>
                <th>Type of Issue:</th>
                <td><apex:inputText required="true" value="{!c.Type_of_Issue__c}"/></td>
            </tr>
             <tr>
                <th>Issue Description:</th>
                <td><apex:inputTextarea required="true"/></td>
            </tr>
            <tr>
                <th>Your Email:</th>
                <td><apex:inputText required="true" value="{!c.Email_ID_to_receive_notification__c}"/></td>
            </tr>
           
            <tr>
                <td><apex:commandButton value="Submit" action="{!submitCase}"/></td>
            </tr>
        </table>
    </apex:form>

</apex:page>
Prashant Pandey07Prashant Pandey07
You can use the input field and just give access to fields to site guest user..
--
Thanks,
Prashant
 
Sumant HegdeSumant Hegde
Where should I find the option to change the field access to site guest user? I couldn't find it.
Prashant Pandey07Prashant Pandey07
Go to Site and Click on site label.

You will see a button called Public access setting and just click on that..and you can see a site guest profile there you need to give access to the object and related fields.

--
Thanks,
Prashant

 
Sumant HegdeSumant Hegde
I found out the issue. Even though all the field-level access were there, the reason for not displaying those values was because the "value" attribute that I used in "apex:inputText" tags.

but if I don't use "value" attribute then I cannot add those values to my custom object.
I will have to figure out the solution for this. Please let me know if you have any other solution for this situation.
 
Prashant Pandey07Prashant Pandey07
No...as mentioned earlier why don't you use apex:inputfield tag instrad of apex:inputtext

--
Thanks,
Prashant 
Sumant HegdeSumant Hegde
I tried inputfield also. The issue is same.
below code has both inputfield and inputtext.

Here is the public link
http://webformtrial-developer-edition.na72.force.com/RegisterNew

You can see the difference.


<apex:page controller="SubmitCaseController">

    <h1>Register</h1>
    
    <apex:form >
        <apex:pageMessages />
        <table>
            <tr>
                <th>Issue Summary:</th>
                <td><apex:inputField required="true" value="{!c.Issue_Summary__c}"/></td>
            </tr>
            <tr>
                <th>Type of Issue:</th>
                <td><apex:inputText required="true"/></td>
            </tr>
             <tr>
                <th>Issue Description:</th>
                <td><apex:inputTextarea required="true"/></td>
            </tr>
            <tr>
                <th>Your Email:</th>
                <td><apex:inputText required="true"/></td>
            </tr>
           
            <tr>
                <td><apex:commandButton value="Submit" action="{!submitCase}"/></td>
            </tr>
        </table>
    </apex:form>

</apex:page>





 
Prashant Pandey07Prashant Pandey07
I am unbale to access your community page..

 
@@@we@@@@@@we@@@
give your page public or home page in Site, url link  open     
 public access object  setting-> field if field   not show
 
Sumant HegdeSumant Hegde
Hi Prashant,

Can you try to access the page now.
Prashant Pandey07Prashant Pandey07
Yes...I can the page and text box too..

I hope your problem is solved.
--
Thanks,
Prashant
 
Sumant HegdeSumant Hegde
No. Problem is not resolved. 
                <td><apex:inputField required="true" value="{!c.Issue_Summary__c}"/></td>

the above field is not visible and rest of the inputtext doesn't have "value" attribute. So I cant read the value of those text boxes in my controller.
Sumant HegdeSumant Hegde
The issue is, whenever I use the "value" attribute in any tag (be it "inputfield" or "inputtext"), the text box or picklist won't be visible.
Prashant Pandey07Prashant Pandey07
Send me your controller and page..will try to resolve and send you the code..

--
Thanks,
Prashant

 
Sumant HegdeSumant Hegde
Hi Prashant,

If I use the String to store the input value and then assign that value to the field of the custom object in the controller, then it is working.
I am not sure if that is the best way to do it or not, but for now I am proceeding with that approach. Let me know if you have any suggestions for this.

I have pasted the sample of working code below.

----------------VFP-------------------------------
<apex:page controller="RegistrationClass" >
    <apex:form >       
        <apex:pageMessages />
        <table>
            <tr>
                <th>First Name:</th>
                <td><apex:inputText value="{!firstName}"/></td>
            </tr>
            <tr>
                <th>Last Name:</th>
                <td><apex:inputText value="{!lastName}"/></td>
            </tr>            
            <tr>
                <td><apex:commandButton value="Submit" action="{!register}"/></td>
            </tr>            
        </table>
    </apex:form>

</apex:page>


------------Controller-----------------------
public class RegistrationClass {
    public Registration__c reg{get ; set; }
    public String firstName{get;set;}
    public String lastName {get;set;}
    
    public RegistrationClass() {
        reg = new Registration__c();              
    }
    
    public PageReference register() {
            try {
                reg.First_Name__c = firstName;
                reg.Last_Name__c = lastName;
              
                Database.DMLOptions dmlOpts = new Database.DMLOptions();
                dmlOpts.assignmentRuleHeader.useDefaultRule = true;
                reg.setOptions(dmlOpts);
                insert reg;
                return new PageReference('/Thanks');
            } catch (Exception e) {
                ApexPages.addMessages(e);
                return null;
            }
    }



Thanks