Giter Site home page Giter Site logo

jongpie / apexuuid Goto Github PK

View Code? Open in Web Editor NEW
65.0 8.0 23.0 55.27 MB

A small library to provide UUID generation and validation in Apex

License: MIT License

Apex 99.22% Shell 0.78%
salesforce apex forcedotcom apex-uuid apex-guid uuid guid uuid4

apexuuid's People

Contributors

jongpie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apexuuid's Issues

Chaining Sobjects to insert with single DML statement

Hello,
Great class!
I have been testing its implementation to chain creation of sObjects in one DML statement using an External ID and followed your documentation example with Account and Contact but my attempts are generating a DML exception.

static void testInsertChainedSObjectsInOneDML() {
        Exception dmlex;
        List<SObject> recordsToCreate = new List<SObject>();
        // Create 10 sample accounts
        for (Integer accountCount = 0; accountCount < 10; accountCount++) {
            // Create a new account & set a custom external ID text field called UUID__c
            Account newAccount = new Account(
                Name    = 'Account ' + accountCount,
                UUID__c = new UUID().getValue()
            );
            recordsToCreate.add(newAccount);

            // For each sample account, create 10 sample contacts
            for (Integer contactCount = 0; contactCount < 10; contactCount++) {
                // Instead of setting contact.AccountId with a Salesforce ID...
                // we can use an Account object with a UUID__c value to set the Contact-Account relationship
                Contact newContact = new Contact(
                    Account  = new Account(UUID__c = newAccount.UUID__c),
                    LastName = 'Contact ' + contactCount
                );
                recordsToCreate.add(newContact);
            }
        }
        // Sort so that the accounts are created before contacts (accounts are the parent object)
        recordsToCreate.sort();
        try {
            insert recordsToCreate;
        } catch(DMLException ex) {
            dmlex = ex;
        }
        System.assertEquals(null, dmlex, 'Expected no DML exception when chaining insert with UUID as external ID');
        // Verify that we only used 1 DML statement
        // System.assertEquals(1, Limits.getDmlStatements(), 'Expected only one DML statement');
    }

UUIDTest.testInsertChainedSObjectsInOneDML System.AssertException: Assertion Failed: Expected no DML exception when chaining insert with UUID as external ID: Expected: null, Actual: System.DmlException: Insert failed. First exception on row 10; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [UUID__c]: [UUID__c]

It works if I insert in separate DMLs the lists I gathered for each sObject type, but, not with single one.
Any ideas?

Add support for generating other versions of UUIDs

The current implementation of the code uses v4 of the UUID standard, which is still a very reliable manner of generating a randomized, unique ID. However, there are several newer versions of UUIDs, each with their own use cases. The specs for the newer versions aren't fully finalized, but seem to be I'd like to expand the current code to provide a way to specify which version of UUID is generated.

Some resources that discuss the differences & benefits of some of the new versions:

At the moment, I'm considering these versions:

  • Version 5 for consistently generated UUIDs: This version uses 2 inputs that will consistently produce the same UUID value when the same inputs are used
  • Version 7 for sortable UUIDs: This version uses an Epoch timestamp as part of the UUID generation, which results in the UUIDs being sortable based on when they were created

There are a few other official & unofficial versions, but these seem like the most useful ones to focus on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.