public with sharing class ExportTrackerController { public string currentRecordId { get; set; } public string exportName { get; set; } public string objectName; public string Approver { get; set; } public string Requester { get; set; } public string BusinessJustification { get; set; } public string BusinessJustificationPickVal { get; set; } public string RecipientName { get; set; } public string RecipientCompany { get; set; } public string RecipientPhone { get; set; } public string RecipientEmail { get; set; } public string AEArtistslist { get; set; } public string AElabels { get; set; } public string AEFanActionsChannels { get; set; } public string AEDateRangeofActivity { get; set; } public string comboTerritory { get; set; } public string comboLabel { get; set; } public string comboArtist { get; set; } public string comboFormId { get; set; } public string artistname { get; set; } public string comboMailingList { get; set; } public string Active { get; set; } public string PromoID { get; set; } public string normalFormId { get; set; } public string ExportNote { get; set; } public string statevalue { get; set; } public string cityvalue { get; set; } public string countryvalue { get; set; } public string postalcodevalue { get; set; } public Date fromDate { get; set; } public Date toDate { get; set; } public Date subhfromDate { get; set; } public Date subhtoDate { get; set; } public Id recordId { get; set; } public DateTime frDT; public DateTime toDT; public string stateoption { get; set; } public string cityoption { get; set; } public string countryoption { get; set; } public string postalcodeoption { get; set; } public Boolean cityDis { get; set; } public Boolean stateDis { get; set; } public Boolean countryDis { get; set; } public Boolean postalDis { get; set; } public Boolean businessFlag { get; set; } public Boolean showactiveccpa { get; set; } public Boolean showae { get; set; } public Boolean filestatus { get; set; } public Boolean showactivetrue { get; set; } public Boolean showactive { get; set; } public Boolean hideActivecheck { get; set; } public Boolean hideformID { get; set; } public Boolean hidepromoID { get; set; } public Boolean showDaterange { get; set; } public Boolean showsubDaterange { get; set; } public Boolean hideShow { get; set; } public Boolean Showfile { get; set; } public Boolean showFr { get; set; } public Boolean showSub { get; set; } public Boolean cust1 { get; set; } public Boolean geocity { get; set; } public Boolean geocountry { get; set; } public Boolean MailingListName { get; set; } public Boolean CreatedDate { get; set; } public Boolean FirstName { get; set; } public Boolean LastName { get; set; } public Boolean AgeRange { get; set; } public Boolean Gender { get; set; } public Boolean Address { get; set; } public Boolean City { get; set; } public Boolean State { get; set; } public Boolean Country { get; set; } public Boolean PostalCode { get; set; } public Boolean Birthday { get; set; } public Boolean Birthdate { get; set; } public Boolean MobilePhone { get; set; } public Boolean Twitterhandle { get; set; } public Boolean Language { get; set; } public Boolean DSP { get; set; } public Boolean PreferredGenre { get; set; } public Boolean InstagramHandle { get; set; } public Boolean PromoIdcheck { get; set; } public Boolean PromoDescription { get; set; } public Boolean FormName { get; set; } public Boolean email { get; set; } public Boolean emailcheck { get; set; } public Boolean Activecheck { get; set; } public Set selectFieldsSet; public List selectFieldsList; public List selectFieldslistfinal; @TestVisible Integer selectFieldLen; public List fromdatelist; public List todatelist; public String fieldsQuery; public string impexpid { get; set; } public string importexpid { get; set; } public String reqFieldsQuery; public String subhreqFieldsQuery; public String optFieldsQuery; public String query = ''; public String statetrims; public String statetrim; public String statetrimfinal; public String citytrim; public String citytrims; public String citytrimfinal; public String countrytrim; public String countrytrims; public String countrytrimfinal; public String postalcodetrim; public String postalcodetrims; public String postalcodetrimfinal; public Boolean inputValue { get; set; } public Boolean snowflakeWarning { get; set; } public Boolean def { get; set; } public Boolean showFr1 { get; set; } public Boolean showae1 { get; set; } public Boolean showSub1 { get; set; } public Boolean textshow { get; set; } public Export__c expObj; List toAdd = new List(); public string frDateRange; public string toDateRange; public string toDateString; public string fromDateString; public integer subhcount = 0; public Map subhpromoMap; public string subpromoid; public string subhpromo; public transient list subhidslist; public list subhislist; public String profileName; public ExportTrackerController(ApexPages.StandardController controller) { recordId = controller.getId(); Id profileId = userinfo.getProfileId(); profileName = [SELECT Id, Name FROM Profile WHERE Id = :profileId].Name; if (profileName == 'UKReadOnly') { showae = false; } else { showae = true; } expObj = new Export__c(); //required Fields initilization exportName = ''; objectName = ''; Approver = ''; Requester = ''; BusinessJustification = ''; RecipientName = ''; RecipientCompany = ''; RecipientPhone = ''; RecipientEmail = ''; AEArtistslist = ''; AElabels = ''; AEFanActionsChannels = ''; AEDateRangeofActivity = ''; ExportNote = ''; comboTerritory = ''; comboLabel = ''; comboArtist = ''; comboFormId = ''; comboMailingList = ''; artistname = ''; Active = 'none'; //datefields frDateRange = ''; toDateRange = ''; toDateString = ''; fromDateString = ''; //optional Fields initilization PromoID = ''; normalFormId = ''; statevalue = ''; cityvalue = ''; countryvalue = ''; postalcodevalue = ''; citytrimfinal = ''; citytrim = ''; statetrim = ''; countrytrim = ''; postalcodetrim = ''; citytrims = ''; statetrims = ''; countrytrims = ''; postalcodetrims = ''; cityoption = 'none'; stateoption = 'none'; countryoption = 'none'; postalcodeoption = 'none'; cityDis = true; stateDis = true; countryDis = true; postalDis = true; businessFlag = true; showactiveccpa = true; emailcheck = true; filestatus = false; fieldsQuery = ''; reqFieldsQuery = ''; subhreqFieldsQuery = ''; optFieldsQuery = ''; query = 'select '; subpromoid = ''; subhpromo = ''; subhpromoMap = new Map(); subhidslist = new List(); subhislist = new List(); selectFieldsSet = new Set(); selectFieldslistfinal = new List(); selectFieldsList = new List(); fromdatelist = new List(); todatelist = new List(); selectFieldsList.clear(); hideActivecheck = false; hideformID = false; hidepromoID = false; showDaterange = false; showsubDaterange = false; Showfile = false; hideShow = false; showFr = false; showSub = false; showFr1 = false; showae1 = false; showSub1 = false; textshow = false; inputValue = false; snowflakeWarning = false; //Intialization Custom1-20 cust1 = false; def = true; importexpid = ''; system.debug(selectFieldsList); } public void ExportData() { try { selectFieldsList.addAll(selectFieldsSet); selectFieldLen = selectFieldsList.size(); if (exportName == 'Mailing List') { if ( Approver == '' || Requester == '' || BusinessJustificationPickVal == 'None' || RecipientName == '' || RecipientCompany == '' || RecipientEmail == '' || RecipientPhone == '' || comboTerritory == '' || comboLabel == '' || comboArtist == '' || comboMailingList == '' || Active == 'none' ) { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please fill all the required fields.') ); inputValue = false; } else if (BusinessJustificationPickVal == 'ML Other' && BusinessJustification == '') { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please fill Business Justification.') ); inputValue = false; } else if (String.isNotBlank(PromoID) && !PromoID.startsWithIgnoreCase('PID')) { system.debug('PromoID value is in Incorrect format'); Apexpages.addMessage( new Apexpages.Message( Apexpages.Severity.Info, 'Please enter Promo ID in valid format (Ex: PID00000).' ) ); inputValue = false; } else if ( String.isNotBlank(normalFormId) && !normalFormId.startsWith('a0Q') && (normalFormId.length() != 15 || normalFormId.length() != 18) ) { system.debug('FormId value is in Incorrect format'); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please enter 15 or 18 digit valid Form ID.') ); inputValue = false; } else if (String.isBlank(cityValue) && (cityOption == 'starts with' || cityOption == 'contains')) { system.debug('Value cannot be blank with starts with or contains as filter'); Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.Info, 'Please fill Fan City.')); inputValue = false; } else if (String.isBlank(statevalue) && (stateOption == 'starts with' || stateOption == 'contains')) { system.debug('Value cannot be blank with starts with or contains as filter'); Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.Info, 'Please fill Fan State.')); inputValue = false; } else if ( String.isBlank(countryvalue) && (countryOption == 'starts with' || countryOption == 'contains') ) { system.debug('Value cannot be blank with starts with or contains as filter'); Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.Info, 'Please fill Fan Country.')); inputValue = false; } else if ( String.isBlank(postalcodevalue) && (postalcodeoption == 'starts with' || postalcodeoption == 'contains') ) { system.debug('Value cannot be blank with starts with or contains as filter'); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please fill Fan Postal Code.') ); inputValue = false; } else if (selectFieldsList.size() < 1) { Apexpages.addMessage( new Apexpages.Message( Apexpages.Severity.Info, 'Please select at least one field from choose field(s).' ) ); inputValue = false; } else { inputValue = true; validateEmail(); } } else { if ( Approver == '' || Requester == '' || BusinessJustificationPickVal == 'None' || RecipientName == '' || RecipientCompany == '' || RecipientEmail == '' || RecipientPhone == '' || comboTerritory == '' || comboLabel == '' || comboArtist == '' || comboFormId == '' ) { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please fill all the required fields.') ); inputValue = false; } else if (BusinessJustificationPickVal == 'FR Other' && BusinessJustification == '') { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please fill Business Justification.') ); inputValue = false; } else if (selectFieldsList.size() < 1) { Apexpages.addMessage( new Apexpages.Message( Apexpages.Severity.Info, 'Please select at least one field from choose field(s).' ) ); inputValue = false; } else { inputValue = true; validateEmail(); } } } catch (Exception e) { SMELogger.logError(e); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.INFO, 'An error has occured, please try again.') ); inputValue = false; } inputValue = !ApexPages.hasMessages(); } public PageReference batchProcessCall() { query = 'select '; fieldsQuery = ''; reqFieldsQuery = ''; optFieldsQuery = ''; selectFieldslistfinal.clear(); try { if (exportName == 'Mailing List') { Export__c exp = new Export__c(); exp.Export_Type__c = exportName; exp.Approver__c = Approver; exp.Requester__c = Requester; if (BusinessJustificationPickVal != 'ML Other') { BusinessJustificationPickVal = BusinessJustificationPickVal.substring(3); exp.Business_Justification__c = BusinessJustificationPickVal; } else { exp.Business_Justification__c = BusinessJustification; } exp.Recipient_Name__c = RecipientName; exp.Recipient_Company__c = RecipientCompany; exp.Recipient_Phone_Number__c = RecipientPhone; exp.Recipient_Email__c = RecipientEmail; exp.Territory_ID__c = comboTerritory; exp.Label_ID__c = comboLabel; exp.Artist_ID__c = comboArtist; exp.Mailing_List_ID__c = comboMailingList; exp.Active__c = Active; exp.Promo_ID__c = PromoID; //if(normalFormId !='') if (PromoID == '') { exp.formId__c = normalFormId; } else { exp.formId__c = ''; } if (PromoID == '') { exp.Subscription_From_Date__c = fromDate; exp.Subscription_To_Date__c = toDate; exp.Active__c = Active; } if (PromoID != '') { exp.Subscription_History_From_Date__c = subhfromDate; exp.Subscription_History_To_Date__c = subhtoDate; exp.Active__c = Active; } exp.Exclude_CCPA_Do_Not_Sell__c = showactiveccpa; exp.Mailing_List_Name__c = MailingListName; exp.Email__c = email; exp.Language__c = Language; exp.DSP__c = DSP; exp.Preferred_Genre__c = PreferredGenre; exp.Twitter_handle__c = Twitterhandle; exp.Mobile_Phone__c = MobilePhone; exp.Birthdate__c = Birthdate; exp.Birthday__c = Birthday; exp.Fan_Country__c = Country; exp.Fan_City__c = City; exp.Fan_State__c = State; exp.Postal_Code_1__c = PostalCode; exp.Address__c = Address; exp.Gender__c = Gender; exp.Age_Range__c = AgeRange; exp.Last_Name__c = LastName; exp.First_Name__c = FirstName; exp.Created_Date__c = CreatedDate; exp.Instagram_Handle__c = InstagramHandle; exp.Active_check__c = Activecheck; exp.PromoID__c = PromoIdcheck; exp.Promo_Description__c = PromoDescription; exp.Export_Note__c = Exportnote; exp.Exported_By__c = UserInfo.getName(); if (cityOption != 'none') exp.Fan_City_option__c = cityOption; if (stateoption != 'none') exp.Fan_State_Option__c = stateoption; if (countryoption != 'none') exp.Fan_Country_Option__c = countryoption; if (postalcodeoption != 'none') exp.Fan_Postal_Code_Option__c = postalcodeoption; System.debug('values selected' + selectFieldslistfinal.size()); /*changes for selected fields */ if (email == true) selectFieldslistfinal.add('Fan_ID__r.Email__c'); if (FirstName == true) selectFieldslistfinal.add('Fan_ID__r.First_Name__c'); if (LastName == true) selectFieldslistfinal.add('Fan_ID__r.Last_Name__c'); if (AgeRange == true) selectFieldslistfinal.add('Fan_ID__r.Age_Range__c'); if (Gender == true) selectFieldslistfinal.add('Fan_ID__r.Gender__c'); if (Address == true) { selectFieldslistfinal.add('Fan_ID__r.Address_1__c'); selectFieldslistfinal.add('Fan_ID__r.Address_2__c'); } if (City == true) selectFieldslistfinal.add('Fan_ID__r.City__c'); if (State == true) selectFieldslistfinal.add('Fan_ID__r.State__c'); if (Country == true) selectFieldslistfinal.add('Fan_ID__r.Country_Region__c'); if (PostalCode == true) selectFieldslistfinal.add('Fan_ID__r.Postal_Code__c'); if (Birthday == true) selectFieldslistfinal.add('Fan_ID__r.Birthday_mm_dd__c'); if (Birthdate == true) selectFieldslistfinal.add('Fan_ID__r.Birthdate__c'); if (MobilePhone == true) selectFieldslistfinal.add('Fan_ID__r.Mobile_Phone__c'); if (Twitterhandle == true) selectFieldslistfinal.add('Fan_ID__r.Twitter_Handle__c'); if (PromoID == '') { if (Activecheck == true) { selectFieldslistfinal.add('Active__c'); } } if (InstagramHandle == true) selectFieldslistfinal.add('Fan_ID__r.Instagram_Handle__c'); if (Language == true) selectFieldslistfinal.add('Fan_ID__r.Preferred_Language__c'); if (DSP == true) selectFieldslistfinal.add('DSP__c'); if (PreferredGenre == true) selectFieldslistfinal.add('Preferred_Genre__c'); if (CreatedDate == true) selectFieldslistfinal.add('CreatedDate'); if (MailingListName == true) { selectFieldslistfinal.add('Mailing_List_Name__c'); } if (PromoIdcheck == true) selectFieldslistfinal.add('Promo_ID_Value__c'); if (PromoDescription == true) selectFieldslistfinal.add('Promo_Description_Value__c'); /*changes ends */ System.debug('values selected after::' + selectFieldslistfinal.size()); fieldsQuery = String.join(selectFieldslistfinal, ','); if (fromDate != null) { frDT = convertDateTime(fromDate); fromDateString = string.valueOf(frDT); fromdatelist = fromDateString.split(' '); frDateRange = fromdatelist[0] + 'T' + '00:00:00' + '.000+0000'; } if (toDate != null) { toDT = convertDateTime(toDate); toDateString = string.valueOf(toDT); todatelist = toDateString.split(' '); toDateRange = todatelist[0] + 'T' + '23:59:59' + '.000+0000'; } if (subhfromDate != null) { frDT = convertDateTime(subhfromDate); fromDateString = string.valueOf(frDT); fromdatelist = fromDateString.split(' '); frDateRange = fromdatelist[0] + 'T' + '00:00:00' + '.000+0000'; } if (subhtoDate != null) { toDT = convertDateTime(subhtoDate); toDateString = string.valueOf(toDT); todatelist = toDateString.split(' '); toDateRange = todatelist[0] + 'T' + '23:59:59' + '.000+0000'; } reqFieldsQuery += ' FROM Subscription__c where Mailing_List_ID__c=\'' + exp.Mailing_List_ID__c + '\' '; subhreqFieldsQuery += ' FROM Subscription_History__c where Mailing_List_ID__c=\'' + exp.Mailing_List_ID__c + '\' '; if (Active == 'true' || Active == 'false') { reqFieldsQuery += ' and Active__c=' + exp.Active__c; subhreqFieldsQuery += ' and Subscription_id__r.Active__c=' + exp.Active__c; } if (normalFormId != '') { reqFieldsQuery += ' and Form_id__c=\'' + exp.formId__c + '\''; } if (PromoID != '' && PromoID.startsWith('PID')) { subhreqFieldsQuery += ' and Promo_ID__r.name=\'' + exp.Promo_ID__c + '\' '; objectName = 'Subscription_History__c'; } else { objectName = 'Subscription__c'; } if (showactiveccpa) { reqFieldsQuery += ' and Fan_id__r.CCPA_Do_Not_Sell__c = false '; subhreqFieldsQuery += ' and Fan_id__r.CCPA_Do_Not_Sell__c = false '; } if (frDateRange != '') { reqFieldsQuery += ' and CreatedDate >= ' + frDateRange; subhreqFieldsQuery += ' and CreatedDate >= ' + frDateRange; } if (toDateRange != '') { reqFieldsQuery += ' and CreatedDate <= ' + toDateRange; subhreqFieldsQuery += ' and CreatedDate <= ' + toDateRange; } //query based on Fan City value with option if (cityoption != 'none') { if (cityOption == 'not equal to') { citytrims = cityvalue.trim(); optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.City__c!=\'' + citytrims + '\''; } else if (cityOption == 'starts with') { List cityValuesList = cityValue.split(','); integer cityValLen = cityValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < cityValLen; i++) { citytrimfinal = cityValuesList[i].trim(); aftertrimlist.add(citytrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { citytrim = citytrim + aftertrimlist[i] + ','; citytrims = citytrim.removeEnd(','); System.debug('citytrim::' + citytrim); } for (Integer i = 0; i < cityValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.City__c LIKE \'' + aftertrimlist[i] + '%' + '\''; if (i == cityValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == cityValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.City__c LIKE \'' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.City__c LIKE \'' + aftertrimlist[i] + '%' + '\''; } } } else if (cityOption == 'contains') { List cityValuesList = cityValue.split(','); integer cityValLen = cityValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < cityValLen; i++) { citytrimfinal = cityValuesList[i].trim(); aftertrimlist.add(citytrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { citytrim = citytrim + aftertrimlist[i] + ','; citytrims = citytrim.removeEnd(','); System.debug('citytrim::' + citytrim); } for (Integer i = 0; i < cityValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.City__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; if (i == cityValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == cityValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.City__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.City__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; } } } else { List cityValuesList = cityValue.split(','); integer cityValLen = cityValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < cityValLen; i++) { citytrimfinal = cityValuesList[i].trim(); aftertrimlist.add(citytrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { citytrim = citytrim + aftertrimlist[i] + ','; citytrims = citytrim.removeEnd(','); System.debug('citytrim::' + citytrim); } for (Integer i = 0; i < cityValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.City__c IN (\'' + aftertrimlist[i] + '\''; if (i == cityValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == cityValLen - 1) optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\')'; else optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\''; } } } } //query based on Fan State value with option if (stateoption != 'none') { if (stateOption == 'not equal to') { statetrims = statevalue.trim(); optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.State__c!=\'' + statetrims + '\''; } else if (stateOption == 'starts with') { List stateValuesList = statevalue.split(','); integer stateValLen = stateValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < stateValLen; i++) { statetrimfinal = stateValuesList[i].trim(); aftertrimlist.add(statetrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { statetrim = statetrim + aftertrimlist[i] + ','; statetrims = statetrim.removeEnd(','); System.debug('statetrim::' + statetrim); } for (Integer i = 0; i < stateValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.State__c LIKE \'' + aftertrimlist[i] + '%' + '\''; if (i == stateValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == stateValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.State__c LIKE \'' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.State__c LIKE \'' + aftertrimlist[i] + '%' + '\''; } } } else if (stateOption == 'contains') { List stateValuesList = statevalue.split(','); integer stateValLen = stateValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < stateValLen; i++) { statetrimfinal = stateValuesList[i].trim(); aftertrimlist.add(statetrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { statetrim = statetrim + aftertrimlist[i] + ','; statetrims = statetrim.removeEnd(','); System.debug('statetrim::' + statetrim); } for (Integer i = 0; i < stateValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.State__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; if (i == stateValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == stateValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.State__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.State__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; } } } else { List stateValuesList = statevalue.split(','); integer stateValLen = stateValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < stateValLen; i++) { statetrimfinal = stateValuesList[i].trim(); aftertrimlist.add(statetrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { statetrim = statetrim + aftertrimlist[i] + ','; statetrims = statetrim.removeEnd(','); System.debug('statetrim::' + statetrim); } for (Integer i = 0; i < stateValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.State__c IN (\'' + aftertrimlist[i] + '\''; if (i == stateValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == stateValLen - 1) optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\')'; else optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\''; } } } } //query based on Fan Country value with option if (countryoption != 'none') { if (countryOption == 'not equal to') { countrytrims = countryvalue.trim(); optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.Country_Region__c!=\'' + countrytrims + '\''; } else if (countryOption == 'starts with') { List countryValuesList = countryvalue.split(','); integer countryValLen = countryValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < countryValLen; i++) { countrytrimfinal = countryValuesList[i].trim(); aftertrimlist.add(countrytrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { countrytrim = countrytrim + aftertrimlist[i] + ','; countrytrims = countrytrim.removeEnd(','); System.debug('countrytrim::' + countrytrim); } for (Integer i = 0; i < countryValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.Country_Region__c LIKE \'' + aftertrimlist[i] + '%' + '\''; if (i == countryValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == countryValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Country_Region__c LIKE \'' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Country_Region__c LIKE \'' + aftertrimlist[i] + '%' + '\''; } } } else if (countryOption == 'contains') { List countryValuesList = countryvalue.split(','); integer countryValLen = countryValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < countryValLen; i++) { countrytrimfinal = countryValuesList[i].trim(); aftertrimlist.add(countrytrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { countrytrim = countrytrim + aftertrimlist[i] + ','; countrytrims = countrytrim.removeEnd(','); System.debug('countrytrim::' + countrytrim); } for (Integer i = 0; i < countryValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.Country_Region__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; if (i == countryValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == countryValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Country_Region__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Country_Region__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; } } } else { List countryValuesList = countryvalue.split(','); integer countryValLen = countryValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < countryValLen; i++) { countrytrimfinal = countryValuesList[i].trim(); aftertrimlist.add(countrytrimfinal); } for (integer i = 0; i < aftertrimlist.size(); i++) { countrytrim = countrytrim + aftertrimlist[i] + ','; countrytrims = countrytrim.removeEnd(','); System.debug('countrytrim::' + countrytrim); } for (Integer i = 0; i < countryValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.Country_Region__c IN (\'' + aftertrimlist[i] + '\''; if (i == countryValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == countryValLen - 1) optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\')'; else optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\''; } } } } //query based on Fan Postal Code value with option if (postalcodeoption != 'none') { if (postalcodeoption == 'not equal to') { postalcodetrims = postalcodevalue.trim(); optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.Postal_Code__c!=\'' + postalcodetrims + '\''; } else if (postalcodeoption == 'starts with') { List postalCodeValuesList = postalCodeValue.split(','); integer pCodeValLen = postalCodeValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < pCodeValLen; i++) { postalcodetrimfinal = postalCodeValuesList[i].trim(); aftertrimlist.add(postalcodetrimfinal); System.debug('aftertrimlist::' + aftertrimlist); } for (integer i = 0; i < aftertrimlist.size(); i++) { postalcodetrim = postalcodetrim + aftertrimlist[i] + ','; System.debug('postalcodetrim::' + postalcodetrim); postalcodetrims = postalcodetrim.removeEnd(','); System.debug('postalcodetrims::' + postalcodetrims); } for (Integer i = 0; i < pCodeValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.Postal_Code__c LIKE \'' + aftertrimlist[i] + '%' + '\''; if (i == pCodeValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == pCodeValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Postal_Code__c LIKE \'' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Postal_Code__c LIKE \'' + aftertrimlist[i] + '%' + '\''; } } } else if (postalcodeoption == 'contains') { List postalCodeValuesList = postalCodeValue.split(','); integer pCodeValLen = postalCodeValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < pCodeValLen; i++) { postalcodetrimfinal = postalCodeValuesList[i].trim(); aftertrimlist.add(postalcodetrimfinal); System.debug('aftertrimlist::' + aftertrimlist); } for (integer i = 0; i < aftertrimlist.size(); i++) { postalcodetrim = postalcodetrim + aftertrimlist[i] + ','; System.debug('postalcodetrim::' + postalcodetrim); postalcodetrims = postalcodetrim.removeEnd(','); System.debug('postalcodetrims::' + postalcodetrims); } for (Integer i = 0; i < pCodeValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and (Fan_ID__r.Postal_Code__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; if (i == pCodeValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == pCodeValLen - 1) optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Postal_Code__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\')'; else optFieldsQuery = optFieldsQuery + ' OR Fan_ID__r.Postal_Code__c LIKE \'' + '%' + aftertrimlist[i] + '%' + '\''; } } } else { List postalCodeValuesList = postalCodeValue.split(','); integer pCodeValLen = postalCodeValuesList.size(); list aftertrimlist = new List(); for (integer i = 0; i < pCodeValLen; i++) { postalcodetrimfinal = postalCodeValuesList[i].trim(); aftertrimlist.add(postalcodetrimfinal); System.debug('aftertrimlist::' + aftertrimlist); } for (integer i = 0; i < aftertrimlist.size(); i++) { postalcodetrim = postalcodetrim + aftertrimlist[i] + ','; System.debug('postalcodetrim::' + postalcodetrim); postalcodetrims = postalcodetrim.removeEnd(','); System.debug('postalcodetrimss::' + postalcodetrims); } for (Integer i = 0; i < pCodeValLen; i++) { if (i == 0) { optFieldsQuery = optFieldsQuery + ' and Fan_ID__r.Postal_Code__c IN (\'' + aftertrimlist[i] + '\''; if (i == pCodeValLen - 1) optFieldsQuery = optFieldsQuery + ')'; } else { if (i == pCodeValLen - 1) optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\')'; else optFieldsQuery = optFieldsQuery + ',\'' + aftertrimlist[i] + '\''; } } } } if (PromoID == '') { query = query + fieldsQuery + reqFieldsQuery + optFieldsQuery; } else { query = query + ' id,Subscription_ID__c,Promo_ID__r.Name,' + fieldsQuery + subhreqFieldsQuery + optFieldsQuery; } exp.Query__c = query.replace(' ', ' '); exp.City__c = citytrims; exp.State__c = statetrims; exp.Country__c = countrytrims; exp.Postal_Code__c = postalcodetrims; exp.Status__c = ExportTrackerHelper.UPLOAD_APPROVAL_STAGE; /* Validating query for any Query Exception */ try { Database.query(query + ' LIMIT 0'); insert exp; expObj = exp; Export__c ex = [SELECT id, Artist_Name__c FROM Export__c WHERE id = :exp.id]; artistname = ex.Artist_Name__c; } catch (Exception e) { SMELogger.logError(e); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.INFO, 'An error has occured, please try again. If the problem persists, please contact SET.') ); return null; } ExportBatch batch = new ExportBatch(artistname, expObj, selectFieldslistfinal, objectName); Database.executeBatch(batch, 2000); selectFieldslistfinal.clear(); PageReference pageRef = new PageReference('/' + expObj.Id); pageRef.setRedirect(true); return pageRef; } else { Export__c exp = new Export__c(); exp.Export_Type__c = exportName; exp.Approver__c = Approver; exp.Requester__c = Requester; if (BusinessJustificationPickVal != 'FR Other') { BusinessJustificationPickVal = BusinessJustificationPickVal.substring(3); exp.Business_Justification__c = BusinessJustificationPickVal; } else { exp.Business_Justification__c = BusinessJustification; } exp.Exclude_CCPA_Do_Not_Sell__c = showactiveccpa; exp.Recipient_Name__c = RecipientName; exp.Recipient_Company__c = RecipientCompany; exp.Recipient_Phone_Number__c = RecipientPhone; exp.Recipient_Email__c = RecipientEmail; exp.Territory_ID__c = comboTerritory; exp.Label_ID__c = comboLabel; exp.Artist_ID__c = comboArtist; exp.Form_ID__c = comboFormId; exp.Form_Name__c = FormName; exp.Form_Response_From_Date__c = fromDate; exp.Form_Response_To_Date__c = toDate; exp.Custom_Fields_1__c = cust1; exp.Custom_Fields_2__c = cust1; exp.Custom_Fields_3__c = cust1; exp.Custom_Fields_4__c = cust1; exp.Custom_Fields_5__c = cust1; exp.Custom_Fields_6__c = cust1; exp.Custom_Fields_7__c = cust1; exp.Custom_Fields_8__c = cust1; exp.Custom_Fields_9__c = cust1; exp.Custom_Fields_10__c = cust1; exp.Custom_Fields_11__c = cust1; exp.Custom_Fields_12__c = cust1; exp.Custom_Fields_13__c = cust1; exp.Custom_Fields_14__c = cust1; exp.Custom_Fields_15__c = cust1; exp.Custom_Fields_16__c = cust1; exp.Custom_Fields_17__c = cust1; exp.Custom_Fields_18__c = cust1; exp.Custom_Fields_19__c = cust1; exp.Custom_Fields_20__c = cust1; exp.Email__c = email; exp.Language__c = Language; exp.DSP__c = DSP; exp.Preferred_Genre__c = PreferredGenre; exp.Twitter_handle__c = Twitterhandle; exp.Mobile_Phone__c = MobilePhone; exp.Birthdate__c = Birthdate; exp.Birthday__c = Birthday; exp.Fan_Country__c = Country; exp.Fan_City__c = City; exp.Fan_State__c = State; exp.Postal_Code_1__c = PostalCode; exp.Address__c = Address; exp.Gender__c = Gender; exp.Age_Range__c = AgeRange; exp.Last_Name__c = LastName; exp.First_Name__c = FirstName; exp.Created_Date__c = CreatedDate; exp.Export_Note__c = Exportnote; exp.Exported_By__c = UserInfo.getName(); System.debug('values selected formresponse::' + selectFieldslistfinal.size()); if (FormName == true) selectFieldslistfinal.add('Form_Id__r.Form_Name__c'); if (CreatedDate == true) selectFieldslistfinal.add('CreatedDate'); if (email == true) selectFieldslistfinal.add('Email__c'); if (FirstName == true) selectFieldslistfinal.add('First_Name__c'); if (LastName == true) selectFieldslistfinal.add('Last_Name__c'); if (AgeRange == true) selectFieldslistfinal.add('Age_Range__c'); if (Gender == true) selectFieldslistfinal.add('Gender__c'); if (Address == true) { selectFieldslistfinal.add('Address_1__c'); selectFieldslistfinal.add('Address_2__c'); } if (City == true) selectFieldslistfinal.add('City__c'); if (State == true) selectFieldslistfinal.add('State__c'); if (Country == true) selectFieldslistfinal.add('Country_Region__c'); if (PostalCode == true) selectFieldslistfinal.add('Postal_Code__c'); if (Birthday == true) selectFieldslistfinal.add('Birthday_mm_dd__c'); if (Birthdate == true) selectFieldslistfinal.add('Birthday__c'); if (MobilePhone == true) selectFieldslistfinal.add('Mobile_Phone__c'); if (Twitterhandle == true) selectFieldslistfinal.add('Twitter_Handle__c'); if (Language == true) selectFieldslistfinal.add('Preferred_Language__c'); if (DSP == true) selectFieldslistfinal.add('DSP__c'); if (PreferredGenre == true) selectFieldslistfinal.add('Preferred_Genre__c'); if (cust1 == true) { selectFieldslistfinal.add('Custom_Form_Field1__c'); selectFieldslistfinal.add('Custom_Form_Field2__c'); selectFieldslistfinal.add('Custom_Form_Field3__c'); selectFieldslistfinal.add('Custom_Form_Field4__c'); selectFieldslistfinal.add('Custom_Form_Field5__c'); selectFieldslistfinal.add('Custom_Form_Field6__c'); selectFieldslistfinal.add('Custom_Form_Field7__c'); selectFieldslistfinal.add('Custom_Form_Field8__c'); selectFieldslistfinal.add('Custom_Form_Field9__c'); selectFieldslistfinal.add('Custom_Form_Field10__c'); selectFieldslistfinal.add('Custom_Form_Field11__c'); selectFieldslistfinal.add('Custom_Form_Field12__c'); selectFieldslistfinal.add('Custom_Form_Field13__c'); selectFieldslistfinal.add('Custom_Form_Field14__c'); selectFieldslistfinal.add('Custom_Form_Field15__c'); selectFieldslistfinal.add('Custom_Form_Field16__c'); selectFieldslistfinal.add('Custom_Form_Field17__c'); selectFieldslistfinal.add('Custom_Form_Field18__c'); selectFieldslistfinal.add('Custom_Form_Field19__c'); selectFieldslistfinal.add('Custom_Form_Field20__c'); } System.debug('values selected formresponses after::' + selectFieldslistfinal.size()); fieldsQuery = String.join(selectFieldslistfinal, ','); if (fromDate != null) { frDT = convertDateTime(fromDate); fromDateString = string.valueOf(frDT); fromdatelist = fromDateString.split(' '); frDateRange = fromdatelist[0] + 'T' + '00:00:00' + '.000+0000'; } if (toDate != null) { toDT = convertDateTime(toDate); toDateString = string.valueOf(toDT); todatelist = toDateString.split(' '); toDateRange = todatelist[0] + 'T' + '23:59:59' + '.000+0000'; } reqFieldsQuery = ' FROM Form_Response__c where Form_ID__c=\'' + exp.Form_ID__c + '\' '; if (showactiveccpa) { reqFieldsQuery += ' and Fan_id__r.CCPA_Do_Not_Sell__c = false '; } if (frDateRange != '') { reqFieldsQuery += ' and CreatedDate >= ' + frDateRange; } if (toDateRange != '') { reqFieldsQuery += ' and CreatedDate <= ' + toDateRange; } query = query + fieldsQuery + reqFieldsQuery + optFieldsQuery; exp.Query__c = query; exp.Status__c = ExportTrackerHelper.UPLOAD_APPROVAL_STAGE; if (ConfigUtils.getConfigBoolean(ConfigUtils.NODEJS_ACTIVE)) { String jsonResult = NodeJsHelper.performExportTrackerQuery(exp); if (jsonResult.startsWith('{"count":-1,')) { snowflakeWarning = true; return null; } else { insert exp; selectFieldslistfinal.clear(); System.enqueueJob(new ExportTrackerSnowflakeQueueable(jsonResult, exp.Id)); PageReference pageRef = new PageReference('/' + exp.Id); pageRef.setRedirect(true); return pageRef; } } else { /* Validating query for any Query Exception */ try { Database.query(query + ' LIMIT 0'); insert exp; expObj = exp; Export__c ex = [SELECT id, Artist_Name__c FROM Export__c WHERE id = :exp.id]; artistname = ex.Artist_Name__c; } catch (Exception e) { SMELogger.logError(e); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.INFO, 'An error has occured, please try again. If the problem persists, please contact SET.') ); return null; } objectName = 'Form_Response__c'; ExportBatch batch = new ExportBatch(artistname, expObj, selectFieldslistfinal, objectName); Database.executeBatch(batch, 2000); selectFieldslistfinal.clear(); PageReference pageRef = new PageReference('/' + expObj.Id); pageRef.setRedirect(true); return pageRef; } } } catch (Exception e) { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.INFO, 'An error has occured, please try again. If the problem persists, please contact SET.') ); SMELogger.logError(e); return null; } } public void getDefault() { if (exportName == 'none') { hideShow = false; def = true; showFr1 = false; showae1 = false; showSub1 = false; showsubDaterange = false; hideActivecheck = false; Showfile = false; } else if (exportName == 'Mailing List') { hideShow = true; Showfile = false; showFr = false; showSub = true; showFr1 = false; showae1 = false; showSub1 = true; hideformID = true; showsubDaterange = true; hideActivecheck = true; showactive = true; def = false; BusinessJustification = null; BusinessJustificationPickVal = 'none'; } else if (exportName == 'Form Response') { hideShow = true; Showfile = false; showFr = true; showSub = false; showFr1 = true; showSub1 = false; showae1 = false; showsubDaterange = false; def = false; BusinessJustification = null; BusinessJustificationPickVal = 'none'; } else if (exportName == 'AE Export') { hideShow = false; Showfile = true; showFr = false; showSub = false; showFr1 = false; showae1 = true; showSub1 = false; showsubDaterange = false; def = false; BusinessJustification = null; BusinessJustificationPickVal = 'none'; } Exportnote = ''; geocity = false; geocountry = false; objectName = ''; stateoption = null; cityoption = null; countryoption = null; postalcodeoption = null; fromDate = null; toDate = null; Active = null; PromoID = ''; BusinessJustification = null; normalFormId = ''; comboFormId = ''; MailingListName = false; CreatedDate = false; FirstName = false; LastName = false; AgeRange = false; Gender = false; Address = false; City = false; State = false; Country = false; PostalCode = false; Birthday = false; Birthdate = false; MobilePhone = false; Twitterhandle = false; InstagramHandle = false; PromoIdcheck = false; PromoDescription = false; Activecheck = false; Language = false; DSP = false; PreferredGenre = false; FormName = false; email = false; cust1 = false; textshow = false; cityDis = true; stateDis = true; countryDis = true; postalDis = true; businessFlag = true; showactiveccpa = true; selectFieldsSet.clear(); } public void getselected() { if (exportName == 'Mailing List') { if (email == true) selectFieldsSet.add('Fan_ID__r.Email__c'); else if (email == false) selectFieldsSet.remove('Fan_ID__r.Email__c'); if (FirstName == true) selectFieldsSet.add('Fan_ID__r.First_Name__c'); else if (FirstName == false) selectFieldsSet.remove('Fan_ID__r.First_Name__c'); if (LastName == true) selectFieldsSet.add('Fan_ID__r.Last_Name__c'); else if (LastName == false) selectFieldsSet.remove('Fan_ID__r.Last_Name__c'); if (AgeRange == true) selectFieldsSet.add('Fan_ID__r.Age_Range__c'); else if (AgeRange == false) selectFieldsSet.remove('Fan_ID__r.Age_Range__c'); if (Gender == true) selectFieldsSet.add('Fan_ID__r.Gender__c'); else if (Gender == false) selectFieldsSet.remove('Fan_ID__r.Gender__c'); if (Address == true) { selectFieldsSet.add('Fan_ID__r.Address_1__c'); selectFieldsSet.add('Fan_ID__r.Address_2__c'); } else if (Address == false) { selectFieldsSet.remove('Fan_ID__r.Address_1__c'); selectFieldsSet.remove('Fan_ID__r.Address_2__c'); } if (City == true) selectFieldsSet.add('Fan_ID__r.City__c'); else if (City == false) selectFieldsSet.remove('Fan_ID__r.City__c'); if (State == true) selectFieldsSet.add('Fan_ID__r.State__c'); else if (State == false) selectFieldsSet.remove('Fan_ID__r.State__c'); if (Country == true) selectFieldsSet.add('Fan_ID__r.Country_Region__c'); else if (Country == false) selectFieldsSet.remove('Fan_ID__r.Country_Region__c'); if (PostalCode == true) selectFieldsSet.add('Fan_ID__r.Postal_Code__c'); else if (PostalCode == false) selectFieldsSet.remove('Fan_ID__r.Postal_Code__c'); if (Birthday == true) selectFieldsSet.add('Fan_ID__r.Birthday_mm_dd__c'); else if (Birthday == false) selectFieldsSet.remove('Fan_ID__r.Birthday_mm_dd__c'); if (Birthdate == true) selectFieldsSet.add('Fan_ID__r.Birthdate__c'); else if (Birthdate == false) selectFieldsSet.remove('Fan_ID__r.Birthdate__c'); if (MobilePhone == true) selectFieldsSet.add('Fan_ID__r.Mobile_Phone__c'); else if (MobilePhone == false) selectFieldsSet.remove('Fan_ID__r.Mobile_Phone__c'); if (Twitterhandle == true) selectFieldsSet.add('Fan_ID__r.Twitter_Handle__c'); else if (Twitterhandle == false) selectFieldsSet.remove('Fan_ID__r.Twitter_Handle__c'); if (PromoID == '') { if (Activecheck == true) { selectFieldsSet.add('Active__c'); } else if (Activecheck == false) { selectFieldsSet.remove('Active__c'); } } if (InstagramHandle == true) selectFieldsSet.add('Fan_ID__r.Instagram_Handle__c'); else if (InstagramHandle == false) selectFieldsSet.remove('Fan_ID__r.Instagram_Handle__c'); if (Language == true) selectFieldsSet.add('Fan_ID__r.Preferred_Language__c'); else if (Language == false) selectFieldsSet.remove('Fan_ID__r.Preferred_Language__c'); if (DSP == true) selectFieldsSet.add('DSP__c'); else if (DSP == false) selectFieldsSet.remove('DSP__c'); if (PreferredGenre == true) selectFieldsSet.add('Preferred_Genre__c'); else if (PreferredGenre == false) selectFieldsSet.remove('Preferred_Genre__c'); if (CreatedDate == true) selectFieldsSet.add('CreatedDate'); else if (CreatedDate == false) selectFieldsSet.remove('CreatedDate'); if (MailingListName == true) selectFieldsSet.add('Mailing_List_Name__c'); else if (MailingListName == false) selectFieldsSet.remove('Mailing_List_Name__c'); if (PromoIdcheck == true) selectFieldsSet.add('Promo_ID_Value__c'); else if (PromoIdcheck == false) selectFieldsSet.remove('Promo_ID_Value__c'); if (PromoDescription == true) selectFieldsSet.add('Promo_Description_Value__c'); else if (PromoDescription == false) selectFieldsSet.remove('Promo_Description_Value__c'); } else if (exportName == 'Form Response') { if (FormName == true) selectFieldsSet.add('Form_Id__r.Form_Name__c'); else if (FormName == false) selectFieldsSet.remove('Form_Id__r.Form_Name__c'); if (CreatedDate == true) selectFieldsSet.add('CreatedDate'); else if (CreatedDate == false) selectFieldsSet.remove('CreatedDate'); if (email == true) selectFieldsSet.add('Email__c'); else if (email == false) selectFieldsSet.remove('Email__c'); if (FirstName == true) selectFieldsSet.add('First_Name__c'); else if (FirstName == false) selectFieldsSet.remove('First_Name__c'); if (LastName == true) selectFieldsSet.add('Last_Name__c'); else if (LastName == false) selectFieldsSet.remove('Last_Name__c'); if (AgeRange == true) selectFieldsSet.add('Age_Range__c'); else if (AgeRange == false) selectFieldsSet.remove('Age_Range__c'); if (Gender == true) selectFieldsSet.add('Gender__c'); else if (Gender == false) selectFieldsSet.remove('Gender__c'); if (Address == true) { selectFieldsSet.add('Address_1__c'); selectFieldsSet.add('Address_2__c'); } else if (Address == false) { selectFieldsSet.remove('Address_1__c'); selectFieldsSet.remove('Address_2__c'); } if (City == true) selectFieldsSet.add('City__c'); else if (City == false) selectFieldsSet.remove('City__c'); if (State == true) selectFieldsSet.add('State__c'); else if (State == false) selectFieldsSet.remove('State__c'); if (Country == true) selectFieldsSet.add('Country_Region__c'); else if (Country == false) selectFieldsSet.remove('Country_Region__c'); if (PostalCode == true) selectFieldsSet.add('Postal_Code__c'); else if (PostalCode == false) selectFieldsSet.remove('Postal_Code__c'); if (Birthday == true) selectFieldsSet.add('Birthday_mm_dd__c'); else if (Birthday == false) selectFieldsSet.remove('Birthday_mm_dd__c'); if (Birthdate == true) selectFieldsSet.add('Birthday__c'); else if (Birthdate == false) selectFieldsSet.remove('Birthday__c'); if (MobilePhone == true) selectFieldsSet.add('Mobile_Phone__c'); else if (MobilePhone == false) selectFieldsSet.remove('Mobile_Phone__c'); if (Twitterhandle == true) selectFieldsSet.add('Twitter_Handle__c'); else if (Twitterhandle == false) selectFieldsSet.remove('Twitter_Handle__c'); if (Language == true) selectFieldsSet.add('Preferred_Language__c'); else if (Language == false) selectFieldsSet.remove('Preferred_Language__c'); if (DSP == true) selectFieldsSet.add('DSP__c'); else if (DSP == false) selectFieldsSet.remove('DSP__c'); if (PreferredGenre == true) selectFieldsSet.add('Preferred_Genre__c'); else if (PreferredGenre == false) selectFieldsSet.remove('Preferred_Genre__c'); if (cust1 == true) { selectFieldsSet.add('Custom_Form_Field1__c'); selectFieldsSet.add('Custom_Form_Field2__c'); selectFieldsSet.add('Custom_Form_Field3__c'); selectFieldsSet.add('Custom_Form_Field4__c'); selectFieldsSet.add('Custom_Form_Field5__c'); selectFieldsSet.add('Custom_Form_Field6__c'); selectFieldsSet.add('Custom_Form_Field7__c'); selectFieldsSet.add('Custom_Form_Field8__c'); selectFieldsSet.add('Custom_Form_Field9__c'); selectFieldsSet.add('Custom_Form_Field10__c'); selectFieldsSet.add('Custom_Form_Field11__c'); selectFieldsSet.add('Custom_Form_Field12__c'); selectFieldsSet.add('Custom_Form_Field13__c'); selectFieldsSet.add('Custom_Form_Field14__c'); selectFieldsSet.add('Custom_Form_Field15__c'); selectFieldsSet.add('Custom_Form_Field16__c'); selectFieldsSet.add('Custom_Form_Field17__c'); selectFieldsSet.add('Custom_Form_Field18__c'); selectFieldsSet.add('Custom_Form_Field19__c'); selectFieldsSet.add('Custom_Form_Field20__c'); } else if (cust1 == false) { selectFieldsSet.remove('Custom_Form_Field1__c'); selectFieldsSet.remove('Custom_Form_Field2__c'); selectFieldsSet.remove('Custom_Form_Field3__c'); selectFieldsSet.remove('Custom_Form_Field4__c'); selectFieldsSet.remove('Custom_Form_Field5__c'); selectFieldsSet.remove('Custom_Form_Field6__c'); selectFieldsSet.remove('Custom_Form_Field7__c'); selectFieldsSet.remove('Custom_Form_Field8__c'); selectFieldsSet.remove('Custom_Form_Field9__c'); selectFieldsSet.remove('Custom_Form_Field10__c'); selectFieldsSet.remove('Custom_Form_Field11__c'); selectFieldsSet.remove('Custom_Form_Field12__c'); selectFieldsSet.remove('Custom_Form_Field13__c'); selectFieldsSet.remove('Custom_Form_Field14__c'); selectFieldsSet.remove('Custom_Form_Field15__c'); selectFieldsSet.remove('Custom_Form_Field16__c'); selectFieldsSet.remove('Custom_Form_Field17__c'); selectFieldsSet.remove('Custom_Form_Field18__c'); selectFieldsSet.remove('Custom_Form_Field19__c'); selectFieldsSet.remove('Custom_Form_Field20__c'); } } else { if (email == true) selectFieldsSet.add('Email__c'); else if (email == false) selectFieldsSet.remove('Email__c'); if (FirstName == true) selectFieldsSet.add('First_Name__c'); else if (FirstName == false) selectFieldsSet.remove('First_Name__c'); if (LastName == true) selectFieldsSet.add('Last_Name__c'); else if (LastName == false) selectFieldsSet.remove('Last_Name__c'); if (Address == true) { selectFieldsSet.add('Address_1__c'); selectFieldsSet.add('Address_2__c'); } else if (Address == false) { selectFieldsSet.remove('Address_1__c'); selectFieldsSet.remove('Address_2__c'); } if (City == true) selectFieldsSet.add('City__c'); else if (City == false) selectFieldsSet.remove('City__c'); if (State == true) selectFieldsSet.add('State__c'); else if (State == false) selectFieldsSet.remove('State__c'); if (Country == true) selectFieldsSet.add('Country_Region__c'); else if (Country == false) selectFieldsSet.remove('Country_Region__c'); if (PostalCode == true) selectFieldsSet.add('Postal_Code__c'); else if (PostalCode == false) selectFieldsSet.remove('Postal_Code__c'); if (MobilePhone == true) selectFieldsSet.add('Mobile_Phone__c'); else if (MobilePhone == false) selectFieldsSet.remove('Mobile_Phone__c'); if (geocity == true) selectFieldsSet.add('Geo_City__c'); else if (geocity == false) selectFieldsSet.remove('Geo_City__c'); if (geocountry == true) selectFieldsSet.add('Geo_Country__c'); else if (geocountry == false) selectFieldsSet.remove('Geo_Country__c'); } } public void getDisable() { System.debug('Before::' + showactiveccpa); System.debug('BusinessJustificationPickVal::' + BusinessJustificationPickVal); if ( BusinessJustificationPickVal == 'FR Other' || BusinessJustificationPickVal == 'ML Other' || BusinessJustificationPickVal == 'AE Other' ) { showactiveccpa = true; textshow = true; def = true; } else if ( (BusinessJustificationPickVal != 'FR Other' || BusinessJustificationPickVal != 'ML Other') && (BusinessJustificationPickVal == 'ML Advertising Studio Retargeting' || BusinessJustificationPickVal == 'FR Advertising Studio Retargeting') ) { showactiveccpa = false; textshow = false; def = true; } else { showactiveccpa = true; textshow = false; def = true; } if (cityoption == 'None') { cityDis = true; cityvalue = ''; citytrims = ''; } else if (cityoption != 'None') cityDis = false; if (stateoption == 'None') { stateDis = true; statevalue = ''; statetrims = ''; } else if (stateoption != 'None') stateDis = false; if (countryoption == 'None') { countryDis = true; countryvalue = ''; countrytrims = ''; } else if (countryoption != 'None') countryDis = false; if (postalcodeoption == 'None') { postalDis = true; postalcodevalue = ''; postalcodetrims = ''; } else if (postalcodeoption != 'None') postalDis = false; } public void dateValidation() { date dt = system.today().addYears(-20); date today = system.today(); system.debug('today ' + today); system.debug('dt' + dt); system.debug('fromDate' + fromDate); system.debug('toDate' + toDate); if (toDate == null || subhtoDate == null) { toDateRange = ''; } if (fromDate == null || subhfromDate == null) { frDateRange = ''; } if (toDate > system.today() || fromDate > system.today()) { system.debug('date cannot be future'); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Selected date cannot be greater than Today.') ); inputValue = false; } else if (fromDate < dt || toDate < dt) { system.debug('fromDate less than 2000'); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'From date should not be less than year 2000.') ); inputValue = false; } else if (fromDate > toDate) { system.debug('from date higher than toDate'); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'From date cannot be greater than To date.') ); inputValue = false; } } public void PromoIdValidation() { if (String.isNotBlank(PromoID) && !PromoID.startsWithIgnoreCase('PID')) { system.debug('PromoID value is in Incorrect format'); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please enter Promo ID in valid format (Ex: PID00000).') ); inputValue = false; } else if (String.isNotBlank(PromoID) && PromoID.startsWithIgnoreCase('PID')) { hideformID = false; showsubDaterange = false; showDaterange = true; hideActivecheck = false; showactivetrue = false; showactive = true; fromDate = null; toDate = null; subhfromDate = null; subhtoDate = null; toDateString = ''; fromDateString = ''; normalFormId = ''; Activecheck = false; } else { hideActivecheck = true; hideformID = true; showsubDaterange = true; showDaterange = false; showactivetrue = false; showactive = true; fromDate = null; toDate = null; subhfromDate = null; subhtoDate = null; toDateString = ''; fromDateString = ''; } } public void formIdValidation() { if ( String.isNotBlank(normalFormId) && !normalFormId.startsWith('a0Q') && (normalFormId.length() != 15 || normalFormId.length() != 18) ) { system.debug('FormId value is in Incorrect format'); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please enter 15 or 18 digit valid Form ID.') ); inputValue = false; } } public void validateEmail() { String emailRegex = '^[A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$'; Pattern MyPattern = Pattern.compile(emailRegex); Matcher MyMatcher = MyPattern.matcher(RecipientEmail.trim()); if (!(MyMatcher.matches())) { Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.Info, 'Please enter email in valid format.')); inputValue = false; } } public DateTime convertDateTime(date chkDate) { Integer d = chkDate.day(); Integer mo = chkDate.month(); Integer yr = chkDate.year(); DateTime DT = DateTime.newInstance(yr, mo, d); return DT; } public PageReference redirectToList() { Schema.DescribeSObjectResult result = Export__c.SObjectType.getDescribe(); PageReference pageRef = new PageReference('/' + result.getKeyPrefix() + '/o'); pageRef.setRedirect(true); return pageRef; } public list getMLExportReasons() { list opt = new List(); schema.DescribeFieldResult fd = Export__c.Mailing_List_Export_Reasons__c.getdescribe(); //Get all picklist value in a list of scheme.picklistentry type list pc = fd.getpicklistvalues(); //Add each value in the list of selectoption opt.add(new selectoption('None', '-Select-')); for (schema.picklistentry f : pc) { if ( (profileName == 'UserAdmin' || profileName == 'System Administrator') && f.getvalue() == 'Advertising Studio Retargeting' ) { opt.add(new selectoption(f.getlabel(), f.getvalue())); } else if (f.getvalue() != 'Advertising Studio Retargeting') { opt.add(new selectoption(f.getlabel(), f.getvalue())); } } System.debug('Options' + opt); return opt; } public list getFRExportReasons() { list opt = new List(); schema.DescribeFieldResult fd = Export__c.Form_Response_Export_Reasons__c.getdescribe(); //Get all picklist value in a list of scheme.picklistentry type list pc = fd.getpicklistvalues(); //Add each value in the list of selectoption opt.add(new selectoption('None', '-Select-')); for (schema.picklistentry f : pc) { if ( (profileName == 'UserAdmin' || profileName == 'System Administrator') && f.getvalue() == 'Advertising Studio Retargeting' ) { opt.add(new selectoption(f.getlabel(), f.getvalue())); } else if (f.getvalue() != 'Advertising Studio Retargeting') { opt.add(new selectoption(f.getlabel(), f.getvalue())); } } System.debug('Options' + opt); return opt; } public list getAEExportReasons() { list opt = new List(); schema.DescribeFieldResult fd = Export__c.AE_Export_Reasons__c.getdescribe(); //Get all picklist value in a list of scheme.picklistentry type list pc = fd.getpicklistvalues(); //Add each value in the list of selectoption opt.add(new selectoption('None', '-Select-')); for (schema.picklistentry f : pc) { opt.add(new selectoption(f.getlabel(), f.getvalue())); } System.debug('Options' + opt); return opt; } /* Dummy method for ajax call - Do Not Delete */ public void fileuploadstatus() { } public void importdata() { Export__c exp = new Export__c(); selectFieldsList.addAll(selectFieldsSet); selectFieldLen = selectFieldsList.size(); if (exportName == 'AE Export') { if ( Approver == '' || Requester == '' || BusinessJustificationPickVal == 'None' || RecipientName == '' || RecipientCompany == '' || RecipientEmail == '' || RecipientPhone == '' || AEArtistslist == '' || AElabels == '' || AEFanActionsChannels == '' || AEDateRangeofActivity == '' ) { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please fill all the required fields.') ); } else if (BusinessJustificationPickVal == 'AE Other' && BusinessJustification == '') { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please fill Business Justification.') ); } else if (filestatus == false) { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.Info, 'Please upload the file to import.') ); } else { exp.Export_Type__c = exportName; exp.Approver__c = Approver; exp.Requester__c = Requester; if (BusinessJustificationPickVal != 'AE Other') { BusinessJustificationPickVal = BusinessJustificationPickVal.substring(3); exp.Business_Justification__c = BusinessJustificationPickVal; } else { exp.Business_Justification__c = BusinessJustification; } exp.Recipient_Name__c = RecipientName; exp.Recipient_Company__c = RecipientCompany; exp.Recipient_Phone_Number__c = RecipientPhone; exp.Recipient_Email__c = RecipientEmail; exp.Artists_List__c = AEArtistslist; exp.Labels__c = AElabels; exp.Fan_Actions_Channels__c = AEFanActionsChannels; exp.Date_Range_of_Activity__c = AEDateRangeofActivity; exp.Email__c = emailcheck; exp.First_Name__c = FirstName; exp.Last_Name__c = LastName; exp.Address__c = Address; exp.Fan_City__c = City; exp.Fan_State__c = State; exp.Fan_Country__c = Country; exp.Postal_Code_1__c = Postalcode; exp.Mobile_Phone__c = MobilePhone; exp.Exported_By__c = UserInfo.getName(); exp.Export_Note__c = Exportnote; exp.Geo_City__c = geocity; exp.Geo_Country__c = geocountry; insert exp; impexpid = exp.id; } } } public Pagereference reDirectimport() { Export__c exp = [SELECT id, Export_Uploaded__c FROM Export__c WHERE id = :importexpid]; exp.Export_Uploaded__c = true; update exp; return new Pagereference('/' + importexpid); } @RemoteAction public static String processChunk( String parentId, String attachmentId, String attachmentName, String base64ChunkPayload, String description, String fileUploadFlag ) { if (parentId != null) { Export__c exp = getExportUpload(parentId); if (exp != null) { if (base64ChunkPayload != null) { Attachment attachment = getAttachment(attachmentId); String newBody = ''; if (attachment.Body != null) { newBody = attachment.Body.toString(); } newBody += base64ChunkPayload; attachment.Body = Blob.valueOf(newBody); if (attachmentId == null) { attachment.Name = attachmentName; attachment.parentId = exp.Id; attachment.Description = description; } upsert attachment; return attachment.Id; } else { return 'Attachment Body was null'; } } else { return 'Parent record could not be found'; } } else { return 'Parent Id was null'; } } @TestVisible private static Attachment getAttachment(String attachmentId) { List attachments = [SELECT Id, Body FROM Attachment WHERE Id = :attachmentId]; if (attachments.isEmpty()) { Attachment a = new Attachment(); return a; } else { return attachments[0]; } } @TestVisible private static Export__c getExportUpload(String expid) { List exports = [SELECT Id FROM Export__c WHERE Id = :expid]; if (exports.isEmpty()) { return null; } else { return exports[0]; } } }