0

Hi I have to query a record information of the customer. Based on the number of Order the customer submits it should retrieve the same.

Please find my query below In the above code i am using the static value to get the same record. I want to make it Dynamic. Please Advise.

I tried the Below logic it still returns me only one at a time.

 if(OrderNumbers!=null){
         String[] splits = OrderNumbers.split(',');
        String succMes = (splits.size() >1 ? 'Thank you for your order request.  Your Order Numbers are ' : 'Thank you for your order request.  Your Order Number is ');
        Set<String> orderIds = new Set<String>();
        for(Integer i = 0; i< splits.size(); i++){
            orderIds.add(splits[i]);
        }
        newOrders = [Select id,
                     Order_Contact__c,
                     OrderNumber,
                     Order_Contact_Phone__c,
                     Order_Contact_Email__c,
                     Type,
                     Rush_Order__c,
                     Type_Of_Order__c,
                     Training_Required__c,
                     Type_Of_Clock__c,
                     Number_of_Clock_Required__c,
                     Ship_to__c,Shipping_Attention__c,
                     Shipping_Attention_Email__c,
                     Shipping_Attention_Phone__c,
                     Shipping_Street__c,
                     Suite_Floor_Address_2__c,
                     Shipping_City__c,
                     Shipping_State__c,
                     Shipping_Postal_Code__c,
                     Shipping_Country__c,
                     Clock_Location_Restriction__c,
                     IP_Restricted__c,
                     Type_of_Clock_Requested__c,
                     Connection_Type__c,
                     Static_IP_Address__c,
                     Static_Subnet_Mask__c,
                     Static_Gateway_Adress__c,
                     DNS1__c,
                     DNS2__c,
                     Branch_Name__c,
                     Branch_number__c,
                     Associates_to_enter_time__c,
                     First_email_reminder_day__c,
                     Second_email_reminder_day__c,
                     PTA_First_email_Day__c,
                     PTA_Second_email_Day__c,
                     PTA_Escalation_email_Day__c,
                     StartTime_for_the_Last_shift_week_time__c,
                     PTA_First_email_Time__c,
                     PTA_Second_email_Time__c,
                     PTA_Escalation_email_Time__c,
                     First_shift_of_the_week_s_start_time__c,
                     Associates_to_enter_late_time__c,
                     i_How_Many_Weeks__c,
                     Last_day_of_your_pay_week__c,
                     Set_up_for_Group_Timesheet__c,
                     Clients_Branch_Name__c,
                     Clients_Branch_ID__c,
                     GT_How_do_they_need_to_enter_time__c,
                     GT_First_name_of_time_submitter__c,
                     GT_Last_name_of_time_submitter__c,
                     Submitter_s_email_address__c,
                     Submitter_First_reminder_day__c,
                     Submitter_Second_reminder_day__c,
                     Auto_approved_submitted_Group_Timesheet__c,
                     Over_Time_Rules__c,
                     Notes__c,
                     Customer_Name__c,
                     Business_Unit_Or_Accounting_number__c,
                     Site_ID_or_Branch_ID_Number__c,
                     Name_of_Clock_Location__c,
                     Site_Street_Address_1__c,
                     Site_Street_Address_2__c,
                     Site_City__c,
                     Site_State__c,
                     Site_ZIP__c,
                     Site_Country_if_not_USA__c,
                     Site_TimeZone__c,
                     Number_of_Employees__c,
                     Pay_Period__c,
                     First_Day_of_payroll_Week__c,
                     First_shift_of_the_week_s_start_day__c,
                     StartTime_for_the_Last_shift_of_the_week__c,
                     Third_Shift_employee_at_the_site__c,
                     OverTime_Rules__c,
                     State_OT_Rules__c,
                     Daily_OT_after_How_many_hours__c,
                     Weekly_OT_after_how_many_hours__c,
                     Does_the_7th_day_rule_apply__c,
                     Non_Standard_Notes__c,
                     Time_Tracking_Options__c,
                     Grace_Period_Before_Shift__c,
                     Grace_Period_After_Shift__c,
                     Meal_Break__c,
                     Length_of_the_meal_break__c,
                     Min_hours_worked_for_auto_meal_deduction__c,
                     California_Meal_Prompts__c,
                     Are_Departments_sent_in_Integration_file__c,
                     Special_Pay_Policies_or_Requests__c 
                     from Order where OrderNumber IN :orderIds];  

Here is the code that defines the OrderNumbers

public without sharing class NewOrderSuccessController {

public List<Order> newOrders{get;set;}
//public List<OrderTraining__c> orderTrainings{get;set;}
public String accountId{get; set;}

public NewOrderSuccessController(ApexPages.StandardController controller)
{

    String OrderNumbers = GetValueFromParam('OrderNumbers'); 
    accountId = '';
    if(OrderNumbers.contains(';'))
    {
        String[] splitNumbers = OrderNumbers.split(';');
        OrderNumbers = splitNumbers[0];
        String str1 = splitNumbers[1];            

       /* if(str1.contains('CID'))
        {
            String[] splitaccount = str1.split('=');
            accountId = splitaccount[1];
        } */       
    }

    if(OrderNumbers!=null){
         String[] splits = OrderNumbers.split(',');
        String succMes = (splits.size() >1 ? 'Thank you for your order request.  Your Order Numbers are ' : 'Thank you for your order request.  Your Order Number is ');
  • What is the content of OrderNumbers ? – Phil Hawthorn Dec 2 '16 at 12:40
  • @PhilHawthorn The content of the OrderNumbers is {00002928,00002929,00002930} – Samuel Robert Dec 2 '16 at 12:54
  • 1
    So if OrderNumbers is an array of Strings then your query could just be WHERE OrderNumber IN :OrderNumbers – Phil Hawthorn Dec 2 '16 at 13:05
  • @PhilHawthorn Yes I was trying that before. In VF page we have option where the customer will be allowed to order multiple clocks, When they submit there will be multiple separate order get created for no . of clock they selected. But the order number retrieved only one – Samuel Robert Dec 2 '16 at 13:18
  • Check your debug logs...how many records does it say its retreiving? – Phil Hawthorn Dec 2 '16 at 13:20
2

From information supplied in comments, it your OrderNumbers array is:

["00002922"," 00002923"," 00002924"," 00002925"," 00002926"]

Therefore, when converting that to your Set:

    Set<String> orderIds = new Set<String>();
    for(Integer i = 0; i< splits.size(); i++){
        orderIds.add(splits[i]);
    }

It is also including the spaces meaning that only the first item in the array is a valid Order Number. So, you can change your code to:

    Set<String> orderIds = new Set<String>();
    for(String orderNo : OrderNumbers){
        orderIds.add(orderNo.replaceAll(' ', ''));
    }

And at least valid Order Numbers will be queried for.

  • 1
    That fixed the issue and Provides me the solution. Thanks A lot. – Samuel Robert Dec 2 '16 at 15:18
0

You can use Dynamic SOQL,please refer here .Also please check if the orderIds still contains value after split.

for(Integer i = 0; i< splits.size(); i++){
            orderIds.add(splits[i]);
}

if(orderIds.size()>0){
String sql ='Select id,
                         Order_Contact__c,
                         OrderNumber,
                         Order_Contact_Phone__c,
                         Order_Contact_Email__c,
                         Type,
                         Rush_Order__c,
                         Type_Of_Order__c,
                         Training_Required__c,
                         Type_Of_Clock__c,
                         Number_of_Clock_Required__c,
                         Ship_to__c,Shipping_Attention__c,
                         Shipping_Attention_Email__c,
                         Shipping_Attention_Phone__c,
                         Shipping_Street__c,
                         Suite_Floor_Address_2__c,
                         Shipping_City__c,
                         Shipping_State__c,
                         Shipping_Postal_Code__c,
                         Shipping_Country__c,
                         Clock_Location_Restriction__c,
                         IP_Restricted__c,
                         Type_of_Clock_Requested__c,
                         Connection_Type__c,
                         Static_IP_Address__c,
                         Static_Subnet_Mask__c,
                         Static_Gateway_Adress__c,
                         DNS1__c,
                         DNS2__c,
                         Branch_Name__c,
                         Branch_number__c,
                         Associates_to_enter_time__c,
                         First_email_reminder_day__c,
                         Second_email_reminder_day__c,
                         PTA_First_email_Day__c,
                         PTA_Second_email_Day__c,
                         PTA_Escalation_email_Day__c,
                         StartTime_for_the_Last_shift_week_time__c,
                         PTA_First_email_Time__c,
                         PTA_Second_email_Time__c,
                         PTA_Escalation_email_Time__c,
                         First_shift_of_the_week_s_start_time__c,
                         Associates_to_enter_late_time__c,
                         i_How_Many_Weeks__c,
                         Last_day_of_your_pay_week__c,
                         Set_up_for_Group_Timesheet__c,
                         Clients_Branch_Name__c,
                         Clients_Branch_ID__c,
                         GT_How_do_they_need_to_enter_time__c,
                         GT_First_name_of_time_submitter__c,
                         GT_Last_name_of_time_submitter__c,
                         Submitter_s_email_address__c,
                         Submitter_First_reminder_day__c,
                         Submitter_Second_reminder_day__c,
                         Auto_approved_submitted_Group_Timesheet__c,
                         Over_Time_Rules__c,
                         Notes__c,
                         Customer_Name__c,
                         Business_Unit_Or_Accounting_number__c,
                         Site_ID_or_Branch_ID_Number__c,
                         Name_of_Clock_Location__c,
                         Site_Street_Address_1__c,
                         Site_Street_Address_2__c,
                         Site_City__c,
                         Site_State__c,
                         Site_ZIP__c,
                         Site_Country_if_not_USA__c,
                         Site_TimeZone__c,
                         Number_of_Employees__c,
                         Pay_Period__c,
                         First_Day_of_payroll_Week__c,
                         First_shift_of_the_week_s_start_day__c,
                         StartTime_for_the_Last_shift_of_the_week__c,
                         Third_Shift_employee_at_the_site__c,
                         OverTime_Rules__c,
                         State_OT_Rules__c,
                         Daily_OT_after_How_many_hours__c,
                         Weekly_OT_after_how_many_hours__c,
                         Does_the_7th_day_rule_apply__c,
                         Non_Standard_Notes__c,
                         Time_Tracking_Options__c,
                         Grace_Period_Before_Shift__c,
                         Grace_Period_After_Shift__c,
                         Meal_Break__c,
                         Length_of_the_meal_break__c,
                         Min_hours_worked_for_auto_meal_deduction__c,
                         California_Meal_Prompts__c,
                         Are_Departments_sent_in_Integration_file__c,
                         Special_Pay_Policies_or_Requests__c 
                         from Order where OrderNumber IN :orderIds';
    List<Order> newOrders= Database.query(string);

}
  • 2
    I think the question is possibly misleading, I think the OP is trying to retrieve multiple rows of data rather than making his query Dynamic in the way that you're thinking – Phil Hawthorn Dec 2 '16 at 13:04
  • @unidha the query returned null as it did not retrieve any record from Order Object – Samuel Robert Dec 2 '16 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.