This is possible by using default value plugin and overriding the lookup component.Please find the code below
global class DefaultValues extends zqu.CreateQuoteController.PopulateDefaultFieldValuePlugin{
//Helpers for Quote Type attributes
private static final String QT_SUB = 'Subscription';
private static final String QT_AMEND = 'Amendment';
private static final String QT_RENEW = 'Renewal';
//Helpers for URL Params
private static final String URL_QUOTETYPE = 'quoteType';
private static final String URL_QUOTEID = 'quoteId';
private static final String URL_SUBID = 'subscriptionId';
global override void populateDefaultFieldValue(SObject record, zqu.PropertyComponentController.ParentController pcc){
final String FUNC_STR = DEBUG_STR+'[populateDefaultFieldValue] ';
//Leverage OOTB defaulting
if(!Test.isRunningTest()) {
super.populateDefaultFieldValue(record, pcc);
}
Id accountId = (Id) record.get('zqu__Account__c');
Id opportunityId = (Id) record.get('zqu__Opportunity__c');
System.debug(FUNC_STR+' opportunityId '+opportunityId);
zqu.LookupComponentOptions billToOptions;
zqu.LookupComponentOptions soldToOptions;
//if the name is longer than 80 characters, we trim it
String quoteName = String.valueOf(record.get('Name'));
if(String.isNotBlank(quoteName) && quoteName.length()>80){
record.put('Name',quoteName.left(80));
}
//if the amendment name is longer than 80 characters, we trim it
String amendmentName = String.valueOf(record.get('zqu__Amendment_Name__c'));
if(String.isNotBlank(amendmentName) && amendmentName.length()>80){
record.put('zqu__Amendment_Name__c', amendmentName.left(80));
}
String quoteType = ApexPages.currentPage().getParameters().get(URL_QUOTETYPE);
quoteType = (String.isNotBlank(quoteType)) ? quoteType : QT_SUB;
Zuora__Subscription__c sub;
zqu__quote__c quote;
// perform org dependent functionality
performOrgSpecificOverrides(record, pcc);
record.put('zqu__InvoiceSeparately__c', true);
if(quoteType.equalsIgnoreCase(QT_SUB)){
record.put('zqu__BillingBatch__c', 'Batch1');
record.put('zqu__RenewalSetting__c','RENEW_WITH_SPECIFIC_TERM');
record.put('zqu__Subscription_Term_Type__c', 'Termed');
record.put('zqu__PaymentTerm__c','Due Upon Receipt');
record.put('zqu__PaymentMethod__c', 'Check');
record.put('zqu__InitialTerm__c', 12);
record.put('zqu__RenewalTerm__c', 12);
record.put('zqu__InitialTermPeriodType__c', 'Month');
record.put('zqu__RenewalTermPeriodType__c', 'Month');
record.put('zqu__QuoteBusinessType__c', 'New');
}
if(quoteType.equalsIgnoreCase(QT_AMEND)){
record.put('zqu__QuoteBusinessType__c', 'Upsell');
}
if(quoteType.equalsIgnoreCase(QT_RENEW)){
record.put('zqu__QuoteBusinessType__c', 'Renewal');
}
List<Id> acctList = new List<Id>();
acctList.add(accountId);
String soqlFragment = buildSqlFragment(acctList);
// Before retrieving the lookup options, needs to populate the map first
if(!Test.isRunningTest()){
super.setLookupOptions(pcc);
// Now retrieve the lookup component options
billToOptions = super.getLookupOption('zqu__BillToContact__c');
soldToOptions = super.getLookupOption('zqu__SoldToContact__c');
billToOptions.lookupComponentControllerName = 'Z_LookupComponentController';
soldToOptions.lookupComponentControllerName = 'Z_LookupComponentController';
}else{
billToOptions = new zqu.LookupComponentOptions();
soldToOptions = new zqu.LookupComponentOptions();
}
System.debug(FUNC_STR+'Bill To Contact options: '+super.getLookupOption('zqu__BillToContact__c'));
System.debug(FUNC_STR+'Sold To Contact options: '+super.getLookupOption('zqu__SoldToContact__c'));
}
public String buildSqlFragment(List<Id> acctList){
String acctIdSoqlFragment = 'accountId = ';
//build the soql fragment in the form ('a4fa0000000KzbV','a4fa0000000KzbW')
for(integer i = 0; i < acctList.size(); i++){
if (i == acctList.size()-1) {
acctIdSoqlFragment += '\''+ acctList.get(i) +'\'';
}else{
acctIdSoqlFragment += '\''+ acctList.get(i) +'\' OR accountId = ';
}
}
System.debug(acctIdSoqlFragment);
return acctIdSoqlFragment;
}
private void performOrgSpecificOverrides(SObject record, zqu.PropertyComponentController.ParentController pcc){
}
}
Lookup Component
global class Z_LookupComponentController extends zqu.LookupComponentController{
public zqu.LookupComponentOptions optionsForLookup {get;set;}
private static final String MASTER_RECORDTYPEID = Contact.SObjectType.getDescribe().getRecordTypeInfosByName().get('Master').getRecordTypeId();
public static zqu.LookupComponentOptions createContactLookupComponentOptions(Id oppId, Id accId, Contact soldToContact) {
zqu.LookupComponentOptions optionsForShipTo = new zqu.LookupComponentOptions();
optionsForShipTo.objectName = 'Contact';
optionsForShipTo.Id = 'soldToContact';
optionsForShipTo.isEditMode = true;
optionsForShipTo.isRequired = true;
optionsForShipTo.lookupComponentControllerName = 'Z_LookupComponentController';
optionsForShipTo.recordTypeId = MASTER_RECORDTYPEID;
optionsForShipTo.popupWindowTitle = 'Sold To Contact Lookup';
optionsForShipTo.soqlFragment = buildSoqlFragment(accId);
if (soldToContact != null) {
optionsForShipTo.targetId = soldToContact.Id;
optionsForShipTo.targetName = soldToContact.Name;
}
return optionsForShipTo;
}
public static String buildSoqlFragment (Id accountId){
List<id> accList = new List<id>();
String accIdSoqlFragment;
accList.add(accountId);
//build the soql fragment in the form ('a4fa0000000KzbV','a4fa0000000KzbW')
for(integer i = 0; i < accList.size(); i++){
if (i == accList.size()-1) {
accIdSoqlFragment += '\''+ accList.get(i) +'\'';
}else{
accIdSoqlFragment += '\''+ accList.get(i) +'\'';
}
}
return accIdSoqlFragment;
}
}
Once the default values plugin Class is registered in Component registration we will be able to see all the contacts from salesforce once lookup icon is clicked in the bill to and sold to contacts
... View more