Generate test data in test classes sometimes consume a lot of time; therefore, developers tend to use uninformative data in test classes like ‘test test’, ‘test@test.test’. To generate the real data in the test class not only to make the data more informative but also the tests are correct in the business case.

I wrote this package for personal use quite some time ago; now, I packaged to share with you. I hope this will speed up your development process. Once the methods are generated, you can modify them for your own need.


https://login.salesforce.com/packaging/installPackage.apexp?p0=04t2x000002gQ3j

Once you installed the app, navigate to Generate Data Factory App, you can find the Generate Datafactory tab.

How To Use?

  • Get the ID of the record you want to generate, then paste it into the text box then click Go.
  • The app will generate all the populated fields of the records; It also generates methods for lookup/master-detail. So Generate from child record will also give you the method to generate the parent
  • For Example, I put the contact Id : 0032x000002qw7NAAQ name Green Avi into the Text Box. Then I will have the below results.
public static Account createAccount(){
        Account createNewAccount = new Account();
        createNewAccount.Name = 'United Oil & Gas Corp.' ;
        createNewAccount.Type = 'Customer - Direct' ;
        createNewAccount.BillingStreet = '1301 Avenue of the Americas \r\nNew York, NY 10019\r\nUSA' ;
        createNewAccount.BillingCity = 'New York' ;
        createNewAccount.BillingState = 'NY' ;
        createNewAccount.ShippingStreet = '1301 Avenue of the Americas \r\nNew York, NY 10019\r\nUSA' ;
        createNewAccount.Phone = '(212) 842-5500' ;
        createNewAccount.Fax = '(212) 842-5501' ;
        createNewAccount.AccountNumber = 'CD355118' ;
        createNewAccount.Website = 'http://www.uos.com' ;
        createNewAccount.Sic = '4437' ;
        createNewAccount.Industry = 'Energy' ;
        createNewAccount.AnnualRevenue = 5600000000 ;
        createNewAccount.NumberOfEmployees = 145000 ;
        createNewAccount.Ownership = 'Public' ;
        createNewAccount.TickerSymbol = 'UOS' ;
        createNewAccount.Description = 'World's third largest oil and gas company.' ;
        createNewAccount.Rating = 'Hot' ;
        createNewAccount.CleanStatus = 'Pending' ;
        createNewAccount.WBCDF__CustomerPriority__c = 'High' ;
        createNewAccount.WBCDF__SLA__c = 'Platinum' ;
        createNewAccount.WBCDF__Active__c = 'Yes' ;
        createNewAccount.WBCDF__NumberofLocations__c = 955 ;
        createNewAccount.WBCDF__UpsellOpportunity__c = 'Yes' ;
        createNewAccount.WBCDF__SLASerialNumber__c = '6654' ;
        createNewAccount.WBCDF__SLAExpirationDate__c = (Date)JSON.deserialize('"2020-12-16"',Date.Class) ;
        insert createNewAccount;
        return createNewAccount;
}


public static Contact createContact(){
        Contact createNewContact = new Contact();
        createNewContact.AccountId = createAccount().Id ;
        createNewContact.LastName = 'Green' ;
        createNewContact.FirstName = 'Avi' ;
        createNewContact.Salutation = 'Mr.' ;
        createNewContact.MailingStreet = '1302 Avenue of the Americas \nNew York, NY 10019\nUSA' ;
        createNewContact.Phone = '(212) 842-5500' ;
        createNewContact.Fax = '(212) 842-5501' ;
        createNewContact.MobilePhone = '(212) 842-2383' ;
        createNewContact.AssistantPhone = '(212) 842-5428' ;
        createNewContact.Email = 'agreen@uog.com' ;
        createNewContact.Title = 'CFO' ;
        createNewContact.Department = 'Finance' ;
        createNewContact.AssistantName = 'Chris Nobel' ;
        createNewContact.LeadSource = 'Public Relations' ;
        createNewContact.Birthdate = (Date)JSON.deserialize('"1933-12-01"',Date.Class) ;
        createNewContact.CleanStatus = 'Pending' ;
        createNewContact.WBCDF__Level__c = 'Primary' ;
        createNewContact.WBCDF__Languages__c = 'English' ;
        insert createNewContact;
        return createNewContact;
}



Let me know if you have any questions!! Happy Coding!!!