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

ASP.NET with VB.NET CASE creation

I am creating a new case with the API in ASP.NET with VB.NET, got this to work.  I would like to set the recordType to one of three types I have setup in SFDC.  But with my Case object the recordType can only be set to a sforce.recordType, Error    1    Value of type 'String' cannot be converted to 'sforce.RecordType'.    How do you set the record type of a new case with the API?

Message Edited by scottskiblack on 05-01-2007 02:35 PM

Got it by creating a function to query for the recordTypeId then set the case's recordTypeId to the result.

   Public Function GetRecordTypeID() As String
        ' query for the recordtype to set it
        Dim recordtypeId As String = Nothing

        Dim qStr As String = "Select Id, Name, SobjectType from RecordType where Name='SFDC Requests Record Type'"
        Dim qr As QueryResult

            qr = binding.query(qStr)
        Catch ex As Exception
            Throw New Exception(ex.Message & vbCrLf & ex.StackTrace)
        End Try

        Dim records() As sforce.sObject
        records = qr.records

        ' process the query result
        If (Not qr Is Nothing) Then
            'we can loop through the returned records
            For i As Integer = 0 To records.GetUpperBound(0)
                'While (Not qr.records Is Nothing)
                'Because we asked for contacts we will convert
                'the SObject for each record into an Contact object
                Dim record As sforce.RecordType = CType(records(i), sforce.RecordType)
                'Now we can access any of the fields we had in the query
                'select clause directly from the contact variable
                recordtypeId = record.Id
                'End While
        End If
        Return recordtypeId
    End Function
set the case RecordTypeId, not the case RecordType, and you can do this at case creation.
if c is your case object,
c.RecordTypeId = "001001001001X";
Or you could add a dropdown list to your page, that lists all the available record types, and set the value of each item to be the RecordTypeId, and then when you create your case,
c.RecordTypeId = lstRecTypes.SelectedValue;
I am not sure what the syntax difference is for VB.NET, but it should carry over easy.
Case c = new Case();
c.RecordTypeId = "0123456789101112" //your record type id here
c.OwnerId = "012345678910112" //your owner or Queue Id here
c.Subject = "Case Subject Line Here";
c.Priority = "Case Priority Setting";
sObject[] records = new sObject[] { c };
SaveResult[] saveResults = YourBindingObjectName.create(records);

you can do this with all fields.