Apex introduction Flashcards
Apex is a strongly-typed programming language. What is a strongly-typed programming language?
Strong vs weak
The opposite of “strongly typed” is “weakly typed”, which means you can work around the type system. C is notoriously weakly typed because any pointer type is convertible to any other pointer type simply by casting. Pascal was intended to be strongly typed, but an oversight in the design (untagged variant records) introduced a loophole into the type system, so technically it is weakly typed. Examples of truly strongly typed languages include CLU, Standard ML, and Haskell. Standard ML has in fact undergone several revisions to remove loopholes in the type system that were discovered after the language was widely deployed.
What’s really going on here?
Overall, it turns out to be not that useful to talk about “strong” and “weak”. Whether a type system has a loophole is less important than the exact number and nature of the loopholes, how likely they are to come up in practice, and what are the consequences of exploiting a loophole. In practice, it’s best to avoid the terms “strong” and “weak” altogether, because
Amateurs often conflate them with “static” and “dynamic”.
Apparently “weak typing” is used by some persons to talk about the relative prevalance or absence of implicit conversions.
Professionals can’t agree on exactly what the terms mean.
Overall you are unlikely to inform or enlighten your audience.
The sad truth is that when it comes to type systems, “strong” and “weak” don’t have a universally agreed on technical meaning. If you want to discuss the relative strength of type systems, it is better to discuss exactly what guarantees are and are not provided. For example, a good question to ask is this: “is every value of a given type (or class) guaranteed to have been created by calling one of that type’s constructors?” In C the answer is no. In CLU, F#, and Haskell it is yes. For C++ I am not sure—I would like to know.
What does Anonymous Block allow you to do?
Anonymous Blocks
The Developer Console allows you to execute code statements on the fly. You can quickly evaluate the results in the
Logs panel. The code that you execute in the Developer Console is referred to as an anonymous block. Anonymous
blocks run as the current user and can fail to compile if the code violates the user’s object- and field-level permissions.
Note that this not the case for Apex classes and triggers.
What is a class referred to in the coding world?
Sometimes
referred to as blueprints or templates for objects.
Describe what the exact code below is:
public static void sayYou() {
System.debug( ‘You’ );
}
A public static method
Describe what the exact code below is:
public void sayMe() {
System.debug( ‘Me’ );
}
An instance method
Write the code that will call the static method below: public class helloworld(){ public static void sayYou() { System.debug( 'You' ); }
HelloWorld.sayYou();
The class does not need to be instantiated for a static method.
Write the code that will call the static method below: public class helloworld(){ public void sayMe() { System.debug( 'Me' ); } }
HelloWorld hw = new HelloWorld(); hw.sayMe();
Describe what the exact code below is:
public static string helloMessage() {
return(‘You say “Goodbye,” I say “Hello”’);
}
A public static data type
What is a string in Apex?
A primitive data type
Strings are set of characters and are enclosed in single quotes.
They store text values such as a name or an address.
Write a method that does not return any value but will pass a string data type as an argument
public static void processString(String s) {
s = ‘Modified value’;
}
What is a Boolean?
Boolean values hold true or false values and you can use them to test whether a certain condition is true or false.
What are Time, Date and Datetime?
Variables declared with any of these data types hold time, date, or time and date values combined.
What are the four kinds of variables to hold numeric values?
Integer
Long
Double
Decimal
What is a variable that you don’t assign a value to?
Null Variables and Initial Values
If you declare a variable and don’t initialize it with a value, it will be null. In essence, null means the absence of a value.
You can also assign null to any variable declared with a primitive type. For example, both of these statements result in a
variable set to null:
Boolean x = null;
Decimal d;
Many instance methods on the data type will fail if the variable is null. In this example, the second statement generates an
exception (NullPointerException)
What is an Enum?
An enumeration of constant values.
Write the code so that a Date data type has a variable called MyDate and is assigned the value of today. Then write another line of code that will retreive todays date as a string. Write a debug statement to call the string extraction variable and add the text before it “today’s date is “.
Date myDate = Date.today();
String myString = String.valueOf(myDate);
System.debug(myString);
2012-03-15
What will be the output from the debug statement?
String x = 'I am a string'; String y = 'I AM A STRING'; String z = 'Hello!'; System.debug (x == y); System.debug (x != z);
True
True
Apex code is limited by the number of operations
(such as DML or SOQL) that it can perform within one process.
How records can an apex request collection return?
All Apex requests return a collection that contains from 1 to 50,000 records
Why must you bulkify your code
Because you cannot assume that your code will be handling one record at a time. Eg a User inserting 1000 contacts
What is Visualforce?
Visualforce consists of a tag-based markup language that gives developers a more powerful way of building applications and customizing the Salesforce user interface.
Provide some examples of what you can do with Visualforce
- Build wizards and other multistep processes.
- Create your own custom flow control through an application.
- Define navigation patterns and data-specific rules for optimal, efficient application interaction.
How is Apex compiled, stored, and run entirely on the Force.com platform?
When a developer writes and saves Apex code to the platform, the platform application server first compiles the code into an
abstract set of instructions that can be understood by the Apex runtime interpreter, and then saves those instructions as
metadata.
When an end-user triggers the execution of Apex, perhaps by clicking a button or accessing a Visualforce page, the platform
application server retrieves the compiled instructions from the metadata and sends them through the runtime interpreter before
returning the result. The end-user observes no differences in execution time from standard platform requests.
Apex is not a general purpose programming language. What can’t you do with apex?
Apex cannot be used to:
• Render elements in the user interface other than error messages
• Change standard functionality—Apex can only prevent the functionality from happening, or add additional functionality
• Create temporary files
• Spawn threads
Describe what the statement below is doing:
Account[] accs;
Declaring a variable