• cmtgolf05
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 6
    Replies

I have created a custom variable from a query on my controller. I am now trying to display this variable on the Apex page in a pageBlockTable. Here is my code:

 

Apex Page:

 

<apex:page controller="groupbytestcontroller">

<apex:form >

<apex:pageBlock title="" id="pageBlock">
<apex:pageBlockTable value="{!XXX}" var="summary">
<apex:column Headervalue="Sum Refund" >
<apex:outputText value="{!sumrefund}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>


</apex:form>

Sum Refund is <apex:outputText value=" {!sumrefund}"/>

</apex:page>

 

Controller:

public with sharing class groupbytestcontroller {

public decimal sumrefund { get; private set; }

List<Refunds__c> myRNDS;
public List<Refunds__c> getXXX() {

AggregateResult[] myRNDS = [Select SUM(Total_Refund__c)xx From Refunds__c Where OppLineItem_Id__c = '00ka000000iBrhG' ];

for (AggregateResult cus:myRNDS){

sumrefund = (Decimal) cus.get('xx');


system.debug('SUM Refund Is '+ sumrefund);

}
return null;
}

}

 

As you can see on the apex page I try to call the variable sumrefund two times. One inside of the pageblock table and one outside of the table. The one outside of the table/form works and displays the correct value. However the one inside the table does not display anything. Also if is substute the collumn headervalue with the variable it will show there as well, it just will not show in its collumn.

 

Any help?

 I am trying for the first time to use the group by function in SOQL. However I am getting the following error with the code I have:

 

"Sobject constructor must use name=value pairs"

 

Here is my code:

 

List<OpportunityLineItem> myOCR;

public List<OpportunityLineItem> getOpportunity() {
if (myOCR == null) { AggregateResult[] myOCR = [Select SUM(ProductTotal__c), SUM(Supplier_Price__c), Opportunity.Sales_Initials__c from                     OpportunityLineItem where opportunity.closedate = YESTERDAY group by Opportunity.Sales_Initials__c ];
for (AggregateResult ar : myOCR) {
myOCR.add(new OpportunityLineItem(string.valueof(myOCR.get('Opportunity.Sales_Initials__c')),
String.valueOf(myOCR.get('ProductTotal__c')),String.valueOf(myOCR.get('Supplier_Price__c'))));

}

}

return myOCR;
}

 

It is indicating the error is coming from "myOCR.add(new ......." Line

 

Any Help?

 

Thank you,

I have built a custom report using Visual Force. I am trying to give the end user the ability to sort the report by a few different fields. I have created a pick list on a Custom Object that contains the field names (API Names) that the user can sort by. In my class I query the Custom object to get the field the end user wants to sort by, I store that in a variable. I then want to use that vairble to order by my SOQL statement that builds the report.

 

Here is my Query to build the report:

 

String shipping = '%Small Parcel%';
String Stage = 'Closed Won';

String Query = 'SELECT Estimated_Ship_Date__c, Date_Shipped__c, Opportunity.CloseDate, Opportunity.Account.Name, From OpportunityLineItem WHERE Opportunity.StageName = :Stage and (NOT ShippingType__c like :shipping) ORDER BY ';
Query += SortBy ;

List<OpportunityLineItem> myOCR = Database.query(Query);

return myOCR;

 

When I hard code the SortBy Variable the query works perfectly however I need to set the SortBy varible to the result of another query and I cannot get the correct syntax. Here is what I have tried so far and none of these worked:

 

String SortBy = 'Select SortBy__C from Custom__c Where Name = FreightDashboard' ;

 

String SortBy = '(Select SortBy__C from Custom__c Where Name = FreightDashboard)' ;

 

String sortx = 'Select SortBy__C from Custom__c Where Name = FreightDashboard' ;
List<Custom__c> Sortby = Database.query(sortx);
Return Sortby;

 

list<Custom__c> Sortby;
list <Custom__c> customa = ([Select SortBy__C from Custom__c Where Name = 'FreightDashboard']);{
   for (Custom__c cx:customa){
   Sortby.add(cx.SortBy__C); //not sure on this syntax 
  }
}

 

 

list<Custom__c> Sortby;

  public list<Custom__c> getCustom__c() {

        Sortby = ([Select SortBy__C from Custom__c Where Name = 'FreightDashboard']);

        return Sortby;
}

 

 

As you can probably tell I am new to SOQL. I have experience with SQL but I am struggling with this Order by variable.

 

Thank you,

 

I have built a custom report using Visual Force. I am trying to give the end user the ability to sort the report by a few different fields. I have created a pick list on a Custom Object that contains the field names (API Names) that the user can sort by. In my class I query the Custom object to get the field the end user wants to sort by, I store that in a variable. I then want to use that vairble to order by my SOQL statement that builds the report.

 

Here is my codes:

 

//Set the variable from the custom field

List<Custom__c> SortBy = [Select SortBy__C from Custom__c Where Name = 'FreightDashboard' ];

 

//My Query to build the report:

SELECT Estimated_Ship_Date__c, Date_Shipped__c, Opportunity.CloseDate, Opportunity.Account.Name, From OpportunityLineItem WHERE Opportunity.StageName = 'Closed Won' and (NOT ShippingType__c like '%Small Parcel%') ORDER BY :SortBY]

 

I want my end user to be able to sort by Estimated_Ship_Date__c or  Date_Shipped__c or Opportunity.CloseDate at their choosing.

 

Any help?

I am trying to pull the date off a custom SObject entry and use that date to filter another SOQL query. However I get an error everytime I try to set the variable to the date from the custom Sobject. Here is my code:

 

list<Date> startDate = new list<date>();
      List<Custom__c> custom = [Select startDate__c from Custom__c Where Name = 'FreightDashboard' ];{
              for (Custom__c cus:custom){
               StartDate = Date.valueof(cus.StartDate__c);
               system.debug('start date is'+StartDate);
        }
}

 

However I get the Error: Illegeal assignment from Date to LIST<Date>

 

Later I use StartDate in the follow query:

 

Select OpportunityId From Opportunity Where Opportunity.CloseDate >= :startDate 

 

Any help as to how I can set a variable from the date stored on a custom sObject. The data type of the startDate__c on Custom__c is "Date".

 

Thank you.,

I am trying to grab the date value from a custom Object and use that value to date range another query. Here is my code:

 

Date startDate = Date.valueof([Select startdate__c From Custom__c ]);

 

I do use a where clause to return just one value. StartDate__c is a date field on the Object.

 

This is then used in the following query:

 

Select OpportunityId From Opportunity Where Opportunity.CloseDate >= :startDate 

 

I get the following error:  Invalid date: common.apex.runtime.impl.SObjectList

 

any help?

 

 

I am new to APEX and SOQL however I have been able to figure out of what most I need to know. That being said I have now become stuck.

 

I am developing a Visualforce page that displays results from my Query. Currently the results are over 1000 items so I need to narrow my search down and I want the user of the page to be able to set date ranges that narrows the results down. My thought is that the user can set the date range and that will load into the URL and my SOQL query will grab the date ranges from the URL. However I am unable to make this work.

 

Here is my SOQL code

 

SELECT Name FROM Opportunity WHERE CloseDate = :ApexPages.currentPage().getParameters().get('CloseDate')

 

However I get an error trying to save this code: Invalid bind expression type of String for column of type Date.

 

The code above works perfectly when grabbing the opportunity number form the url however I cannot get it to work for the date.

 

Any help?

I have created a custom variable from a query on my controller. I am now trying to display this variable on the Apex page in a pageBlockTable. Here is my code:

 

Apex Page:

 

<apex:page controller="groupbytestcontroller">

<apex:form >

<apex:pageBlock title="" id="pageBlock">
<apex:pageBlockTable value="{!XXX}" var="summary">
<apex:column Headervalue="Sum Refund" >
<apex:outputText value="{!sumrefund}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>


</apex:form>

Sum Refund is <apex:outputText value=" {!sumrefund}"/>

</apex:page>

 

Controller:

public with sharing class groupbytestcontroller {

public decimal sumrefund { get; private set; }

List<Refunds__c> myRNDS;
public List<Refunds__c> getXXX() {

AggregateResult[] myRNDS = [Select SUM(Total_Refund__c)xx From Refunds__c Where OppLineItem_Id__c = '00ka000000iBrhG' ];

for (AggregateResult cus:myRNDS){

sumrefund = (Decimal) cus.get('xx');


system.debug('SUM Refund Is '+ sumrefund);

}
return null;
}

}

 

As you can see on the apex page I try to call the variable sumrefund two times. One inside of the pageblock table and one outside of the table. The one outside of the table/form works and displays the correct value. However the one inside the table does not display anything. Also if is substute the collumn headervalue with the variable it will show there as well, it just will not show in its collumn.

 

Any help?

I have built a custom report using Visual Force. I am trying to give the end user the ability to sort the report by a few different fields. I have created a pick list on a Custom Object that contains the field names (API Names) that the user can sort by. In my class I query the Custom object to get the field the end user wants to sort by, I store that in a variable. I then want to use that vairble to order by my SOQL statement that builds the report.

 

Here is my codes:

 

//Set the variable from the custom field

List<Custom__c> SortBy = [Select SortBy__C from Custom__c Where Name = 'FreightDashboard' ];

 

//My Query to build the report:

SELECT Estimated_Ship_Date__c, Date_Shipped__c, Opportunity.CloseDate, Opportunity.Account.Name, From OpportunityLineItem WHERE Opportunity.StageName = 'Closed Won' and (NOT ShippingType__c like '%Small Parcel%') ORDER BY :SortBY]

 

I want my end user to be able to sort by Estimated_Ship_Date__c or  Date_Shipped__c or Opportunity.CloseDate at their choosing.

 

Any help?

I am trying to pull the date off a custom SObject entry and use that date to filter another SOQL query. However I get an error everytime I try to set the variable to the date from the custom Sobject. Here is my code:

 

list<Date> startDate = new list<date>();
      List<Custom__c> custom = [Select startDate__c from Custom__c Where Name = 'FreightDashboard' ];{
              for (Custom__c cus:custom){
               StartDate = Date.valueof(cus.StartDate__c);
               system.debug('start date is'+StartDate);
        }
}

 

However I get the Error: Illegeal assignment from Date to LIST<Date>

 

Later I use StartDate in the follow query:

 

Select OpportunityId From Opportunity Where Opportunity.CloseDate >= :startDate 

 

Any help as to how I can set a variable from the date stored on a custom sObject. The data type of the startDate__c on Custom__c is "Date".

 

Thank you.,

I am trying to grab the date value from a custom Object and use that value to date range another query. Here is my code:

 

Date startDate = Date.valueof([Select startdate__c From Custom__c ]);

 

I do use a where clause to return just one value. StartDate__c is a date field on the Object.

 

This is then used in the following query:

 

Select OpportunityId From Opportunity Where Opportunity.CloseDate >= :startDate 

 

I get the following error:  Invalid date: common.apex.runtime.impl.SObjectList

 

any help?

 

 

I am new to APEX and SOQL however I have been able to figure out of what most I need to know. That being said I have now become stuck.

 

I am developing a Visualforce page that displays results from my Query. Currently the results are over 1000 items so I need to narrow my search down and I want the user of the page to be able to set date ranges that narrows the results down. My thought is that the user can set the date range and that will load into the URL and my SOQL query will grab the date ranges from the URL. However I am unable to make this work.

 

Here is my SOQL code

 

SELECT Name FROM Opportunity WHERE CloseDate = :ApexPages.currentPage().getParameters().get('CloseDate')

 

However I get an error trying to save this code: Invalid bind expression type of String for column of type Date.

 

The code above works perfectly when grabbing the opportunity number form the url however I cannot get it to work for the date.

 

Any help?