Activity Forums Salesforce® Discussions How to write static block in salesforce?

  • Piyush

    Member
    September 18, 2019 at 3:27 am

    Hi,

    You can take help from this example:-

    public class MyClass {
     
        class RGB {
    
            Integer red;
            Integer green;
            Integer blue;
    
            RGB(Integer red, Integer green, Integer blue) {
                this.red = red;
                this.green = green;
                this.blue = blue;
            }
         }
    
       static Map<String, RGB> colorMap = new Map<String, RGB>();
    
        static {
            colorMap.put('red', new RGB(255, 0, 0));
            colorMap.put('cyan', new RGB(0, 255, 255));
            colorMap.put('magenta', new RGB(255, 0, 255));
        }
    }

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos