I have two instances of one custom object and want to compare all of their fields to make sure they are exactly the same. I have the code below:
CustomObject__c validCustomObject = new CustomObject__c(...); CustomObject__c queriedCustomObject = [SELECT ... FROM CustomObject__c WHERE Name validCustomObject.Name]; System.assertEquals(validCustomObject, queriedCustomObject);
But the assertion fails. I have confirmed that the two variables have exactly the same fields and ids and want to find a way to compare them. I can build an equals() method but is there such a method for sObjects so I don't need to implement it myself?