Skip to content

Commit

Permalink
Testing re-introducing HH_ManageHH_CTRL original changes (with !isHHA…
Browse files Browse the repository at this point in the history
…ccount fix)...
  • Loading branch information
npsp-reedestockton committed Dec 9, 2023
1 parent f267088 commit ba8bf84
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
48 changes: 40 additions & 8 deletions force-app/main/default/classes/HH_ManageHH_CTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,28 @@ public with sharing class HH_ManageHH_CTRL {
* @return null
*/
public PageReference handleNewHousehold() {
if (hhId == null) {
hh = new npo02__Household__c();
hh.put('Name', Label.npo02.DefaultHouseholdName); // name will get fixed up when we update the contact
UTIL_DMLService.insertRecord(hh);
hhId = hh.Id;
try {
if (hhId == null) {
if (!UTIL_Permissions.canCreate('npo02__Household__c')) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
hh = new npo02__Household__c();
hh.put('Name', Label.npo02.DefaultHouseholdName); // name will get fixed up when we update the contact
UTIL_DMLService.insertRecord(hh);
hhId = hh.Id;

if (contactId != null) {
Contact con = new Contact(Id = contactId, npo02__Household__c = hhId);
UTIL_DMLService.updateRecord(con);
if (contactId != null) {
if (!UTIL_Permissions.canUpdate('Contact','npo02__Household__c', false)) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
Contact con = new Contact(Id = contactId, npo02__Household__c = hhId);
UTIL_DMLService.updateRecord(con);
}
}
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, e.getMessage()));
}

return null;
}

Expand Down Expand Up @@ -164,10 +175,31 @@ public with sharing class HH_ManageHH_CTRL {
*/
public PageReference save() {
try {
if (!canUpdateHousehold()) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
UTIL_DMLService.updateRecord(hh);
} catch (Exception ex) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, ex.getMessage()));
}
return null;
}

private Boolean canUpdateHousehold() {
String accountToCheck = isHHAccount ? 'Account' : 'npo02__Household__c';
Set<String> fieldsToCheck = new Set<String>();
for (FieldSetMember fsMember : hhFieldSet) {
fieldsToCheck.add(fsMember.getFieldPath());
}
if (!isHHAccount) {
fieldsToCheck.add('npo02__Household__c');
}
for (String fieldToCheck : fieldsToCheck) {
if (!UTIL_Permissions.canUpdate(accountToCheck, fieldToCheck, false)) {
return false;
}
}

return true;
}
}
1 change: 0 additions & 1 deletion force-app/main/default/pages/HH_ManageHH.page
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<div id="lightning" />
<!-- household fields section (using fieldset that Lightning does not yet support) -->
<apex:form id="vfForm" >
<div>This is HH_ManageHH</div>
<div class="slds-grid slds-grid_align-spread slds-m-around_medium" id="fieldset">
<div class="slds-form_stacked" style="width:80%" >
<apex:variable value="{!IF(isHHAccount, 'Account', 'npo02__Household__c')}" var="objType"/>
Expand Down

0 comments on commit ba8bf84

Please sign in to comment.