8

The when values must be literals, so you cannot use String.valueOf as demonstrated in your second example. That said, using String.valueOf is approximately 10% more efficient when using literal string values: Long t3, t2, t1 = datetime.now().gettime(); for(Integer i = 0; i < 100000; i++) { sobjecttype a = account.sobjecttype; switch on a....


4

From the sObjectType object, use the newSobject method to create a new record in memory. It accepts a single optional parameter for the record Id: targetSObject = new sor.getSObjectType().newSobject(sObjectID); As an aside, if you already know the Id, you don't need the describe: targetSObject = sObjectID.getSobjectType().newSobject(sObjectID); Also, you ...


3

The alternative solution (for now) would be: static void myMethod(SObjectType t) { switch on t.newSobject() { when Claim__c claim { xyzForClaims(); } when Account account { xyzForAccounts(); } when Contact contact { xyzForContacts(); } ... } } It is possible that the sObjectType (and others) will be supported in the future, so make sure ...


1

This is a documented limit on SOQL parent-child queries: No more than 20 parent-to-child relationships can be specified in a query. You'll have to batch your queries in groups of 20 parent-child relationships.


1

You need : getRelationshipName() in this part of code (it may not worked for you, because you haven't checked it for null value): for (Schema.ChildRelationship cr: obj.getChildRelationships()) { if (cr.getRelationshipName() == null) continue; system.debug('Child Object Relationship Name:'+cr.getRelationshipName()); query = query + '(select Id ...


Only top voted, non community-wiki answers of a minimum length are eligible