SalesForce APEX:
/* public MyFirstApexClass(){
System.debug('I am a Constructor');
}
}*/
************************************DOUBTS*************
how to insert a picklist value from Apex.
***********************************************
public class ListDemo {
public void listMethod(){
List<String> strList = new List<String>();
List<String> strList2 = new List<String>();
List<String> strList3 = new List<String>();
Set<String> strSet = new Set<String>();
Boolean result;
sObject sobj = [SELECT Id, Name from Account Limit 1];
strList.add('India'); //add(listElement)
strList.add('USA');
strList.add(1,'Switzerland'); //add(index,listElement) -> Insert a
particular value for specified Index
strList2.add('Norway');
strList2.addAll(strList);//add ALL Demo
strList3 = strList.clone(); // clone method
strSet.add('Japan');
strList2.addAll(strSet);
//result = strList2.contains('India');
//System.debug('Result = '+result);
// System.debug('strList =>'+strList);
//System.debug('strList2 =>'+strList2.get(2));
// System.debug('strList3 =>'+strList3);
// System.debug('Object Type = '+sobj.getSObjectType());
strList.sort();
System.debug(strList);
//strList2.clear(); //clear()
//System.debug('strList2 =>'+strList2);
Salesforce Platform: Quick Look
Introduction to Apex in Salesforce
Data Types in Apex in Salesforce
List in Apex in Salesforce
*************************** Anonymous Window *******************************
MyFirstApexClass d = new MyFirstApexClass();
d.methodDemo();
ListDemo l = new ListDemo();
l.listMethod();
SetDemo s = new SetDemo();
s.setMethod();
MapDemo m = new MapDemo();
m.mapDemoMethod();
******************************************************88
public class DemoSObjects {
public void demoMethod(){
Account acc = new Account();
acc.Name = 'Adhiti';
acc.Phone = '77849302019';
System.debug('acc = '+acc);
Event__c
}
-----------------------DML-----------------------
****Iserting Records*******
List<Account> accList = new List<Account>();
Account acc1 = new Account(Name = 'UA school2',Phone = '77893423234', AccountNumber
= 'ac0987') ;
Account acc2 = new Account(Name = 'Salesforce Training',Phone = '77893423237',
AccountNumber = 'ac0988') ;
accList.add(acc1);
accList.add(acc2);
insert accList;
*********** inserting related records***************
Account acc = new Account(Name = 'LWC',Phone = '77893423004', AccountNumber =
'ac0007') ;
insert acc;
Contact con = new Contact(FirstName = 'Vansika',LastName = 'P',AccountId = acc.Id);
insert con;
******************updating a record**********************
Account acc = [Select Id,Name,Phone FROM Account Where Name = 'LWC'];
System.debug('acc = ' +acc);
acc.phone = '9999999999';
update acc;
Account updatedAcc = [Select Id,Name,Phone FROM Account Where Name = 'LWC'];
System.assertEquals(updatedAcc.phone,acc.phone,'unequal');
-------updating relTED RECORDS------------
Contact con = [SELECT Id, FirstName, LastName, Phone,Account.Phone FROM Contact
Where FirstName = 'Vansika' AND AccountId != null];
con.phone = '77777777777';
con.Account.Phone = '11111111';
update con;
update con.Account;
************************UPSERT *************************************
List<Account> accList= new List<Account>();
Account acc1 = new Account(Name = 'UA school3',Phone = '77893423234', AccountNumber
= 'ac0987') ;
Account acc2 = [Select Id,Name,Phone FROM Account Where Name = 'LWC'];
acc2.Phone = '77777777';
accList.add(acc1);
accList.add(acc2);
upsert accList;
************************MERGE*********************************************
Account masterAcc =[SELECT Id, Name, Phone from Account where Name = 'UA school3'];
Account mergeAcc = [SELECT Id, Name, Phone from Account where Name = 'LWC'];
merge masterAcc mergeAcc;
*****************************DELETE**************************
List<Account> acc = [SELECT Id, Name, Phone from Account where Name = 'LWC'];
delete acc;
********************UNDELETE*******************
List<Account> deletedacc = [SELECT Id, Name, Phone from Account where Name = 'LWC'
ALL ROWS];
undelete deletedacc;
*****************************TRY Catch *********************
try{
Account acc = new Account();
insert acc;
}
catch(DMLException e){
System.debug('Error => ' +e.getMessage); // give the entire error message.
}
********************************************