Skip to content

Commit

Permalink
Merge pull request #76 from SalesforceFoundation/feature/8478-remove-…
Browse files Browse the repository at this point in the history
…gender-setting

Removing Gender_Field__c from hierarchy settings. We will always use …
  • Loading branch information
ceiroa committed Oct 23, 2015
2 parents cc9243e + fc1560a commit a6b52c6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 43 deletions.
5 changes: 2 additions & 3 deletions src/classes/REL_Relationships_Con_TDTM.cls
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class REL_Relationships_Con_TDTM extends TDTM_Runnable {
List<Id> ReciprocalIds = new List<Id>();
List<String> Types = new List<String>();

string genderField = UTIL_CustomSettingsFacade.getSettings().Gender_Field__c;
Set<Id> changedGender = new set<Id>();

if(newlist != null && newlist.size() > 0) {
Expand Down Expand Up @@ -86,8 +85,8 @@ public class REL_Relationships_Con_TDTM extends TDTM_Runnable {
}

//handle updates to the gender field if we have one
if (triggerAction == TDTM_Runnable.Action.afterUpdate && genderField!=null) {
if (c.get(genderField) != oldMap.get(c.id).get(genderField)) {
if (triggerAction == TDTM_Runnable.Action.afterUpdate && c.Gender__c!=null) {
if (c.Gender__c != oldMap.get(c.id).Gender__c) {
changedGender.add(c.id);
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/classes/REL_Relationships_TDTM.cls
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,7 @@ public class REL_Relationships_TDTM extends TDTM_Runnable {
rIDs.add(r.Contact__c);
}

String query_string = 'select id, Salutation';
String gender_field = '';

if (rs.Gender_Field__c != null){
gender_field = rs.Gender_Field__c;
query_string += ', ' + gender_field;
}

query_string += ' from Contact where Id IN :rIDs';
String query_string = 'select id, Salutation, Gender__c from Contact where Id IN :rIDs';

map<id, Contact> cMap = new map<id,Contact>((List<Contact>)database.query(query_string));

Expand All @@ -301,22 +293,20 @@ public class REL_Relationships_TDTM extends TDTM_Runnable {
femaleset.addAll(femalelist);

//was a gender field defined?
if (gender_field != null && gender_field != '' && relatedContact.get(gender_field) != null){

String contact_gender = (String)relatedContact.get(gender_field);
if (relatedContact.Gender__c != null){
String match_type = '';

//try male
for (String s : malelist){
if (contact_gender.toLowerCase() == s.toLowerCase().trim()){
if (relatedContact.Gender__c.toLowerCase() == s.toLowerCase().trim()){
match_type = 'male';
break;
}
}
//if we haven't found it, try female
if(match_type == ''){
for (String s : femalelist){
if (contact_gender.toLowerCase() == s.toLowerCase().trim()){
if (relatedContact.Gender__c.toLowerCase() == s.toLowerCase().trim()){
match_type = 'female';
break;
}
Expand Down
27 changes: 15 additions & 12 deletions src/classes/REL_Relationships_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public class REL_Relationships_TEST {
*/
private static void setupRelationshipTestData(Hierarchy_Settings__c rs){

//set running user to avoid dml issue
//set running user to avoid dml issue
System.runAs(new User(id = UserInfo.getUserId())){

if (rs != null)
UTIL_CustomSettingsFacade.getSettingsForTests(rs);
else
UTIL_CustomSettingsFacade.getSettingsForTests(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting',
Gender_Field__c = 'Description', Store_Errors_On__c = true));
Store_Errors_On__c = true));

//add autocreate settings for CMs
delete [select id from Relationship_Auto_Create__c];
Expand Down Expand Up @@ -560,11 +560,11 @@ public class REL_Relationships_TEST {
public static void testNeutralGenderFieldReciprocal(){
if (strTestOnly != '*' && strTestOnly != 'testNeutralGenderFieldReciprocal') return;

setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting', Gender_Field__c = 'Description'));
setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting'));
Relationship__c[] crel = new Relationship__c[]{
new Relationship__c(contact__c = c3.id, Relatedcontact__c = c2.id, Type__c='TestLookupType')
};
c3.Description = 'Neutral';
c3.Gender__c = 'Neutral';
update c3;
//reset the process controller to mimic a second user action
//Relationships_ProcessControl.hasRun = false;
Expand All @@ -584,8 +584,8 @@ public class REL_Relationships_TEST {
public static void testMaleGenderFieldReciprocal(){
if (strTestOnly != '*' && strTestOnly != 'testMaleGenderFieldReciprocal') return;

setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting', Gender_Field__c = 'Description'));
c1.Description = 'Male';
setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting'));
c1.Gender__c = 'Male';
update c1;
Relationship__c[] crel = new Relationship__c[]{
new Relationship__c(contact__c = c1.id, Relatedcontact__c = c2.id, Type__c='TestLookupType')
Expand All @@ -608,8 +608,8 @@ public class REL_Relationships_TEST {
public static void testFemaleGenderFieldReciprocal(){
if (strTestOnly != '*' && strTestOnly != 'testFemaleGenderFieldReciprocal') return;

setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting', Gender_Field__c = 'Description'));
c2.Description = 'Female';
setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting'));
c2.Gender__c = 'Female';
update c2;

Relationship__c[] crel = new Relationship__c[]{
Expand Down Expand Up @@ -709,11 +709,11 @@ public class REL_Relationships_TEST {
static testMethod void testGenderChange(){
if (strTestOnly != '*' && strTestOnly != 'testGenderChange') return;

setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting', Gender_Field__c = 'Description'));
setupRelationshipTestData(new Hierarchy_Settings__c(Reciprocal_Method__c = 'List Setting'));

list<Contact> conList = new list<Contact>{
new Contact(LastName='foo', Description='Female'),
new Contact(LastName='foo2', Description='Male')
new Contact(LastName='foo', Gender__c='Female'),
new Contact(LastName='foo2', Gender__c='Male')
};
insert conList;

Expand All @@ -729,8 +729,11 @@ public class REL_Relationships_TEST {
recRel = [select id, Type__c from Relationship__c where ReciprocalRelationship__c = :crel[0].id];
system.assertEquals('TestFemaleType', recRel.Type__c);

conList[1].Description='Female';
conList[1].Gender__c='Female';

Test.startTest();
update conList[1];
Test.stopTest();

recRel = [select id, Type__c from Relationship__c where id = :crel[0].id];
system.assertEquals('TestFemaleType', recRel.Type__c);
Expand Down
1 change: 0 additions & 1 deletion src/classes/UTIL_CustomSettingsFacade.cls
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public without sharing class UTIL_CustomSettingsFacade {
settings.Simple_Address_Change_Treated_as_Update__c = mySettings.Simple_Address_Change_Treated_as_Update__c;
settings.Household_Adm_Acct_Addresses_Enabled__c = mySettings.Household_Adm_Acct_Addresses_Enabled__c;
settings.Reciprocal_Method__c = mySettings.Reciprocal_Method__c;
settings.Gender_Field__c = mySettings.Gender_Field__c;
settings.Error_Notifications_On__c = mySettings.Error_Notifications_On__c;
settings.Error_Notifications_To__c = mySettings.Error_Notifications_To__c;
settings.Store_Errors_On__c = mySettings.Store_Errors_On__c;
Expand Down
12 changes: 0 additions & 12 deletions src/objects/Hierarchy_Settings__c.object
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@
<trackTrending>false</trackTrending>
<type>TextArea</type>
</fields>
<fields>
<fullName>Gender_Field__c</fullName>
<description>The custom field used to define the gender of a Contact for determining reciprocal relationships</description>
<externalId>false</externalId>
<inlineHelpText>The custom field used to define the gender of a Contact for determining reciprocal relationships</inlineHelpText>
<label>Gender Field</label>
<length>255</length>
<required>false</required>
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>false</unique>
</fields>
<fields>
<fullName>Household_Adm_Acct_Addresses_Enabled__c</fullName>
<defaultValue>false</defaultValue>
Expand Down
1 change: 0 additions & 1 deletion src/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
<members>Hierarchy_Settings__c.Enable_Debug__c</members>
<members>Hierarchy_Settings__c.Error_Notifications_On__c</members>
<members>Hierarchy_Settings__c.Error_Notifications_To__c</members>
<members>Hierarchy_Settings__c.Gender_Field__c</members>
<members>Hierarchy_Settings__c.Household_Adm_Acct_Addresses_Enabled__c</members>
<members>Hierarchy_Settings__c.Organizational_Account_Addresses_Enabled__c</members>
<members>Hierarchy_Settings__c.Reciprocal_Method__c</members>
Expand Down

0 comments on commit a6b52c6

Please sign in to comment.