Code snippets

Some useful execute anoymous code snippets


Set Password

Sets the users password as desired without having to reset in UI.


System.setPassword('userid', 'strongpassword')


GetRelationship Plural Name

Useful for determining master detail relationship names for use in SOQL queries.

public static void GetRelationship(string whatObject){

SObjectType objectType = Schema.getGlobalDescribe().get(whatObject); Schema.DescribeSObjectResult R = objectType.getDescribe(); List C = R.getChildRelationships(); for(Schema.ChildRelationship cr : C){ if(!String.isBlank(cr.getRelationshipName())) System.debug('OName: ' + cr.getChildSObject().getDescribe().name + ' Rname: ' +cr.getRelationshipName()); } }

End