Posts

Showing posts from August, 2018

@TestVisible Annotation in Apex

In Salesforce, the @TestVisible annotation makes private or protected variables and methods visible in test classes. This annotation allows you to access and manipulate these elements for testing purposes without changing their access modifiers, thereby maintaining encapsulation and security in production code while enabling thorough testing. Here is an example  public class MyClass {     // Private member variable     @TestVisible private Integer myPrivateVariable = 09; } @isTest  private class TestVisibleClassTest {     @isTest static void testExample() {         // Access private variable annotated with TestVisible         Integer i = MyClass. myPrivateVariable;         System.assertEquals(09, i);     }  } Here are the key points about the @TestVisible annotation: Visibility : @TestVisible makes private or protected variables, properties, and methods visible in test...

@testSetup annotation in Apex

In Salesforce, the @ testSetup annotation is used in Apex tests to create test data that can be reused across multiple test methods within the same test class. This annotation is especially useful for making common test data required for various test methods, reducing redundancy, and improving test efficiency. Here's an example of how you can use the @ testSetup method in Salesforce: @isTest private class MyTestClass {          // Define test data setup method     @testSetup     static void setupTestData() {         // Create test records         Account acc = new Account(Name='Test Account');         insert acc;                  Contact con = new Contact(LastName='Test Contact', AccountId=acc.Id);         insert con;                  // You can create more test records as ...

Dynamically Calling JavaScript Functions

Dynamically invoking JavaScript functions enhances code flexibility and efficiency. By dynamically calling JavaScript functions, we can create more flexible and efficient applications that adapt to various scenarios. Dynamic Functionality : Dynamically calling JavaScript functions allows your code to adapt to different scenarios and conditions at runtime. This flexibility lets you execute functions based on user interactions, system events, or data-driven logic. Code Reusability : By dynamically invoking JavaScript functions, you can reuse standard functions across multiple components or modules within your application. This promotes code modularity, reduces duplication, and leads to cleaner and more maintainable code. Conditional Logic: Dynamically invoking functions allows you to apply conditional logic to determine which functions to execute based on specific conditions or criteria. This enables you to build more intelligent and adaptive applications that respond dynamically to cha...