• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Sample Apex Classes

Sample 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 for 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 Salesforce Training Online.

Retrieving Account Records by passing 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 account,contact,opportunity ata 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’);

For indepth understandingng on Salesforce click on

Summary
Review Date
Reviewed Item
Sample Apex Classes
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Sample Apex Classes"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.