• solarcooker
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 14
    Replies
Hi there,

I have a problem with my schedulable class for many days. I create a job with this schedulable class to get date field of a custom object and update them, see the code bellow:
global class SellStovesAtResellerJob implements Schedulable {
    global void execute(SchedulableContext sc) {
        //Get the number of days after which stoves delivered to a reseller are sold
        Integer daysUntilSold = Sales_Settings__c.getInstance('Days_Until_Sold').Number_of_Days__c.intValue();
        
        //Calculate the date of the delivery
        Date deliveryDate = System.today() - daysUntilSold;
        
        //Search for all sales to reseller that have made X days ago and before
        List<Sale__c> salesToUpdate = [SELECT Date_of_Delivery__c, Date_of_Sale__c FROM Sale__c
                                       WHERE Date_of_Delivery__c <= :deliveryDate AND Date_of_Sale__c = null];
        
        //Change the date of sale
        for (Sale__c sale : salesToUpdate) sale.Date_of_Sale__c = sale.Date_of_Delivery__c + daysUntilSold;
        
        //Update the sales
        update salesToUpdate;
    }
}
The main problem is that the query returns no row when I look at the log (I create a trace flag for this class) when the job is finished (with success status) while it gives thousand rows in developper consol. I use the code bellow in an Execute Anonymous Windows:
Integer daysUntilSold = Sales_Settings__c.getInstance('Days_Until_Sold').Number_of_Days__c.intValue();
        
        //Calculate the date of the delivery
        Date deliveryDate = System.today() - daysUntilSold;
        
        //Search for all sales to reseller that have made X days ago and before
        List<Sale__c> salesToUpdate = [SELECT Date_of_Delivery__c, Date_of_Sale__c FROM Sale__c
                                       WHERE Date_of_Delivery__c <= :deliveryDate AND Date_of_Sale__c = null];
My user's profil is "System Administrator" with all rights (classes, custom objects and theirs fields, etc ...)

Can somebody explain me what the problem is?

Any kind of help will be welcome.
Cheers


 
Hi there,

I have the following exception with my trigger:
System.QueryException: Non-selective query against large object type (more than 100000 rows).
My SOQL query is like this:
SELECT Id, Type__c, Assembled__c, Production_Center__c, 
	Transport_to__c, Quality_Control_Result__c, Quality_Control_Date__c 
	FROM OLI_Core__c 
	WHERE Production_Center__c = :centerId 
	ORDER BY Quality_Control_Date__c DESC LIMIT 8000
The OLI_Core__c object contains around 100942 records and Production_Center__c field is an indexed field.
After some research I use the following query to check the request's cost in query plan (developer console):
SELECT Id FROM OLI_Core__c WHERE 
Production_Center__c != null AND Production_Center__c = 'a03D000000FrF4HIAV' 
ORDER BY Quality_Control_Date__c DESC LIMIT 8000
The query plan result is like the image bellow:
query plan screen shoot

I think that it's not possible to index IsDeleted field because it is a system field, and even if it's possible I think that's not a good idea because I will need to do like this with some other objects when records will be over 100K (which are used in other triggers).

Someone can help me to have a cost bellow 1 with Index as Leading Operation Type for this query considering the IsDeleted field problem. Or is there a workaround?

Thanks in advance for any kind of help.
 
Hello,

I'm beginner with apex and SOQL and I recently have problem with "Too many query rows: 50001" exception.
I thought this exception occurs when the SOQL query returns more than 50000 rows.
I have a class with 4 query but 2 of then cause the problem. The first query counts the number of products sold and group it by owner for each type of product: number of owner = 10, number of product = 10; total query = 10, total rows = 100
The second query counts the number of products sold and group it by month for each owner (center.name): number of month = 12, number of owner = 10; total query = 10, total rows = 120

NOTE: Total of number products sold is more than 50000. See bellow my requests:
//Get sales per stove type at each center
    	for (String stoveType : STOVE_TYPES) {
	    	AggregateResult[] centerNbSales = [SELECT owner.userRole.name salesCenterName, count(id) nbSales FROM Sale__c 
				WHERE Stove__r.Type__c LIKE :stoveType AND CALENDAR_YEAR(Date_of_Sale_real__c) =: System.today().Year() 
				GROUP BY owner.userRole.name];
			
			//Initialize the map with center name and sales = 0
			tmpCenterNbSalesMap = new Map<String, Integer>();
			for(String cName : centerName) tmpCenterNbSalesMap.put(cName, 0);
				
			for (AggregateResult ag : centerNbSales) tmpCenterNbSalesMap.put((String)ag.get('salesCenterName'), (Integer)ag.get('nbSales'));
			
			//Put the number sold stoves for each center for the current stove type
			salesStoveTypeMap.put(stoveType, tmpCenterNbSalesMap);
    	}
//Get the number of direct sales per month
AggregateResult[] tmpDateOfSalesList = [SELECT CALENDAR_MONTH(Date_of_Sale_Real__c) month, count(ID) nbSales FROM Sale__c
                                          WHERE CALENDAR_YEAR(Date_of_Sale_Real__c) = :year
                                          AND Stove__r.Selling_Center_3__c = :center.Name
                                          GROUP BY CALENDAR_MONTH(Date_of_Sale_Real__c)];
Please clarify me if I misunderstand the meaning of the "Too many query rows: 50001" exception and any help would be welcome.
(the class contains 700 lines but I can post it if necessary)

Thanks in advance.
Hello everybody,

I would like to run a report (Matrix report with lookup and formula fields) from Apex with the code below:

// Get the report ID
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where 
    DeveloperName = 'My_custom_report'];
String reportId = (String)reportList.get(0).get('Id');

// Run a report synchronously
Reports.reportResults results = Reports.ReportManager.runReport(reportId);

The following exception is thrown:

reports.MetadataException: Can't run the report because it doesn't have any columns selected. Be sure to add fields as columns to the report through the user interface.

Can somebody explain me what the problem is?

Cheers

Hello everybody,

 

I have a little problem here for which I'm not able to find a solution. We are an NGO in Madagascar an produce different types of solar cookers and charcoal/wood saving cookers. Thus, for each type I created a record in the Product object. I then created a custom object "Cooker" which is linked with a lookup-field to the Product object. Each cooker has therefore a type (link to Product object) and a Name, which is a unique number (we sell the cookers and have to register the clients and the number of the cookers).

 

Everything is working fine so far, there is just one annoying point: When someone searches for a cooker type with the lookup button, not only the Type field is filled out, but surprisingly (to me anyway) the Name field of the cooker (so, both fields are populated with the name of the Product). Every time, that field has to be cleared before entering the cooker number. It doesn't happen when the Type field is filled out manually, but only when the search button for the lookup is used.

 

Is it possible to somehow disable that, or did I make a mistake when creating my custom object/field?

 

Thank you very much for your help.

Hi there,

I have a problem with my schedulable class for many days. I create a job with this schedulable class to get date field of a custom object and update them, see the code bellow:
global class SellStovesAtResellerJob implements Schedulable {
    global void execute(SchedulableContext sc) {
        //Get the number of days after which stoves delivered to a reseller are sold
        Integer daysUntilSold = Sales_Settings__c.getInstance('Days_Until_Sold').Number_of_Days__c.intValue();
        
        //Calculate the date of the delivery
        Date deliveryDate = System.today() - daysUntilSold;
        
        //Search for all sales to reseller that have made X days ago and before
        List<Sale__c> salesToUpdate = [SELECT Date_of_Delivery__c, Date_of_Sale__c FROM Sale__c
                                       WHERE Date_of_Delivery__c <= :deliveryDate AND Date_of_Sale__c = null];
        
        //Change the date of sale
        for (Sale__c sale : salesToUpdate) sale.Date_of_Sale__c = sale.Date_of_Delivery__c + daysUntilSold;
        
        //Update the sales
        update salesToUpdate;
    }
}
The main problem is that the query returns no row when I look at the log (I create a trace flag for this class) when the job is finished (with success status) while it gives thousand rows in developper consol. I use the code bellow in an Execute Anonymous Windows:
Integer daysUntilSold = Sales_Settings__c.getInstance('Days_Until_Sold').Number_of_Days__c.intValue();
        
        //Calculate the date of the delivery
        Date deliveryDate = System.today() - daysUntilSold;
        
        //Search for all sales to reseller that have made X days ago and before
        List<Sale__c> salesToUpdate = [SELECT Date_of_Delivery__c, Date_of_Sale__c FROM Sale__c
                                       WHERE Date_of_Delivery__c <= :deliveryDate AND Date_of_Sale__c = null];
My user's profil is "System Administrator" with all rights (classes, custom objects and theirs fields, etc ...)

Can somebody explain me what the problem is?

Any kind of help will be welcome.
Cheers


 
Hi there,

I have the following exception with my trigger:
System.QueryException: Non-selective query against large object type (more than 100000 rows).
My SOQL query is like this:
SELECT Id, Type__c, Assembled__c, Production_Center__c, 
	Transport_to__c, Quality_Control_Result__c, Quality_Control_Date__c 
	FROM OLI_Core__c 
	WHERE Production_Center__c = :centerId 
	ORDER BY Quality_Control_Date__c DESC LIMIT 8000
The OLI_Core__c object contains around 100942 records and Production_Center__c field is an indexed field.
After some research I use the following query to check the request's cost in query plan (developer console):
SELECT Id FROM OLI_Core__c WHERE 
Production_Center__c != null AND Production_Center__c = 'a03D000000FrF4HIAV' 
ORDER BY Quality_Control_Date__c DESC LIMIT 8000
The query plan result is like the image bellow:
query plan screen shoot

I think that it's not possible to index IsDeleted field because it is a system field, and even if it's possible I think that's not a good idea because I will need to do like this with some other objects when records will be over 100K (which are used in other triggers).

Someone can help me to have a cost bellow 1 with Index as Leading Operation Type for this query considering the IsDeleted field problem. Or is there a workaround?

Thanks in advance for any kind of help.
 
Hello,

I'm beginner with apex and SOQL and I recently have problem with "Too many query rows: 50001" exception.
I thought this exception occurs when the SOQL query returns more than 50000 rows.
I have a class with 4 query but 2 of then cause the problem. The first query counts the number of products sold and group it by owner for each type of product: number of owner = 10, number of product = 10; total query = 10, total rows = 100
The second query counts the number of products sold and group it by month for each owner (center.name): number of month = 12, number of owner = 10; total query = 10, total rows = 120

NOTE: Total of number products sold is more than 50000. See bellow my requests:
//Get sales per stove type at each center
    	for (String stoveType : STOVE_TYPES) {
	    	AggregateResult[] centerNbSales = [SELECT owner.userRole.name salesCenterName, count(id) nbSales FROM Sale__c 
				WHERE Stove__r.Type__c LIKE :stoveType AND CALENDAR_YEAR(Date_of_Sale_real__c) =: System.today().Year() 
				GROUP BY owner.userRole.name];
			
			//Initialize the map with center name and sales = 0
			tmpCenterNbSalesMap = new Map<String, Integer>();
			for(String cName : centerName) tmpCenterNbSalesMap.put(cName, 0);
				
			for (AggregateResult ag : centerNbSales) tmpCenterNbSalesMap.put((String)ag.get('salesCenterName'), (Integer)ag.get('nbSales'));
			
			//Put the number sold stoves for each center for the current stove type
			salesStoveTypeMap.put(stoveType, tmpCenterNbSalesMap);
    	}
//Get the number of direct sales per month
AggregateResult[] tmpDateOfSalesList = [SELECT CALENDAR_MONTH(Date_of_Sale_Real__c) month, count(ID) nbSales FROM Sale__c
                                          WHERE CALENDAR_YEAR(Date_of_Sale_Real__c) = :year
                                          AND Stove__r.Selling_Center_3__c = :center.Name
                                          GROUP BY CALENDAR_MONTH(Date_of_Sale_Real__c)];
Please clarify me if I misunderstand the meaning of the "Too many query rows: 50001" exception and any help would be welcome.
(the class contains 700 lines but I can post it if necessary)

Thanks in advance.
Hello everybody,

I would like to run a report (Matrix report with lookup and formula fields) from Apex with the code below:

// Get the report ID
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where 
    DeveloperName = 'My_custom_report'];
String reportId = (String)reportList.get(0).get('Id');

// Run a report synchronously
Reports.reportResults results = Reports.ReportManager.runReport(reportId);

The following exception is thrown:

reports.MetadataException: Can't run the report because it doesn't have any columns selected. Be sure to add fields as columns to the report through the user interface.

Can somebody explain me what the problem is?

Cheers

Hello everybody,

 

I have a little problem here for which I'm not able to find a solution. We are an NGO in Madagascar an produce different types of solar cookers and charcoal/wood saving cookers. Thus, for each type I created a record in the Product object. I then created a custom object "Cooker" which is linked with a lookup-field to the Product object. Each cooker has therefore a type (link to Product object) and a Name, which is a unique number (we sell the cookers and have to register the clients and the number of the cookers).

 

Everything is working fine so far, there is just one annoying point: When someone searches for a cooker type with the lookup button, not only the Type field is filled out, but surprisingly (to me anyway) the Name field of the cooker (so, both fields are populated with the name of the Product). Every time, that field has to be cleared before entering the cooker number. It doesn't happen when the Type field is filled out manually, but only when the search button for the lookup is used.

 

Is it possible to somehow disable that, or did I make a mistake when creating my custom object/field?

 

Thank you very much for your help.

When I click on a tab (say it MyObject), the layout show me recent items. This is ok for me.I would like to add to this layout a my custom button. I have created the custom button (as list button) and I tried to add that button to the search layout page.

I am able to add the button to the "Search Result" layout but not on the "MyObject Tab" layout page. What I am wrong?

 

BR