Sample Apex Classes

Ratings:
(4.7)
Views:2985
Banner-Img
  • Share this blog:

APEX Classes

Class for Account Creation

Public Class AccountCreation
{
Public List<Account> CreateAccount(String s, String p){
List<Account> a = new List<Account>();
for(Account acc:a)
{
acc.Name=s;
acc.phone=p;
insert all;
}
return a;
}
}

Go to Developer Console and execute the following code: AccountCreation ac= new AccountCreation(); Ac.CreateAccount(‘Osmania University’, ‘9052’);

Example of Static Keyword

Public Class HelloWorld{
Public static void Method1(){
System.debug('Capital Info Solutions');
}
Public void method2(){
System.debug('Osmaina University');
}
}

Go to the Developer Console and execute the following HelloWorld hw= new HelloWorld(); Hw. Method1(); // It gives Error. For static methods, we cannot have instant for the class. HelloWorld.Method1(); Hw.Method2();

Inclined to build a profession as SalesForce Developer? Then here is the blog post on, explore SalesForce Training

 

Retrieving Account Records bypassing Single field value(Phone number)

Public class FetchAccountNameFromPhone
{
Public Set<String> FetchAccName(String p) {  Set<String> s1= new Set<String>();
List<Account> acc=“Select id, Name From Account where phone”; for(Account a:acc)
{
String s =a.name;
s1.add(s);
}
System.debug('xxxxxxxxx' +s1); return s1;
}
} 

Apex class for creating an account, contact, and opportunity at a time

Public class Acc_Con_Opty_Creation
{
Public Account CreateAccount(String n)
{
Account a = new Account(); a.Name=’n’;
insert a;
Contact c = new Contact(); c.LastName='Satti Reddy';
c.AccountId=a.id;
insert c;
Opportunity opp= new Opportunity(); opp.Name='Test Opportunity';
Date d= Date.newinstance(‘2012, 2, 17’); opp.CloseDate=d; opp.StageName='Closed Lost';
opp.Accountid=a.id;
insert opp;  return a;
}
}

Go to the Developer Console and execute the following: Acc_Con_Opty_Creation acoc= new Acc_Con_Opty_Creation(); Acc. CreateAccount(‘capital info Solutions’);

 

You liked the article?

Like : 3

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.