Wednesday, June 28, 2017

What are different Control Statements available in Apex?

What are different Control Statements available in Apex?


The control statement are used to control the flow of execution of the program . This execution order depends on the supplied data values and the conditional logic. Apex contains the following types of control statements:

  1. Selection Statements
  2. Repetition Statements
  3. Branching Statements 
Selection statements:
If

The if statement is apex conditional branch statement. It can be used to route program execution through two different paths. Here is the general form of the if statement:

if (condition) statement1;
else statement2;

Here, each statement may be a single statement or a compound statement enclosed in curly braces (that is, a block). The condition is any expression that returns a boolean value. The else clause is optional.

The if works like this: If the condition is true, then statement1 is executed. Otherwise, statement2 (if it exists) is executed. In no case will both statements be executed. For example, consider the following:
i
nt a, b;
// ...
if(a < b) a = 0;

else b = 0;


Nested ifs

A nested if is an if statement that is the target of another if or else. Nested ifs are very common
in programming. When you nest ifs, the main thing to remember is that an else statement always refers to the nearest if statement that is within the same block as the else and that is not already associated with an else. Here is an example:

if(i == 10) {
if(j < 20) a = b;
if(k > 100) c = d; // this if is
else a = c; // associated with this else
}
else a = d; // this else refers to if(i == 10)

The if-else-if Ladder

A common programming construct that is based upon a sequence of nested ifs is the if-else-if ladder. It looks like this:

if(condition)
statement;
else if(condition)
statement;
else if(condition)
statement;
...
else
statement;

The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed. The final else acts as a default condition; that is, if all other conditional tests fail, then the last else statement is performed. If there is no final else and all other conditions are false, then no action will take place.

Repetition Statements:

While Loops

The Apex while loop repeatedly executes a block of code as long as a particular Boolean condition remains true. Its syntax is:

while (condition) {
code_block
}

the while loop checks the Boolean condition statement before the first loop is executed. Consequently, it is possible for the code block to never execute. As an example, the following code outputs the numbers 1 - 10 into the debug log:

Integer count = 1;
while (count < 11) {
System.debug(count);
count++;
}

Do-While Loops

if the conditional expression controlling a while loop is initially false, then the body of the loop will not be executed at all. However, sometimes it is desirable to execute the body of a loop at least once, even if the conditional expression is false to begin with. The do-while loop always executes its body at least once, because its conditional expression is at the bottom of the loop.

do {
code_block
} while (condition);
Apex do-while loop does not check the Boolean condition statement until after the first loop is executed.Consequently, the code block always runs at least once.

As an example, the following code outputs the numbers 1 - 10 into the debug log:

Integer count = 1;
do {
System.debug(count);
count++;
} while (count < 11);

For

Here is the general form of the traditional for statement:
for(initialization; condition; iteration) {
// body
}

The for loop operates as follows. When the loop first starts, the initialization portion of the loop is executed. Generally, this is an expression that sets the value of the loop control variable, which acts as a counter that controls the loop. It is important to understand that the initialization expression is only executed once. Next, condition is evaluated. This must be a Boolean expression. It usually tests the loop control variable against a target value. If this expression is true, then the body of the loop is executed. If it is false, the loop terminates.Next, the iteration portion of the loop is executed. This is usually an expression that increments or decrements the loop control variable. The loop then iterates, first evaluating the conditional expression, then executing the body of the loop, and then executing the iteration expression with each pass. This process repeats until the controlling expression is false.

// Demonstrate the for loop.

class ForTick {
integer n;
for(int i=0; i<10; i++)
System.debug(‘I value is : ‘ + i);
}


The For-Each Version of the for Loop

The advantage of this approach is that no new keyword is required, and no preexisting code is broken. The for-each style of for is also referred to as the enhanced for loop. The general form of the for-each version of the for is shown here:

for(type itr-var : collection) statement-block

Here, type specifies the type and itr-var specifies the name of an iteration variable that will receive the elements from a collection, one at a time, from beginning to end. The collection being cycled through is specified by collection.

Integer[] myInts = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (Integer i : myInts) {
System.debug(i);
}

Branching Statements:

Return statements:

It is a special branching statement that  transfers the control to the caller of the method. This statement is used to return a value to the caller method and terminates execution of method. This has two forms: one that returns a value and the other that can not return. the returned value type must match the return type of  method. 

Syntax:  return;
 
return values;
return;   //This returns nothing. So this can be used when method is declared with void return type.
return expression;   //It returns the value evaluated from the expression.
Example: Here Welcome() function which returns a String value "Welcome to sfdcsrini.blogspot.com". This is printed to the screen.

static String Welcome(){
  return 'Welcome to sfdcsrini.blogspot.com';
}

What is cloud computing?


Cloud computing services are evolving like anything. Companies of all sizes are adapting to the cloud computing technology. Cloud technology could either be private or public. There are 3 models that are fundamentally used in cloud computing

1. Platform as a service 
2. Infrastructure as a service  
3. software as a service 

There is 99% chance that you as an individual have already used cloud computing. If you have an web based mail account hosted by gmail, yahoo, hotmail etc or if you have a facebook account, picasa account then you have already experienced cloud computing. Instead of storing the mails on your computer you store them some where else, you use a browser to connect to the Internet and access the mails.The software and storage for your account doesn't exist on your computer. It is with the cloud computing




service provider company. You as an user simply access the services in cloud with your computer and an interface software which could be a simple browser. But, in the back end there are various computers, servers and data storing systems that create the whole cloud computing system.

Moving to cloud means storing your data files on a remotely located servers, using web based application online not installed on your personal computer. The only thing you will need to access the services of cloud computing is the software Interface that connects you with  cloud computing services this could be a simple browser, rest of the things are taken care of by service providers network. 

With advancement in the cloud technology the applications of cloud computing are turning to be practically limitless. Cloud computing can execute all the programs you could run on your personal normal computer. Maintenance of cloud computing applications is easier, because they do not need to be installed on user's computer and can be accessed from any location.

Any cloud computing company generally has quite a large number of clients, thus they need to have a large amount of digital space to store all the client data. They have to also make sure they create duplicate copies of the data as a back up in case of any break down. Cloud computing service providers offer their services according to below 3 fundamental models:

1. Infrastructure As A Service (IaaS)
This is a raw model which includes offering storage and computing resources which can be used by software developers for building business solutions. IT organisations can deliver solutions for their clients using IAAS model. Cloud users can install their operating system and their applications on the cloud infrastructure.
Example of the companies that provide IAAS are amazon EC2, google compute engine, hp cloud

2. Platform As A Service (PaaS)
This model gives a computing platform on top of which you can build a application as desired. The platform can include operating system, programming language execution service, database and server. Service provider could offer a developer tool which can be used to build services or database services or data storage services on the provided platform. Developers can build an application on this platform without bothering about the underlying hardware and software layers.
Example of PAAS service providers are force.com, heroku, azure cloud services, google app engine.

3. Software As A Service (SaaS)
In this type of model the service provider gives a specific built

application and supporting database. We can say that the application or the software is hosted by provider and you don't have to install anything from your side. You have to just connect using internet to use the application service. An example of application service is CRM or ERP. SAAS delivers single application through the browser to number of customers using a multitenant architecture environment. Salesforce.com is a Best known example of SAAS, that provides CRM application built on force.com. Other examples of SAAS are google apps, microsoft office 365.















Advantages of cloud computing
1. As an user you don't store anything on your computer, so you are not bothered about installing anything or perhaps maintain anything personally.
2. Low cost. Maintenance cost, installation cost are reduced.
3. Easy access, you can access the services (applications and data) easily using software    interface like browser. You only need to be connected to the Internet.
4. Access data from anywhere irrespective of your location as long as you have a computer    and an Internet connection
5. Brings the hardware costs down
6. Clients can access their data from anywhere at any time.
7. Reduces the need for advanced hardware on the client side
8. Data storage requires physical space, with cloud computing you are not bothered about    physical space and its security. Cloud computing service provider takes care of this.
9. Data recovery and backup.
10. Streamlines the business processes.
11. Globalization, employees can access same services irrespective of their location


Disadvantages of Cloud Computing
1. Security could be one concern as the data resides with the service providers.

2. Privacy of data is other concern.


What is Public cloud and Private Cloud?


Ans).
Public Cloud: Could services are provided "as a service" over the Internet with little or no control over the underlying technology infrastructure. More than one tenant can use the same resources.


    Private Cloud: This also offers activities and functions "as a service" but is deployed over a company intranet or hosted datacenter. This is private product for a company or organization offering advance security.

    Salesforce.com: Is a public cloud as it is hosted on salesforce.com data centers and data of more than one tenant resides on same servers.



What all the services provided in cloud computing?


Hi!

In this post i am trying to explain about what is cloud computing and what are the different services offered by cloud computing.


Cloud Computing Services provide information technology (IT) as a service over the Internet or dedicated network, with delivery on demand, and payment based on usage. Cloud computing services range from full applications and development platforms, to servers, storage, and virtual desktops.

Who uses cloud computing services and why?
Corporate and government entities utilize cloud computing services to address a variety of application and infrastructure needs such as CRM, database, compute, and data storage. Unlike a traditional IT environment, where software and hardware are funded up front by department and implemented over a period of months, cloud computing services deliver IT resources in minutes to hours and align costs to actual usage. As a result, organizations have greater agility and can manage expenses more efficiently. Similarly, consumers utilize cloud computing services to simplify application utilization, store, share, and protect content, and enable access from any web-connected device.

How cloud computing services work
Cloud computing services have several common attributes:

Virtualization- cloud computing utilizes server and storage virtualization extensively to allocate/reallocate resources rapidly

Multi-tenancy -resources are pooled and shared among multiple users to gain economies of scale

Network-access - resources are accessed via web-browser or thin client using a variety of networked 
devices (computer, tablet, smartphone)

On demand - resources are self-provisioned from an online catalogue of pre-defined configurations

Elastic -resources can scale up or down, automatically

Metering/chargeback -resource usage is tracked and billed based on service arrangement

Among the many types of cloud computing services delivered internally or by third party service providers, the most common are:

Software as a Service (SaaS) – software runs on computers owned and managed by the SaaS provider, versus installed and managed on user computers. The software is accessed over the public Internet and generally offered on a monthly or yearly subscription.

Infrastructure as a Service (IaaS) – compute, storage, networking, and other elements (security, tools) are provided by the IaaS provider via public Internet, VPN, or dedicated network connection. Users own and manage operating systems, applications, and information running on the infrastructure and pay by usage.

Platform as a Service (PaaS) – All software and hardware required to build and operate cloud-based applications are provided by the PaaS provider via public Internet, VPN, or dedicated network connection. Users pay by use of the platform and control how applications are utilized throughout their lifecycle.

Benefits of cloud computing services
Cloud computing services offer numerous benefits to include:
  • Faster implementation and time to value
  • Anywhere access to applications and content
  • Rapid scalability to meet demand
  • Higher utilization of infrastructure investments
  • Lower infrastructure, energy, and facility costs
  • Greater IT staff productivity and across organization
  • Enhanced security and protection of information assets

The Importance of Customer Relationship.

Hi, 
You can get the clear idea of what exactly Customer Relationship Management (CRM) is in the below link.

http://www.openlearningworld.com/books/CRM/The%20Importance%20of%20Customer%20Relationship/index.html