Hot answers tagged

6

Salesforce has a governor limits! In a single apex execution context, you can only do 150 DML operations. Being a beginner to apex I suggest you read through some of the best practices highlighted here Instead of doing DML in a loop, use List to collect all objects and perform one DML instead. @isTest public static void testScenario(){ List<Account&...


3

The maximum length of User.Alias (8) is significantly shorter than the maximum length of ContactFirstName (40). You need to truncate to fit. Often the String.abbreviate method is most convenient for this purpose, but for Alias you should probably prefer substring. Your code should look something like: String alias = con.firstName; if (alias.length() > 8) ...


2

The base SObject API, extended by all the specific object types, does not include the Name property since not every single SObject in Salesforce has a Name (though most do). You have two choices here: Continue treating the returned data as SObject and use the SObject.get() function to read a named field, like you do in the second example. Treat the result ...


2

That would look like this: public class RecordClass { Integer id; String name; Date start; Date end; String status; Record[] records; } public class Record { RecordClass record; } Unfortunately, end is a reserved keyword. If you can change the properties to something like startDate and endDate, then these two classes would work. ...


1

As I explain in depth in this answer, the state of the record in memory has nothing to do with the state of the record in the database. When you perform an operation in a trigger, and you're testing this in your class, you need to remember to query the records back afterwards to check for changes. Campaign camp = new Campaign(); camp.Name = 'test'; ...


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