Skip to main content

Posts

Showing posts from May, 2017

Apex JSON Parser

Below apex method helps in finding record corresponding to a key from the JSON. public static String parserUtility(String jsonString, String recordType){         try{             JSONParser parser = JSON.createParser(jsonString);             while (parser.nextToken() != null) {                 if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {                     parser.nextToken();                     if(parser.getCurrentName() == recordType){                         return parser.getText();                     }                 }             }         }catch(Exception e){           e.getMessage();             return null;         }         return '';     } Example: String jsonString = '{"size":1,"totalSize":1,"done":true,"queryLocator":null,"entityTypeName":"ApexOrgWideCoverage","records":[{"attributes":{"type":"ApexOrgWideCoverage","url&q

Moving Javascript Buttons to lightning alternatives

As locker service is being introduced, Below are the alternatives with the required functionalities that were fulfilled by custom javascript buttons: JavaScript Button Top Use Cases Lightning Alternatives Declarative/Programmatic Validate fields (presave) Quick actions (using default values and/or formulas) D Apex triggers P Create records with prepopulated values Quick actions (using default values and/or formulas) D Redirect to a record page Custom URL buttons D Redirect to a Visualforce page Visualforce quick actions P Lightning actions P Prefill values based on inputs Lightning actions P Confirmation pop-up screens Lightning actions P API calls (Salesforce and third-party) Lightning actions P Feedback pop-up screens Lightning actions P Third-party integration Lightning actions P Mass actions on list view records Custom Visualforce buttons on list views P Use link: https://trailhead.salesforce.com/modules/lex_javascript_button_migration/units/javascript_button

Creating Remote Site Settings Dynamically

As remote site setting is essential for making callouts to external systems. We can create remote site through apex code: Steps: 1.       Add a metadataService class either through WSDL or you can use attached  file: metadataService.class 2.       Use below code: public void createRemoteSiteSetting (){     MetadataService.MetadataPort service = createService();     MetadataService.RemoteSiteSetting remoteSiteSettings = new MetadataService.RemoteSiteSetting();     remoteSiteSettings.fullName = ‘abc123';     remoteSiteSettings.url = 'http://www.clrdp727.com';     remoteSiteSettings.isActive=true;     remoteSiteSettings.disableProtocolSecurity=false;     service.createMetadata(new List<MetadataService.Metadata> { remoteSiteSettings }); } // This method returns the metadata service, using this we can fire action to create the remote site settings. public static MetadataService.MetadataPort createService () {     MetadataService.Metadat