Add Single Account with Insert
// datatype variableName = exp
Account singleAcc= New Account(name='New Account from APEX',phone='123123123');
System.debug(singleAcc);
// DML variable sent to Salesforce DB
**insert** singleAcc;
Add Account and Contact with Insert
// datatype variableName = exp
Account singleAcc= New Account();
singleAcc.Name='APEX ACC HAS CONTACT LLC';
singleAcc.Phone='+11111111';
singleAcc.Website='www.ACC1.com';
singleAcc.Rating='Hot';
System.debug('Account BEFORE INSERT ID: '+ singleAcc.id);
// DML variable sent to Salesforce DB
**insert** singleAcc;
System.debug('Account AFTER INSERT ID: '+ singleAcc.id);
// contact oluşturma
Contact singleContact = New Contact();
singleContact.firstName='Alex';
singleContact.lastName='Victor'; // required
singleContact.AccountId=singleAcc.id; // Lookup this field is required account id from account object
System.debug('Contact BEFORE INSERT ID: '+ singleContact.id);
// DML contact creation request to SALESFORCE
**insert** singleContact;
System.debug('Contact BEFORE INSERT ID: '+ singleContact.id);
Update Account Record
// SELECT id, Name FROM Account WHERE Name ='APEX ESTA LLC' LIMIT 1
Account singleAccount = [SELECT id, Name FROM Account WHERE Name ='APEX ESTA LLC' LIMIT 1];
System.debug('Single Account : '+ singleAccount);
singleAccount.Industry='Banking';
System.debug('Single Account : '+ singleAccount);
**update** singleAccount;
Make SOQL Query and Add Opportunity to Related Account
// SELECT id, Name FROM Account WHERE Name ='APEX ESTA LLC' LIMIT 1
Account singleAccount = [SELECT id, Name FROM Account WHERE Name ='APEX ESTA LLC' LIMIT 1];
singleAccount.Industry='Education';
**update** singleAccount;
Opportunity singleOpportunity = New Opportunity();
String opName =singleAccount.Name + ' 🔥 ' + ' Webinar APEX';
Date futureDate = date.today()+20;
singleOpportunity.Name=opName;
singleOpportunity.CloseDate =futureDate;
singleOpportunity.StageName='Prospecting';
singleOpportunity.Amount = 5000;
singleOpportunity.AccountId=singleAccount.id; // lookup Relation
**insert** singleOpportunity;
// this is not a good way to check opportunity creation.
// best way is to do this steps using Try- Catch we will learn this later.
if(String.isBlank(singleOpportunity.id)){
System.Debug('Opportunity Cannot be Created');
} else {
System.Debug('Opportunity Created');
}