0
votes

I want to migrate Lotus Notes database to salesforce. using domingo I am able to retrieve the forms , form fields ,documents and etc. As soon as I get the form with its fields & their datatypes, I want to create a class for this form. Like this I want to create a class for each form. Each document can then be made as an instance to this class. I am looping the database to get forms and then looping forms to get their fields(using for loops), now is there a way to create a class for this form right in this for loop dynamically so that each form can be exposed as a class. Please kindly help

5
Just clarify something please:would you like to see generated code for each form.e.g. if you have two forms Memo and Appointment are you saying you want to create two Java classes with e.g. Memo.java and Appointment.java with with form fields as Class properties e.g. field From of data type Text in notes becomes property private String from .Thats quite easy if you want just that.Shahzeb
Yeah exaclty this is what I want, I am using for loops to iterate thru forms and then fields. Once I get a form then I wanna create a class and after iterating thru fields I populate them as class properties. Can you please guide me for achieving thisVikash Talanki

5 Answers

1
votes

This certainly is possible, but wouldn't it be better to use a data structure like nested maps/lists in this case? When you dynamically create classes, you also have to dynamically create the code that works with these classes, otherwise you do not gain anything over a generic data structure.

1
votes

I believe that it might be possible to do this via the Salesforce metadata API, but I haven't personally used that API yet. I've had people recommend it to me as a means for handling similar tasks.

I'd question the benefits of doing a migration so generically. Unless you have so many objects and fields to create that the simple task of object and field creation will take significant time, what's the advantage? Remember, you can get and set fields on Salesforce standard and custom objects without writing code to go with those objects (at least you can in Apex). Likewise, each object automatically gets a standard controller to handle display and standard operations.

You should ask yourself if your data and data model are clean enough to generate code from. Are you sure? Really really sure? What about that widget count field that got added to the shipment object back in 2005 to solve a reporting issue? Nobody uses it anymore. Still want it in your new db?

Both times I've migrated Notes databases to Salesforce, I've exported to CSV and someone else has loaded the data. The first export was just a simple export of contacts and accounts. The second time I wrote my own Lotusscript exporter since I needed to fix certain data problems before doing the Salesforce import. The second time the load was done with the data loader. If I was loading the data myself, I'd use Demand Tools. It's much more industrial-strength tool. The de-duplication features alone can save you writing a lot of custom code.

0
votes

I believe the word 'dynamically' is misleading in this case. Perhaps I am reading the question wrong, but it seems that the forms in question are of fixed format and the word 'dynamically' is used in place of the ability to instantiate an object of a given class (aka how Java and many other languages work).

That being said, I would agree with michael667 in that this is certainly possible. Converting Form data (View) to an in memory Object (Model) via code logic (Controller) is what I (and many MANY others) do as a day job. Keep MVC in mind while developing and you should be just fine.

0
votes

You will need to code this yourself by exporting Lotus Notes domino form elements as DXL and then translate that into you're own custom form objects for use with SalesForce.

0
votes

Code java skeleton classes creation what you are doing is correct. Below is my quick and untested version:

Sub Initialize  
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView   
    Dim views As Variant
    Dim notesToJavaFieldMap List As String  
    Dim doc As NotesDocument
    Dim count As Integer
    count = 0
    Dim formsAlreadyProcessed(count) As String
    Set db = session.CurrentDatabase

    views = db.Views
    Forall v In views
        If v.IsDefaultView Then
            Set view = v
            Exit Forall
        End If
    End Forall

    'Declare a complete on to one mapping here for all Notes item types to Java datatypes
    notesToJavaFieldMap(" RichText") = "String"
    notesToJavaFieldMap("Text") = "String"
    notesToJavaFieldMap("Time/Date") = "Date"

    Dim authorItem As NotesItem 
    Dim itemType As String
    Dim itemName As String
    Dim formName As String  
    Dim fileNum As Integer  
    Dim fileName As String

    Set doc = view.GetFirstDocument 
    While Not(doc Is Nothing)       
        fileNum% = Freefile()       
        If Arraygetindex(formsAlreadyProcessed,doc.form(0)) Is Not Null Then
            formsAlreadyProcessed(Ubound(formsAlreadyProcessed)) = doc.form(0)
            Redim Preserve formsAlreadyProcessed(Ubound(formsAlreadyProcessed) + 1)
            fileName$ = doc.form(0) +".java"        
            Open fileName$ For Output As fileNum%           

            Write #fileNum%, "package com.mypackage;"
            Write #fileNum%, "\n \r"
            Write #fileNum%, " public class " + fileName
            Write #fileNum%, "\n \r"

            Forall item In doc.Items
                itemType = item.type
                itemName = item.name                    
                Write #fileNum%, "private " +notesToJavaFieldMap(itemType) + " " +itemName
                Write #fileNum%, "\n \r"
            End Forall      
            Close fileNum%
        End If      
    Wend

End Sub

You can them open these class java files with an IDE like eclipse and import missing imports by going Ctrl+ O and generate get and sets as well.
For the data itself dump it out as cvs and export it in.

I did not have lotus notes designer with me so this code is not tested .