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
CatamaransCatamarans 

Web To Custom Object?

How complex would this be...has this been achieved by anybody?
 
Thanks
Jason
Tran ManTran Man
Sure it can be done and is done all the time via the API.  It is known as Web2X.  The JSP Samples found under Projects & Toolkits has an example of Web2Leads done in a JSP.  There shouldn't be any difference in the way one persists a web form to a standard or custom object.

Message Edited by Tran Man on 06-07-2006 01:38 PM

CatamaransCatamarans

Nick, would it at all be possible to get a full example of how this works at basic level even if it is just to populate one <field> in one <custom> object.

I come from an ASP background and I am still learning the .NET architecture. I realise there are numerous eg: .net login examples but a fully threaded example would be a huge starter leap for me and I am sure others.

One of the things I am struggling with is how to mix the .net eg grid controls with the sfdc code....

Would you be able to provide a sample INSERT example from start to finish in perhaps .ASP net.

Any further progress I make on the app I will post back to help other newbies.

Thanks

Jason

DevAngelDevAngel
Hi Catamarans,

Although I have been doing asp development for many years now (over 7), I am not fully up to speed on ASP .NET 2.0.  But, I have built and demo'd at AppExchange seminars an ASP .NET web to custom object solution.

It feels like as ASP .NET progresses you get more locked into a particular pattern of developing web pages that varies from release to release.  In the latest version, for instance, you can create data bound forms for displaying data as well as entering and editing data.  This works pretty well with a database and is not entirely new.  What is new is that you can use a local web service as a datasource for both read/write data bound forms. 

In the solution that I came up with, I just create a local web service that actually calls the AppExchange web service to provide records and to update and create records.  It works pretty well and you can bind this to the widgets that .NET provides. For instance, in my app I have a custom object called candidates and I want to create that object using a form on an ASP .NET web site.

I created the following local web service:

Code:

<WebMethod()> _
    Public Function CreateCandidate(ByVal Current_Employer__c As String, ByVal Currently_Employed__c As Boolean, _
            ByVal Education__c As String, ByVal Name As String, _
            ByVal US_Citizen__c As Boolean, ByVal Visa_Required__c As Boolean, _
            ByVal Years_of_Relevant_Experience__c As Integer) As String
        Dim c As New sforce.Candidate__c()
        c.Current_Employer__c = Current_Employer__c
        c.Currently_Employed__c = Currently_Employed__c
        c.Currently_Employed__cSpecified = True
        c.Education__c = Education__c
        c.Name = Name
        c.citizenship__c = US_Citizen__c
        c.citizenship__cSpecified = True
        c.Visa_Required__c = Visa_Required__c
        c.Visa_Required__cSpecified = True
        c.Years_of_Relevant_Experience__c = Years_of_Relevant_Experience__c
        c.Years_of_Relevant_Experience__cSpecified = True
        Dim sr As sforce.SaveResult = Utils.Binding.create(New sforce.Candidate__c() {c})(0)
        If (sr.success) Then
            Return sr.id
        Else
            Return Nothing
        End If
    End Function


 
This local web service is used as the datasource for form databinding.

Code:

        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="CreateCandidate"
            SelectMethod="GetCandidate" TypeName="LocalSforceWebservice">
            <InsertParameters>
                <asp:Parameter Name="Current_Employer__c" Type="String" />
                <asp:Parameter Name="Currently_Employed__c" Type="Boolean" />
                <asp:Parameter Name="Education__c" Type="String" />
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Total_Years_Employed__c" Type="Int32" />
                <asp:Parameter Name="US_Citizen__c" Type="String" />
                <asp:Parameter Name="Visa_Required__c" Type="Boolean" />
                <asp:Parameter Name="Years_at_Latest_Position__c" Type="Int32" />
                <asp:Parameter Name="Years_of_Relevant_Experience__c" Type="Int32" />
            </InsertParameters>
            <SelectParameters>
                <asp:FormParameter DefaultValue="null" FormField="Name" Name="name" Type="String" />
                <asp:FormParameter DefaultValue="null" FormField="PIN" Name="pin" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>


 

Then later in the page, the datasource is bound to the input elements:

Code:

                        <InsertItemTemplate>
                            <table style="position: relative; text-align: center;" cellpadding="4">
                                <tr style="background-color: #f5f5f5;">
                                    <td align="right" style="width: 180px">
                                        <b>Name:</b></td>
                                    <td style="text-align: left;">
                                        <asp:TextBox ID="Name" Text='<%# Bind("Name") %>' runat="Server" Width="257px" />&nbsp;&nbsp;PIN&nbsp;<asp:TextBox
                                            ID="PIN" ToolTip="Enter a 4 digit pin to auto-fill this form." runat="server" MaxLength="4" Width="41px"></asp:TextBox>&nbsp;&nbsp;<asp:Button ID="search" Text="Get Profile" runat="server" OnClick="search_Click" /></td>
                                </tr>
                                <tr>
                                    <td align="right" style="width: 180px">
                                        <b>Current Employer:</b></td>
                                    <td style="text-align: left;">
                                        <asp:TextBox ID="InsertLastNameTextBox" Text='<%# Bind("Current_Employer__c") %>'
                                            runat="Server" Width="257px" /></td>
                                </tr>
                                <tr style="background-color: #f5f5f5;">
                                    <td align="right" style="width: 180px">
                                        <b>Currently Employed:</b></td>
                                    <td style="text-align: left">
                                        <asp:CheckBox ID="Currently_Employed" Checked='<%# Bind("Currently_Employed__c") %>'
                                            runat="Server" /></td>
                                </tr>
                                <tr>
                                    <td align="right" style="height: 18px; width: 180px" valign="top">
                                        <b>Education:</b></td>
                                    <td style="height: 18px; text-align: left;">
                                        <asp:TextBox ID="Education" Text='<%# Bind("Education__c") %>' runat="Server" Height="62px"
                                            Width="505px" /></td>
                                </tr>
                                <tr style="background-color: #f5f5f5;">
                                    <td align="right" style="width: 180px">
                                        <b>Total Years Employed:</b></td>
                                    <td style="text-align: left">
                                        <asp:DropDownList runat="server" ID="DropDownList1" ></asp:DropDownList>
                                        <asp:HiddenField runat="server" ID="DropDownData1" Value='<%# Bind("Total_Years_Employed__c") %>' />
                                </tr>
                                <tr>
                                    <td align="right" style="width: 180px">
                                        <b>US Citizen:</b></td>
                                    <td style="text-align: left">
                                        <asp:TextBox ID="TextBox4" Text='<%# Bind("US_Citizen__c") %>' runat="Server" /></td>
                                </tr>
                                <tr style="background-color: #f5f5f5;">
                                    <td align="right" style="width: 180px">
                                        <b>Visa Required:</b></td>
                                    <td style="text-align: left">
                                        <asp:CheckBox ID="CheckBox1" Checked='<%# Bind("Visa_Required__c") %>' runat="Server" /></td>
                                </tr>
                                <tr>
                                    <td align="right" style="width: 180px">
                                        <b>Years at Latest Position:</b></td>
                                    <td style="text-align: left">
                                        <asp:DropDownList runat="server" ID="DropDownList2" ></asp:DropDownList>
                                        <asp:HiddenField runat="server" ID="DropDownData2" Value='<%# Bind("Years_at_Latest_Position__c") %>' />
                                </tr>
                                <tr style="background-color: #f5f5f5;">
                                    <td align="right" style="width: 180px">
                                        <b>Years of Relevant Experience:</b></td>
                                    <td style="text-align: left">
                                        <asp:DropDownList runat="server" ID="DropDownList3" ></asp:DropDownList>
                                        <asp:HiddenField runat="server" ID="DropDownData3" Value='<%# Bind("Years_of_Relevant_Experience__c") %>' />
                                </tr>
                                <tr>
                                    <td align="right" style="width: 180px" valign="top">
                                        <b>Comments:</b></td>
                                    <td style="text-align: left">
                                        <asp:TextBox  ID="Comments" runat="server" Height="65px" Width="500px"></asp:TextBox>
                                    </td>
                                </tr>

                                <tr style="background-color: #f5f5f5;">
                                    <td colspan="2">
                                        Include Resume:
                                        <asp:FileUpload ID="FileUpload1" runat="server" />
                                        <asp:LinkButton ID="InsertButton" Text="Apply" CommandName="Insert" runat="server" />
                                        &nbsp;
                                        <asp:LinkButton ID="CancelInsertButton" Text="Cancel" CommandName="Cancel" runat="server" />
                                    </td>
                                </tr>
                            </table>
                        </InsertItemTemplate>


 

The full Utils class is shown below:

Code:

Imports Microsoft.VisualBasic
Imports sforce
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

Public Class Utils
    Inherits System.Web.Services.WebService

    Private Shared _binding As New sforce.SforceService()
    Private Shared nextLogin As Date = Date.Now

    Public Shared ReadOnly Property Binding() As sforce.SforceService
        Get
            CheckLogin()
            Return _binding
        End Get
    End Property
    Private Shared Sub CheckLogin()
        If _binding Is Nothing Then
            _binding = New sforce.SforceService
        End If

        Dim doLogin = False
        If _binding.SessionHeaderValue Is Nothing Then
            doLogin = True
        ElseIf nextLogin < Now Then
            doLogin = True
        End If

        If doLogin Then
            _binding.Url = "https://www.salesforce.com/services/Soap/c/7.0"
            Dim lr As sforce.LoginResult = _binding.login("username", "password")
            _binding.SessionHeaderValue = New sforce.SessionHeader()
            _binding.SessionHeaderValue.sessionId = lr.sessionId
            _binding.Url = lr.serverUrl
            nextLogin = Now.AddMinutes(60.0)
        End If
    End Sub

End Class


 

Message Edited by DevAngel on 07-20-2006 10:17 AM