Sunday, 25 February 2018
Friday, 9 February 2018
Apex Trigger with Helper Class and Test Class
For New Developer Like I am.
1. Scenario - Create a Class, when an Account is inserted then an Opportunity with pre-defined value will be inserted under Account (Related List).
2. Create a Trigger for call the Class functionality.
3. Also create a Test Class.
Step 1. Class - 'CreateAccountOpportunity'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class CreateAccountOpportunity { public List <opportunity> oppList = new List <opportunity>(); public void CreateOpportunity(List <account> accList){ for (Account objAcc: accList) { Opportunity objOpp = new Opportunity(); objOpp.AccountID = objAcc.ID; objOpp.Name = a.Name; objOpp.CloseDate = System.Today().addDays(3); objOpp.StageName = 'Prospecting'; oppList.add(objOpp); } if (oppList.size() > 0) Database.Insert(oppList); } } |
Step 2. Trigger - 'trg_createnewoppor'
1 2 3 4 5 6 | trigger trg_createnewoppor on Account(after Insert, after update) { if ((Trigger.isInsert) || (Trigger.IsBefore)) { CreateAccountOpportunity objAccOpp = new CreateAccountOpportunity(); objAccOpp.CreateOpportunity(Trigger.New); } } |
Step 3. Test Class - 'trg_createnewoppor'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | @isTest public class CreateNewOpportunityTest { @isTest public static void CreateOpportunityTestMethod() { Account objAccount = new Account(); objAccount.Name = 'Test Acc'; insert objAccount; System.AssertEquals(objAccount.Name, 'Test Acc'); Opportunity objOpportunity = new Opportunity(); objOpportunity.Name = 'Test Opp'; objOpportunity.Accountid = objAccount.id; objOpportunity.StageName = 'Prospecting'; objOpportunity.CloseDate = system.Today() + 3; insert objOpportunity; System.AssertEquals(objOpportunity.Name, 'Test Opp'); } } |
In my next Blog I'll tell you some tips for Test Classes that I know, So don't forget to Follow me.
Thanks for Learn Carefully
Thanks & Regard.
Monday, 5 February 2018
Easy Way to Create a Visualforce page in Salesforce.
Step 1. Enter the URL like this.
Url_Name/apex/Your_Page_Name
After that Press "Enter". You will get this page, click 'Create Page Your_Page_Name'.
If you don't get this page, then make sure to activate your "Developer Mode".
Now the thing is for New Salesforce Trainees how to activate the "Developer Mode". So I will say please don't stress, it is so simple.
How? Let's go.
1. Click on your name (right side above).
2. Click on "My Setting".
3. Click on "Personal" (Left Sidebar).
4. Click on "Advanced User Detail".
5. Find here "Developer Mode" (Use - from the keyboard press 'Ctrl + F' and type here 'Developer Mode' and press Enter)
6. Please check the checkbox and Save.
7. Now Repeat the VisualForce page creation using the URL again and click on 'Create Page Your_Page_Name'.
Thanks & Regards
If it is helpful then Motivate me to new posts. So share on FB, Twitter, Linkedin, Google+ &, etc.
Url_Name/apex/Your_Page_Name
After that Press "Enter". You will get this page, click 'Create Page Your_Page_Name'.
If you don't get this page, then make sure to activate your "Developer Mode".
Now the thing is for New Salesforce Trainees how to activate the "Developer Mode". So I will say please don't stress, it is so simple.
How? Let's go.
1. Click on your name (right side above).
2. Click on "My Setting".
3. Click on "Personal" (Left Sidebar).
4. Click on "Advanced User Detail".
5. Find here "Developer Mode" (Use - from the keyboard press 'Ctrl + F' and type here 'Developer Mode' and press Enter)
6. Please check the checkbox and Save.
7. Now Repeat the VisualForce page creation using the URL again and click on 'Create Page Your_Page_Name'.
Thanks & Regards
If it is helpful then Motivate me to new posts. So share on FB, Twitter, Linkedin, Google+ &, etc.
Subscribe to:
Posts (Atom)
-
Difference between System.Today() & System.Now ? ***** System.Today() ******* 1. The return type of System.Today() is Date, so you ...
-
Note - These steps are for the Lightning Environment. Implement in Salesforce: You need to follow just these steps to create a QR cod...
-
Hi Guys and Learners. I think all of you are aware of the Connected App in Salesforce. But one thing is that after being given the f...