# Bank Application using Apex Problem Statement: Create Bank application in SalesForce.com using Apex programming Language. - [Method 1 (Create Visual App)](#method-1) - [Method 2 (Execution Window)](#method-2) *(expected method)* - [Video Instructions](https://git.kska.io/sppu-te-comp-content/CloudComputing/src/branch/main/Practical/Assignment-3/Bank-App-Demo.mp4) --- ## Method 1 1. In the Developer Console, after creating a new `Apex Class` with the name `CreateBankCustomer`, paste the below code: > [!IMPORTANT] > Remove all the existing stuff from the file before pasting. ```java public class CreateBankCustomer { public String customerName { get; set; } public String contactNumber { get; set; } public String customerSegment { get; set; } public String accountNumber { get; set; } public String accountType { get; set; } public List segmentOptions { get; set; } public List accountTypeOptions { get; set; } public CreateBankCustomer(ApexPages.StandardController controller) { segmentOptions = new List(); segmentOptions.add(new SelectOption('', '- None -')); segmentOptions.add(new SelectOption('Retail Banking', 'Retail Banking')); segmentOptions.add(new SelectOption('Corporate Banking', 'Corporate Banking')); segmentOptions.add(new SelectOption('Private Banking', 'Private Banking')); segmentOptions.add(new SelectOption('Investment Banking', 'Investment Banking')); accountTypeOptions = new List(); accountTypeOptions.add(new SelectOption('', '- None -')); accountTypeOptions.add(new SelectOption('Savings', 'Savings')); accountTypeOptions.add(new SelectOption('Current', 'Current')); } public PageReference createCustomer() { System.debug('Creating new bank customer'); if (!String.isEmpty(customerName)) { Account customer = new Account( Name = customerName, Phone = contactNumber, Industry = customerSegment, AccountNumber = accountNumber, Type = accountType ); insert customer; PageReference pg = new PageReference('/' + customer.Id); pg.setRedirect(true); return pg; } else { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter Customer Name')); } return null; } public PageReference cancelCreation() { return new PageReference('/' + Schema.SObjectType.Account.getKeyPrefix() + '/o'); } } ``` 2. In top-left corner, click on `File` followed by `Save` to save this file. 3. In top-left corner, click on `File`, then `New -> Visualforce Page` and create a new Apex Page titled `CreateBankCustomer`. Then, paste the following code: > [!IMPORTANT] > Remove all the existing stuff from the file before pasting. ```xml ``` 4. In top-left corner, click on `File` followed by `Save` to save this file. 5. In top-left corner, right above the line numbers, click on `Preview` button. A new browser tab will open. Enter the required details and click on `Create` to create a new user. > [!TIP] > Visit `Accounts` section from App Launcher to view the changes. --- ## Method 2 1. In the Developer Console, after creating a new `Apex Class` with the name `User`, paste the below code: > [!IMPORTANT] > Remove all the existing stuff from the file before pasting. ```java public class User { public static void createAccount(String accName, String accType) { Account newAcc = new Account(); newAcc.Name = accName; newAcc.Type = accType; // Use the standard Type field try { insert newAcc; System.debug('Account created with id: ' + newAcc.Id); } catch (DmlException e) { System.debug('Error creating Account: ' + e.getMessage()); } } public static void deleteAccount(Id accId) { // Check if the account ID is valid if (accId == null) { System.debug('Account Id cannot be null'); return; } try { // Perform the delete operation delete [SELECT Id FROM Account WHERE Id = :accId LIMIT 1]; System.debug('Account with ID: ' + accId + ' has been deleted.'); } catch (DmlException e) { System.debug('Error deleting Account: ' + e.getMessage()); } catch (QueryException e) { System.debug('Error finding Account: ' + e.getMessage()); } } } ``` 2. In top-left corner, click on `File` followed by `Save` to save this file. 3. Press `Ctrl+E` to open execute anonymous window. 4. Paste the below content and hit `Execute`. ```java User.createAccount('Test Account', 'Savings); User.deleteAccount('#specified_Id'); // Id can be checked in URL when clicked on any account created in Accounts Page ``` > [!TIP] > Visit `Accounts` section from App Launcher to view the changes. > [!NOTE] > For account deletion, you have to do it directly from the `Accounts` section in App Launcher. ---