Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data corruption during delete of soft credits #4138

Merged
merged 15 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/classes/PSC_ManageSoftCredits_CTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ public with sharing class PSC_ManageSoftCredits_CTRL {
}

} else {
// Because we turn off UI requirement validation on the contact
// we need to check on the server side to make sure the contact is populated
if (sc.contactRole.ContactId == null) {
Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, System.Label.pscManageSoftCreditsContactMissing));
return null;
}

if (sc.partial.Id != null) {
toDelete.add(sc.partial);
}
Expand Down
33 changes: 20 additions & 13 deletions src/classes/PSC_ManageSoftCredits_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -354,27 +354,33 @@ public with sharing class PSC_ManageSoftCredits_TEST {
}

/*******************************************************************************************************
* @description delete some existing PSCs by clearing their contactId.
* verify PSC's deleted, OCR's deleted
* @description verify empty contact records are not saved.
* verify PSC's are not deleted and OCR's are not deleted
*/
static testmethod void deleteExistingPSCsByClearContactId() {
@IsTest
private static void verifyEmptyContactRecordsAreNotSaved() {
initTestDataWithPscs();
Test.setCurrentPage(Page.PSC_ManageSoftCredits);
PSC_ManageSoftCredits_CTRL ctrl = new PSC_ManageSoftCredits_CTRL(new ApexPages.StandardController(opp));
system.assertEquals(cPSCExisting, ctrl.softCredits.size());
system.assertEquals(cPSCExisting * 100 , ctrl.oppTotalSoftCredit.Amount);
for (integer i = 0; i < cPSCExisting; i++)
System.assertEquals(cPSCExisting, ctrl.softCredits.size());
System.assertEquals(cPSCExisting * 100 , ctrl.oppTotalSoftCredit.Amount);

for (Integer i = 0; i < cPSCExisting; i++) {
ctrl.softCredits[i].contactRole.ContactId = null;

}

List<OpportunityContactRole> existingOCRs = [SELECT Id, ContactId, OpportunityId, Role FROM OpportunityContactRole];

Test.startTest();
system.assertNotEquals(null, ctrl.save());
System.assertEquals(null, ctrl.save());
UTIL_UnitTestData_TEST.assertPageHasMessage(System.Label.pscManageSoftCreditsContactMissing, ApexPages.Severity.WARNING);
Test.stopTest();

list<Partial_Soft_Credit__c> listPSC = [select Id, Contact__c, Opportunity__c, Amount__c, Role_Name__c from Partial_Soft_Credit__c];
system.assertEquals(0, listPSC.size());
list<OpportunityContactRole> listOCR = [select Id, ContactId, OpportunityId, Role from OpportunityContactRole];
system.assertEquals(0, listOCR.size());
List<Partial_Soft_Credit__c> listPSC = [SELECT Id, Contact__c, Opportunity__c, Amount__c, Role_Name__c FROM Partial_Soft_Credit__c];
System.assertEquals(cPSCExisting, listPSC.size());

List<OpportunityContactRole> listOCR = [SELECT Id, ContactId, OpportunityId, Role FROM OpportunityContactRole];
System.assertEquals(existingOCRs.size(), listOCR.size());
}

/*******************************************************************************************************
Expand Down Expand Up @@ -612,4 +618,5 @@ public with sharing class PSC_ManageSoftCredits_TEST {
System.assertNotEquals(0, ApexPages.getMessages().size(), 'A message should be displayed on the page.');
}
}

}
3 changes: 2 additions & 1 deletion src/components/UTIL_FormField.component
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<apex:attribute name="styleClass" type="String" default="" description="The style to apply to the outer form element." />
<apex:attribute name="labelOverride" type="String" default="" description="Override the standard field label with this text" />
<apex:attribute name="showLabel" type="Boolean" default="true" description="When false, hide the field label" />
<apex:attribute name="overrideRequired" type="Boolean" default="false" description="When true, it will set the field as not required" />

<!-- Action Support assumes onchange event and calling page has an action status component on the page -->
<apex:attribute name="actSup" type="Boolean" default="false" description="When true the input field will render action support, defaults to false." />
Expand Down Expand Up @@ -65,7 +66,7 @@
onchange="{!onchange}" actSupAction="{!actSupAction}"
actSupReRender="{!actSupReRender}" actSup="{!actSup}"
actSupStatus="{!actSupStatus}" actSupImmediate="{!actSupImmediate}"
required="{!IF(required == true, true, NOT($ObjectType[sObjType].fields[field].nillable))}"
required="{!IF(overrideRequired, false, IF(required == true, true, NOT($ObjectType[sObjType].fields[field].nillable)))}"
id="inputx"
/>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/labels/CustomLabels.labels
Original file line number Diff line number Diff line change
Expand Up @@ -5277,6 +5277,14 @@ To check your GAU Allocation settings, go to Donations | GAU Allocations.</value
<shortDescription>pscManageSoftCreditsAmountMissing</shortDescription>
<value>Please enter an amount or percent for each soft credit.</value>
</labels>
<labels>
<fullName>pscManageSoftCreditsContactMissing</fullName>
<categories>Manage Soft Credits</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>pscManageSoftCreditsContactMissing</shortDescription>
<value>You must enter a Contact for each soft credit.</value>
</labels>
<labels>
<fullName>pscManageSoftCreditsAmountOrPercent</fullName>
<categories>Manage Soft Credits</categories>
Expand Down
1 change: 1 addition & 0 deletions src/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,7 @@
<members>pscManageSoftCreditsAdd</members>
<members>pscManageSoftCreditsAmount</members>
<members>pscManageSoftCreditsAmountMissing</members>
<members>pscManageSoftCreditsContactMissing</members>
<members>pscManageSoftCreditsAmountOrPercent</members>
<members>pscManageSoftCreditsCantChangeCurrency</members>
<members>pscManageSoftCreditsFull</members>
Expand Down
7 changes: 5 additions & 2 deletions src/pages/PSC_ManageSoftCredits.page
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
<tr>
<td>
<c:UTIL_FormField sObj="{!credit.contactRole}" sObjType="OpportunityContactRole" field="ContactId"
showLabel="false" actSup="true" actSupAction="{!refresh}" actSupReRender="totalSelected, totalUn"/>
showLabel="false" actSup="true" actSupAction="{!refresh}" actSupReRender="totalSelected, totalUn"
overrideRequired="true"/>

</td>
<td>
Expand All @@ -114,7 +115,9 @@
</apex:outputPanel>
</td>
<td>
<apex:commandButton styleClass="slds-button slds-button_destructive" value="{!$Label.alloDeleteRow}" id="delRowBTN" title="{!$Label.alloDeleteRow}" action="{!delRow}" reRender="tablePanel, totalSelected, totalUn" immediate="true">
<apex:commandButton styleClass="slds-button slds-button_destructive" value="{!$Label.alloDeleteRow}" id="delRowBTN"
title="{!$Label.alloDeleteRow}" action="{!delRow}" reRender="tablePanel, totalSelected, totalUn"
immediate="false">
<span class="slds-form-element__label slds-assistive-text">
{!$Label.pscDeleteRow} {!cnt}
</span>
Expand Down