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

SfdcClient: configuration enabled record type fields #235

Merged
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
28 changes: 18 additions & 10 deletions src/main/java/com/impactupgrade/nucleus/client/SfdcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,31 @@ public SfdcClient(Environment env, String username, String password, boolean isS
boolean npsp = env.getConfig().salesforce.npsp;

ACCOUNT_FIELDS = "id, OwnerId, Owner.Id, Owner.IsActive, name, phone, BillingStreet, BillingCity, BillingPostalCode, BillingState, BillingCountry, ShippingStreet, ShippingCity, ShippingPostalCode, ShippingState, ShippingCountry";
CAMPAIGN_FIELDS = "id, name, parentid, ownerid, owner.id, owner.isactive, StartDate, EndDate, RecordTypeId, RecordType.Id, RecordType.Name";
CAMPAIGN_FIELDS = "id, name, parentid, ownerid, owner.id, owner.isactive, StartDate, EndDate";
CONTACT_FIELDS = "Id, AccountId, OwnerId, Owner.Id, Owner.Name, Owner.IsActive, FirstName, LastName, Title, Account.Id, Account.Name, Account.BillingStreet, Account.BillingCity, Account.BillingPostalCode, Account.BillingState, Account.BillingCountry, Account.ShippingStreet, Account.ShippingCity, Account.ShippingPostalCode, Account.ShippingState, Account.ShippingCountry, name, email, mailingstreet, mailingcity, mailingstate, mailingpostalcode, mailingcountry, CreatedDate, HomePhone, MobilePhone, Phone";
LEAD_FIELDS = "Id, FirstName, LastName, Email, OwnerId, Owner.Id, Owner.Name, Owner.IsActive";
DONATION_FIELDS = "id, AccountId, Account.Id, Account.Name, ContactId, Amount, Name, RecordTypeId, RecordType.Id, RecordType.Name, CampaignId, Campaign.ParentId, CloseDate, StageName, Type, Description, OwnerId, Owner.Id, Owner.IsActive";
DONATION_FIELDS = "id, AccountId, Account.Id, Account.Name, ContactId, Amount, Name, CampaignId, Campaign.ParentId, CloseDate, StageName, Type, Description, OwnerId, Owner.Id, Owner.IsActive";
USER_FIELDS = "id, name, firstName, lastName, email, phone";
REPORT_FIELDS = "Id, Name";
TASK_FIELDS = "Id, WhoId, OwnerId, Subject, description, status, priority, activityDate";

// SFDC returns a query error if you try to query recordtype fields but no recordtypes exist for that object.
if (env.getConfig().salesforce.accountHasRecordTypes) {
ACCOUNT_FIELDS += ", RecordTypeId, RecordType.Id, RecordType.Name";
CONTACT_FIELDS += ", Account.RecordTypeId, Account.RecordType.Id, Account.RecordType.Name";
DONATION_FIELDS += ", Account.RecordTypeId, Account.RecordType.Id, Account.RecordType.Name";
}
if (env.getConfig().salesforce.campaignHasRecordTypes) {
CAMPAIGN_FIELDS += ", RecordTypeId, RecordType.Id, RecordType.Name";
}
if (env.getConfig().salesforce.donationHasRecordTypes) {
DONATION_FIELDS += ", RecordTypeId, RecordType.Id, RecordType.Name";
}

if (npsp) {
// TODO: Record Types are not NPSP specific, but we have yet to see them in a commercial context. IE, NPSP always
// has them due to the Household vs. Organization default, but commercial entities have a flatter setup.
// IF we need these commercially, needs to become a configurable option in env.json. Unfortunately, SFDC
// returns a query error if you try to query them but no record types exist for that object.
ACCOUNT_FIELDS += ", RecordTypeId, RecordType.Id, RecordType.Name, npo02__NumberOfClosedOpps__c, npo02__TotalOppAmount__c, npo02__LastCloseDate__c, npo02__LargestAmount__c, npo02__OppsClosedThisYear__c, npo02__OppAmountThisYear__c, npo02__FirstCloseDate__c";
// TODO: Same point about NPSP.
CONTACT_FIELDS += ", Account.RecordTypeId, Account.RecordType.Id, Account.RecordType.Name, account.npo02__NumberOfClosedOpps__c, account.npo02__TotalOppAmount__c, account.npo02__FirstCloseDate__c, account.npo02__LastCloseDate__c, account.npo02__LargestAmount__c, account.npo02__OppsClosedThisYear__c, account.npo02__OppAmountThisYear__c, npe01__Home_Address__c, npe01__WorkPhone__c, npe01__PreferredPhone__c, npe01__HomeEmail__c, npe01__WorkEmail__c, npe01__AlternateEmail__c, npe01__Preferred_Email__c";
DONATION_FIELDS += ", npe03__Recurring_Donation__c, Account.RecordTypeId, Account.RecordType.Id, Account.RecordType.Name";
ACCOUNT_FIELDS += ", npo02__NumberOfClosedOpps__c, npo02__TotalOppAmount__c, npo02__LastCloseDate__c, npo02__LargestAmount__c, npo02__OppsClosedThisYear__c, npo02__OppAmountThisYear__c, npo02__FirstCloseDate__c";
CONTACT_FIELDS += ", account.npo02__NumberOfClosedOpps__c, account.npo02__TotalOppAmount__c, account.npo02__FirstCloseDate__c, account.npo02__LastCloseDate__c, account.npo02__LargestAmount__c, account.npo02__OppsClosedThisYear__c, account.npo02__OppAmountThisYear__c, npe01__Home_Address__c, npe01__WorkPhone__c, npe01__PreferredPhone__c, npe01__HomeEmail__c, npe01__WorkEmail__c, npe01__AlternateEmail__c, npe01__Preferred_Email__c";
DONATION_FIELDS += ", npe03__Recurring_Donation__c";
RECURRINGDONATION_FIELDS = "id, name, npe03__Recurring_Donation_Campaign__c, npe03__Recurring_Donation_Campaign__r.Name, npe03__Next_Payment_Date__c, npe03__Installment_Period__c, npe03__Amount__c, npe03__Open_Ended_Status__c, npe03__Contact__c, npe03__Contact__r.Id, npe03__Contact__r.Name, npe03__Contact__r.Email, npe03__Contact__r.Phone, npe03__Schedule_Type__c, npe03__Date_Established__c, npe03__Organization__c, npe03__Organization__r.Id, npe03__Organization__r.Name, OwnerId, Owner.Id, Owner.IsActive";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public static class Salesforce extends Platform {
public boolean npsp = true;
// some differences in fields/operations
public boolean enhancedRecurringDonations = false;
public boolean accountHasRecordTypes = true;
public boolean campaignHasRecordTypes = false;
public boolean donationHasRecordTypes = true;

public boolean sandbox = false;
public String url = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,13 @@ public static CrmImportEvent fromClassy(Map<String, String> _data) {
importEvent.contactMailingZip = data.get("Billing Postal Code");
importEvent.contactMailingCountry = data.get("Billing Country");

if (!Strings.isNullOrEmpty(data.get("Campaign ID"))) {
CampaignMembership campaignMembership = new CampaignMembership();
// TODO: more likely to be an extref?
campaignMembership.campaignId = data.get("Campaign ID");
importEvent.contactCampaigns.add(campaignMembership);
}
// TODO: more likely to be an extref?
// TODO: rework this condition - triggers 'Campaign ID: id value of incorrect type: 87647' error
// if (!Strings.isNullOrEmpty(data.get("Campaign ID"))) {
// CampaignMembership campaignMembership = new CampaignMembership();
// campaignMembership.campaignId = data.get("Campaign ID");
// importEvent.contactCampaigns.add(campaignMembership);
// }
if (!Strings.isNullOrEmpty(data.get("Campaign Name"))) {
CampaignMembership campaignMembership = new CampaignMembership();
campaignMembership.campaignName = data.get("Campaign Name");
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/impactupgrade/nucleus/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ public static ZonedDateTime toZonedDateTime(Long epochSecond, String timezoneId)
}

public static Calendar toCalendar(ZonedDateTime zonedDateTime, String explicitTimezoneId) {
if (zonedDateTime == null) {
return null;
}
if (!Strings.isNullOrEmpty(explicitTimezoneId)) {
zonedDateTime = zonedDateTime.withZoneSameInstant(ZoneId.of(explicitTimezoneId));
}
return zonedDateTime != null ? GregorianCalendar.from(zonedDateTime) : null;
return GregorianCalendar.from(zonedDateTime);
}

public static String cleanUnicode(String s) {
Expand Down
Loading