Skip to content

Instantly share code, notes, and snippets.

@britishboyindc
Created March 25, 2020 14:04
Show Gist options
  • Save britishboyindc/a4e4ceaec659190796ce27acac43dee1 to your computer and use it in GitHub Desktop.
Save britishboyindc/a4e4ceaec659190796ce27acac43dee1 to your computer and use it in GitHub Desktop.
public without sharing class CongressLookupUtility {
public kweos__EOCS_Data__c c {get;set;}
public kweos__EOCS_Data__c processedc {get;set;}
public String cDistrict {get;set;}
public List<Contact> kwcontacts {get;set;}
public CongressLookupUtility() {
c = new kweos__EOCS_Data__c();
}
public void getDistrictInfo () {
c.kwac__KW_Error_Code__c = '';
c.kwac__Latitude__c = NULL;
c.kwac__Longitude__c = NULL;
c.kwac__ZTDM_Expiry_Date__c = NULL;
c.kwac__KWD_Last_Processed_DT__c = NULL;
c.kwac__Zip_4__c = NULL;
c.kwac__KW_USHouseDistrict__c = '';
c.kwac__KW_USHouseDesc__c = '';
kwzd.KWD_SingleRecordUpdate kws;
String sErrorMessage = '';
try {
kws = new kwzd.KWD_SingleRecordUpdate();
kws.executeupdate('kweos__EOCS_Data__c', c);
}
Catch (Exception Ex) {
system.debug(Ex);
sErrorMessage = Ex.getmessage();
}
if (kws.showerrors) {
system.debug(kws.dbError);
sErrorMessage = kws.dbError;
cDistrict = sErrorMessage;
}
else {
processedc = (kweos__EOCS_Data__c)kws.soProcessed;
cDistrict = json.serializePretty(processedc);
}
}
public void getElectedOfficialsbyKWID(String sIds) {
List<String> kwids = sids.split(';');
kwcontacts = [Select Id, FirstName, LastName, Account.Name, kw__KW_Category__c, kw__KnowWhoIdNew__c,
Account.kw__KnowWhoIdNew__c
FROM Contact
WHERE Account.kw__KnowWhoIdNew__c IN :kwids
AND kw__KW_Category__c = 'Fed Legislator'];
}
//global KWD_ZDM_Input knowwhoResponse;
}
@RestResource(urlMapping='/congresslookup')
global class CongressLookup_REST {
@HttpGet
global static String getDistrictInfo() {
system.debug(RestContext.request.params);
Map<String, String> params = RestContext.request.params;
CongressLookupUtility clutility = new CongressLookupUtility();
clutility.c.kweos__Address1__c = params.get('street');
clutility.c.kweos__City__c = params.get('city');
clutility.c.kweos__State__c = params.get('state');
clutility.c.kweos__Postal_Code__c = params.get('zip');
clutility.getDistrictInfo();
if (params.get('officials') != NULL && params.get('officials') == '1') {
clutility.getElectedOfficialsbyKWID(clutility.processedc.kwac__Elected_Officials_Ids__c);
//RestContext.response.responseBody = Blob.valueOf(json.serializePretty(clutility.kwcontacts));
return json.serializePretty(clutility.kwcontacts);
}
else {
return clutility.cDistrict;
//RestContext.response.responseBody = Blob.valueOf(clutility.cDistrict);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment