fork download
  1. /*
  2. Insurance MISSalesforce Implementation (Option 1: Full Salesforce App)
  3. This document contains:
  4. 1) Recommended Custom Object schema XML snippets (metadata outline)
  5. 2) Apex classes (service layer, REST endpoints, schedulable batch)
  6. 3) Example Triggers
  7. 4) Lightning Web Component (LWC) prototypes (JS + HTML)
  8. 5) Deployment & Security notes (Profiles, Permission Sets, Sharing)
  9. 6) Reporting & Dashboard guidance
  10.  
  11. -- IMPORTANT --
  12. This is a developer-ready blueprint. Metadata XML files should be placed under force-app/main/default/objects for deployment via SFDX, and LWC under force-app/main/default/lwc.
  13. */
  14.  
  15. /* ===================================================
  16. 1) CUSTOM OBJECTS (metadata outline)
  17. - Create one custom object per module. Below are sample fields (API names end with __c).
  18. - Use Setup -> Object Manager or metadata XML to create these.
  19. =================================================== */
  20.  
  21. /* Matured_Case__c.object (summary of fields)
  22. - Label: Matured Case
  23. - Plural Label: Matured Cases
  24. - Fields:
  25. * Policy_Number__c (Text, 50)
  26. * EMP_ID_CSS__c (Text, 50)
  27. * Date_of_Maturity__c (Date)
  28. * Cases__c (Number, 0)
  29. * Amount__c (Currency)
  30. * Case_Status__c (Picklist): Outstanding, Paid, Writeback
  31. * Outstanding_At_YearStart__c (Number)
  32. * Outstanding_At_MonthStart__c (Number)
  33. * Paid_During_Month__c (Number)
  34. * Writeback_During_Month__c (Number)
  35. * Closing_Outstanding__c (Formula/Number)
  36. * Reason_Discharge_Voucher__c (Number)
  37. * Reason_Policy_Doc__c (Number)
  38. * Reason_Claimant_Not_Traceable__c (Number)
  39. * Reason_Reassignment__c (Number)
  40. * Reason_Record_Not_Available__c (Number)
  41. * Reason_Under_Process__c (Number)
  42. * Reason_Other__c (Number)
  43. * Reason_Grand_Total__c (Formula SUM of reasons)
  44. * Zone__c (Lookup: Zone__c)
  45. * Region__c (Lookup: Region__c)
  46. * CreatedByZoneUser__c (Checkbox)
  47. */
  48.  
  49. /* Death_Claim__c.object (outline)
  50. - Fields pulled/integrated from DCMS
  51. * DCMS_Claim_ID__c (Text)
  52. * Policy_Number__c
  53. * Deceased_Name__c
  54. * Claim_Date__c
  55. * Claim_Status__c (Picklist)
  56. * Outstanding_Reason__c (Long Text)
  57. * Linked_DCMS_Synced__c (Checkbox)
  58. * Zone__c, Region__c
  59. */
  60.  
  61. /* Surrender_Case__c.object
  62. - Fields: Policy_Number__c, Date_of_Surrender__c, Amount__c, Status__c, Zone__c, Region__c */
  63.  
  64. /* Suspense_Account__c.object
  65. - Fields: Zone__c (Lookup), Opening_Balance__c (Currency), Credit__c (Currency), Debit__c (Currency), Closing_Balance__c (Formula: Opening+Credit-Debit), Month__c (Date), Year__c (Number)
  66. */
  67.  
  68. /* Loan_Case__c.object
  69. - Fields: Policy_Number__c, Loan_Amount__c, Loan_Date__c, Recovery_Status__c (Picklist), Outstanding_Amount__c, Zone__c, Region__c
  70. */
  71.  
  72. /* Revival__c.object
  73. - Fields: Policy_Number__c, Revival_Date__c, Status__c, Remarks__c, Zone__c, Region__c
  74. */
  75.  
  76. /* Reinstatement__c.object
  77. - Fields: Policy_Number__c, Reinstatement_Date__c, Premium_Due__c, Status__c, Zone__c, Region__c
  78. */
  79.  
  80. /* Region__c and Zone__c simple master objects
  81. - Region__c: Name, Region_Code__c
  82. - Zone__c: Name, Zone_Code__c, Region__c (Master-Detail to Region)
  83. */
  84.  
  85. /* ===================================================
  86. 2) APEX: Service Layer & REST endpoints
  87. - Core service class handles calculations and aggregation
  88. - REST endpoint for external DCMS sync or for front-end React app
  89. =================================================== */
  90.  
  91. // File: ApexClasses/MISService.cls
  92. public with sharing class MISService {
  93. // Calculate closing outstanding for a matured case record
  94. public static Decimal calculateClosingOutstanding(Decimal opening, Decimal matured, Decimal paid, Decimal writeback){
  95. if(opening == null) opening = 0;
  96. if(matured == null) matured = 0;
  97. if(paid == null) paid = 0;
  98. if(writeback == null) writeback = 0;
  99. return opening + matured - (paid + writeback);
  100. }
  101.  
  102. // Aggregate outstanding by zone for a given month
  103. public class ZoneOutstanding {
  104. public Id zoneId;
  105. public String zoneName;
  106. public Integer cases;
  107. public Decimal amount;
  108. public ZoneOutstanding(Id zId, String zName){ zoneId = zId; zoneName = zName; cases=0; amount=0; }
  109. }
  110.  
  111. public static List<ZoneOutstanding> aggregateOutstandingByZone(Date monthStart, Date monthEnd){
  112. // Query matured cases with closing outstanding > 0
  113. List<AggregateResult> agg = [
  114. SELECT Zone__c z, SUM(Cases__c) sumCases, SUM(Amount__c) sumAmount
  115. FROM Matured_Case__c
  116. WHERE Date_of_Maturity__c <= :monthEnd AND Closing_Outstanding__c > 0
  117. GROUP BY Zone__c
  118. ];
  119. Map<Id, ZoneOutstanding> mapRes = new Map<Id, ZoneOutstanding>();
  120. for(AggregateResult ar : agg){
  121. Id zid = (Id) ar.get('z');
  122. Integer c = ((Decimal) ar.get('sumCases')).intValue();
  123. Decimal a = (Decimal) ar.get('sumAmount');
  124. ZoneOutstanding zo = new ZoneOutstanding(zid, (String) '');
  125. zo.cases = c; zo.amount = a;
  126. mapRes.put(zid, zo);
  127. }
  128. return mapRes.values();
  129. }
  130. }
  131.  
  132. // File: ApexClasses/MISRestController.cls
  133. @RestResource(urlMapping='/MIS/*')
  134. global with sharing class MISRestController {
  135. @HttpGet
  136. global static void getOutstandingByZone(){
  137. RestRequest req = RestContext.request;
  138. RestResponse res = RestContext.response;
  139. Date now = Date.today();
  140. Date monthStart = now.toStartOfMonth();
  141. Date monthEnd = monthStart.addMonths(1).addDays(-1);
  142. List<MISService.ZoneOutstanding> result = MISService.aggregateOutstandingByZone(monthStart, monthEnd);
  143. res.responseBody = Blob.valueOf(JSON.serialize(result));
  144. res.statusCode = 200;
  145. }
  146.  
  147. @HttpPost
  148. global static void createMaturedCase(){
  149. RestRequest req = RestContext.request;
  150. String body = req.requestBody.toString();
  151. Map<String, Object> payload = (Map<String, Object>) JSON.deserializeUntyped(body);
  152. Matured_Case__c m = new Matured_Case__c();
  153. m.Policy_Number__c = (String) payload.get('Policy_Number__c');
  154. m.EMP_ID_CSS__c = (String) payload.get('EMP_ID_CSS__c');
  155. m.Date_of_Maturity__c = Date.valueOf((String) payload.get('Date_of_Maturity__c'));
  156. m.Cases__c = (Decimal) payload.get('Cases__c');
  157. m.Amount__c = (Decimal) payload.get('Amount__c');
  158. insert m;
  159. RestContext.response.responseBody = Blob.valueOf(JSON.serialize(m));
  160. RestContext.response.statusCode = 201;
  161. }
  162. }
  163.  
  164. /* ===================================================
  165. 3) TRIGGERS
  166. - Example: trigger on Matured_Case__c to compute Closing_Outstanding__c and reason total
  167. =================================================== */
  168.  
  169. // File: triggers/MaturedCaseTrigger.trigger
  170. trigger MaturedCaseTrigger on Matured_Case__c (before insert, before update) {
  171. if(Trigger.isBefore){
  172. if(Trigger.isInsert || Trigger.isUpdate){
  173. for(Matured_Case__c m : Trigger.new){
  174. // Ensure null safety
  175. m.Outstanding_At_YearStart__c = m.Outstanding_At_YearStart__c == null ? 0 : m.Outstanding_At_YearStart__c;
  176. m.Outstanding_At_MonthStart__c = m.Outstanding_At_MonthStart__c == null ? 0 : m.Outstanding_At_MonthStart__c;
  177. m.Paid_During_Month__c = m.Paid_During_Month__c == null ? 0 : m.Paid_During_Month__c;
  178. m.Writeback_During_Month__c = m.Writeback_During_Month__c == null ? 0 : m.Writeback_During_Month__c;
  179.  
  180. // calculate closing
  181. m.Closing_Outstanding__c = MISService.calculateClosingOutstanding(m.Outstanding_At_MonthStart__c, m.Cases__c, m.Paid_During_Month__c, m.Writeback_During_Month__c);
  182.  
  183. // reason grand total
  184. Decimal reasonsSum = 0;
  185. reasonsSum += (m.Reason_Discharge_Voucher__c == null ? 0 : m.Reason_Discharge_Voucher__c);
  186. reasonsSum += (m.Reason_Policy_Doc__c == null ? 0 : m.Reason_Policy_Doc__c);
  187. reasonsSum += (m.Reason_Claimant_Not_Traceable__c == null ? 0 : m.Reason_Claimant_Not_Traceable__c);
  188. reasonsSum += (m.Reason_Reassignment__c == null ? 0 : m.Reason_Reassignment__c);
  189. reasonsSum += (m.Reason_Record_Not_Available__c == null ? 0 : m.Reason_Record_Not_Available__c);
  190. reasonsSum += (m.Reason_Under_Process__c == null ? 0 : m.Reason_Under_Process__c);
  191. reasonsSum += (m.Reason_Other__c == null ? 0 : m.Reason_Other__c);
  192. m.Reason_Grand_Total__c = reasonsSum;
  193. }
  194. }
  195. }
  196. }
  197.  
  198. /* ===================================================
  199. 4) Schedulable Batch to generate monthly reports (example)
  200. =================================================== */
  201.  
  202. // File: ApexClasses/MonthlyReportBatch.cls
  203. global class MonthlyReportBatch implements Database.Batchable<sObject>, Schedulable {
  204. global Database.QueryLocator start(Database.BatchableContext bc){
  205. Date now = Date.today();
  206. Date monthEnd = now.toStartOfMonth().addDays(-1);
  207. // Query matured cases for last month
  208. String q = 'SELECT Id, Zone__c, Cases__c, Amount__c, Closing_Outstanding__c FROM Matured_Case__c WHERE Date_of_Maturity__c >= :Date.newInstance(monthEnd.year(), monthEnd.month(), 1) AND Date_of_Maturity__c <= :monthEnd';
  209. return Database.getQueryLocator([SELECT Id, Zone__c, Cases__c, Amount__c, Closing_Outstanding__c FROM Matured_Case__c WHERE Date_of_Maturity__c >= :Date.newInstance(monthEnd.year(), monthEnd.month(), 1) AND Date_of_Maturity__c <= :monthEnd]);
  210. }
  211. global void execute(Database.BatchableContext bc, List<sObject> scope){
  212. // transform and store report rows into a custom Report__c object or send email
  213. List<Report_Row__c> rows = new List<Report_Row__c>();
  214. for(sObject s : scope){
  215. Matured_Case__c m = (Matured_Case__c) s;
  216. rows.add(new Report_Row__c(Name = 'Matured-'+m.Id, Zone__c = m.Zone__c, Cases__c = m.Cases__c, Amount__c = m.Amount__c));
  217. }
  218. if(!rows.isEmpty()) insert rows;
  219. }
  220. global void finish(Database.BatchableContext bc){
  221. // notify admins
  222. }
  223. global void execute(SchedulableContext sc){
  224. Database.executeBatch(this, 200);
  225. }
  226. }
  227.  
  228. /* ===================================================
  229. 5) LWC Prototype (folder: force-app/main/default/lwc/misDashboard)
  230. - misDashboard.html, misDashboard.js, misDashboard.js-meta.xml
  231. =================================================== */
  232.  
  233. /* misDashboard.html
  234. <template>
  235. <lightning-card title="Insurance MIS — Dashboard">
  236. <div class="slds-p-around_medium">
  237. <lightning-combobox label="Level" value={level} options={levelOptions} onchange={handleLevelChange}></lightning-combobox>
  238. <lightning-button label="Generate PDF" onclick={generatePdf}></lightning-button>
  239. <div class="slds-m-top_medium">
  240. <template if:true={zoneData}>
  241. <c-mis-zone-summary data={zoneData}></c-mis-zone-summary>
  242. </template>
  243. </div>
  244. </div>
  245. </lightning-card>
  246. </template>
  247. */
  248.  
  249. /* misDashboard.js
  250. import { LightningElement, track } from 'lwc';
  251. import getOutstandingByZone from '@salesforce/apex/MISRestController.getOutstandingByZone';
  252. export default class MisDashboard extends LightningElement {
  253. @track level = 'Principal';
  254. levelOptions = [{label:'Principal', value:'Principal'},{label:'Regional', value:'Regional'},{label:'Zonal', value:'Zonal'}];
  255. @track zoneData;
  256. connectedCallback(){ this.loadZoneData(); }
  257. loadZoneData(){
  258. // call Apex REST or Apex class
  259. }
  260. handleLevelChange(e){ this.level = e.detail.value; }
  261. generatePdf(){ /* use Lightning Reporting or export functionality */ }
  262. }
  263. */
  264.  
  265. /* misDashboard.js-meta.xml
  266. <?xml version="1.0" encoding="UTF-8"?>
  267. <LightningComponentBundle xmlns="http://s...content-available-to-author-only...e.com/2006/04/metadata">
  268. <apiVersion>58.0</apiVersion>
  269. <isExposed>true</isExposed>
  270. <targets>
  271. <target>lightning__AppPage</target>
  272. <target>lightning__RecordPage</target>
  273. <target>lightning__HomePage</target>
  274. </targets>
  275. </LightningComponentBundle>
  276. */
  277.  
  278. /* ===================================================
  279. 6) SECURITY, SHARING & DEPLOYMENT NOTES
  280. - Create Permission Sets for Principal, Regional, Zonal with object-level CRUD
  281. - Sharing rules: Zone-level sharing (criteria-based using Zone__c)
  282. - Profiles: Admin profile for Principal Office
  283. - Data validation rules: ensure Reason_Grand_Total__c equals explicit outstanding counts when needed
  284. - Use SFDX to deploy metadata, or use Change Sets for smaller teams
  285. =================================================== */
  286.  
  287. /* ===================================================
  288. 7) REPORTS & DASHBOARDS
  289. - Create standard Salesforce Reports grouped by Region, Zone, and Case Status
  290. - Dashboard components:
  291. * KPI tile: Total Outstanding Cases
  292. * Bar chart: Outstanding by Zone
  293. * Pie: Reasons breakdown (use report formula fields)
  294. - Schedule the dashboard refresh monthly and email to Principal Office
  295. =================================================== */
  296.  
  297. /* ===================================================
  298. 8) DATA MIGRATION & DCMS SYNC
  299. - Create a middleware (Heroku/External service) to pull DCMS and push into Death_Claim__c via REST endpoint (/services/apexrest/MIS/)
  300. - Use Bulk API for large historical data
  301. =================================================== */
  302.  
  303. /* ===================================================
  304. 9) NEXT STEPS I CAN DELIVER (choose any):
  305. - Full set of metadata XML files for each custom object and fields (ready for SFDX deploy)
  306. - Full Apex test classes with 75%+ coverage for deployment
  307. - Complete LWC components (Zone summary, Module forms) with Apex controllers
  308. - Permission Set and Sharing rule XML templates
  309. - Example data migration scripts (Apex + Data Loader CSV templates)
  310.  
  311. Tell me which of the above you want next and I will generate the files.
  312. */
  313.  
Success #stdin #stdout #stderr 0.01s 7844KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog:1: expected expression
./prog:2: Invalid character 0xe2
./prog:2: Invalid character 0x80
./prog:2: Invalid character 0x94
./prog:218: expected expression