Sample Apex Classes

24 September, 2020

Related Blogs

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)
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;
System.debug('xxxxxxxxx' +s1); return s1;

Apex class for creating an account, contact, 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';;
insert c;
Opportunity opp= new Opportunity(); opp.Name='Test Opportunity';
Date d= Date.newinstance(‘2012, 2, 17’); opp.CloseDate=d; opp.StageName='Closed Lost';;
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’);

For in-depth understanding on Salesforce click on