• Matt Tindall
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 16
    Replies
Hello,

I am tring to use a dyamic query to pull a value from a related object depending on the PRODUCT and SUPPLIER used.

From what i can see the trigger is working to an extent. The "Message__c" field is being populated but getting alot more info than required. See the code used below.
 
trigger GetBinWeight on OpportunityLineItem (before update) {    
    for (OpportunityLineItem binWeight : Trigger.new) {        
        
        string SupplierID = binWeight.Waste_Supplier_ID__c;
        string WeightField = binWeight.Weight_Field_To_Use__c;
        
        List<Waste_Supplier__c> myList = Database.query('SELECT ' + WeightField + ' FROM Waste_Supplier__c WHERE Waste_Supplier__c.ID = :SupplierID limit 1');        
        string TheValue = string.valueOf(myList);
                
        binWeight.Message__c = TheValue;
        
    }
}
The result in "Message__c" is: (Waste_Supplier__c:{X1100_generalwaste_weight_nonefood__c=54545.00, Id=a09L00000056MbdIAE})

The correct result is in there and it is "54545.00"

Can anyone advise how i can change this?

Thanks,

Matt
 
Hello,

I am trying to create a trigger that will select the quantity of products that an opportunity has using a specific criteria.

The issue I'm having is:

1) I am un sure on how to make the query string match the opportunity from the list.
2) The string i am using is giving the following error "Illegal assignment from LIST<aggregateResult> to Decimal

Here is the code i am trying to use:

trigger CountWasteBins on Opportunity (after UPDATE) {
// List all customers
list<Opportunity> CustomerList = [SELECT id, General_Waste_Containers__c FROM Opportunity];

// Update all customers from the list
public void UpdateField()
{
for(Opportunity o : CustomerList)
{
o.General_Waste_Containers__c = [SELECT sum(Quantity) FROM OpportunityLineItem WHERE PricebookEntry.Product2.Family = 'General Waste'];

}
}

public void UpdateCustomerList()
{
// Update List
update CustomerList;
}
}

Hello,

 

I am trying to put an IF statement into my Class that determines if an Aggregate Result is NULL then place a 0 in its place.

Iv tried a few different ideas and just can't get it to work.

 

Public Integer getShowJanuarySales() {
    if (ShowJanuarySales > 0){
        return ShowJanuarySales;
    } else {
        return 1;
    }
 

 

Iv got the following statement that works fine as long as a record exists and I know that it changes the value for me. But if I replace the "> 0" with "== null" I just get an error on my page saying it can't reference a null object.

Anyone got any ideas?

Matt

Hello,

I am using IF statements to change the colour of text determined on its value. I have it working to show either "RED"  if the value is below 15 and Green thereafter.

 

<font size="6" color="{!IF((ShowNovemberSales<15),"RED","GREEN")}">{!ShowNovemberSales}</font>

 I'd like to add in an extra colour and that is if the value is GREATER than 15 but LOWER than 26 to show orange. 

Can anyone tell me how i write this as im having no luck!

Thanks,

Matt

I've tried every tutorial and referencing website I can and still just cannot figure what I need to do or how to start a test class for the following class. Please is there anyone out there who can help get me started?

public with sharing class Staff_Holiday_Calculator{
    // Staff Variables
        Private integer staff_allowance=252;
        public integer staff_total_used;
        public List<Holiday__c> staff_holidays {get;set;}
    
    // The SOQL without the order and limit
        private String soql {get;set;}
        
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
        public String sortField {
            get  { if (sortField == null) {sortField = 'Leave_Work__c'; } return sortField;  }
            set;
        }
    
    // format the soql for display on the visualforce page
        public String debugSoql {
            get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
            set;
        }
    
    // init the controller and display some sample data when the page loads
        public Staff_Holiday_Calculator() {
            soql = 'SELECT Staff_Memeber__c, Leave_Work__c, Return_to_Work__c, Hours_Used__c, Reason__c, Status__c FROM Holiday__c WHERE Staff_Memeber__c=';
            runQuery();
            
        List<AggregateResult> results=[select sum (Hours_Used__c) FROM Holiday__c WHERE Staff_Memeber__c = 'staff'];
        decimal staff_temp = (decimal)results[0].get('expr0');
        staff_total_used = staff_temp.intvalue();
                    
        }
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                    try {
                        staff_holidays = Database.query(soql + '\'staff\'' + ' order by ' + sortField + ' ' + sortDir + ' limit 100');
                    } catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                    }
                }
                
        // The number of hours a staff member is allowed 
            Public Integer getstaff_allowance() {
                return staff_allowance;
            }
    
        // The total numer or hours already used.
            Public Integer getstaff_total_used() {
                return staff_total_used;
            }
            
        // The total number of of hours allowed minus the total number of hours used.
            Public Integer getstaff_Available() {
                return staff_allowance-staff_total_used;
            }
            
        // A working day is based on 9 hours. Divide the available hours by 9 to show the number of whole days available.
            public integer getstaff_Daysleft() { 
                return (staff_allowance-staff_total_used)/9;   
            }
}

 

Iv been trying to write my test code for the following class and i just cant seem to get my head around it.

public with sharing class Total{
	// Staff Variables
		Private integer staff_allowance=252;
    	public integer staff_total_used;
    	public List<Holiday__c> staff_holidays {get;set;}
    
    // The SOQL without the order and limit
        private String soql {get;set;}
        
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
		public String sortField {
			get  { if (sortField == null) {sortField = 'Leave_Work__c'; } return sortField;  }
			set;
		}
    
	// format the soql for display on the visualforce page
		public String debugSoql {
			get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
			set;
		}
    
	// init the controller and display some sample data when the page loads
		public Total() {
			soql = 'SELECT Staff_Memeber__c, Leave_Work__c, Return_to_Work__c, Hours_Used__c, Reason__c, Status__c FROM Holiday__c WHERE Staff_Memeber__c=';
			runQuery();
            
		List<AggregateResult> results=[select sum (Hours_Used__c) FROM Holiday__c WHERE Staff_Memeber__c = 'staff'];
		decimal staff_temp = (decimal)results[0].get('expr0');
		staff_total_used = staff_temp.intvalue();
                    
		}
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                	try {
                        staff_holidays = Database.query(soql + '\'staff\'' + ' order by ' + sortField + ' ' + sortDir + ' limit 100');
                	} catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                	}
        		}
                
		// The number of hours a staff member is allowed 
    		Public Integer getstaff_allowance() {
        		return staff_allowance;
    		}
    
    	// The total numer or hours already used.
   	 		Public Integer getstaff_total_used() {
        		return staff_total_used;
    		}
            
		// The total number of of hours allowed minus the total number of hours used.
    		Public Integer getstaff_Available() {
        		return staff_allowance-staff_total_used;
    		}
            
		// A working day is based on 9 hours. Divide the available hours by 9 to show the number of whole days available.
    		public integer getstaff_Daysleft() { 
        		return (staff_allowance-staff_total_used)/9;   
    		}
    
}

 For the purpose of this example im just using one staff member and just refferencing as "staff". Can anyone point me in the right direction with this one. Self taught myself APEX so still learning but getting abit of preasure off the boss now ha.

Thanks,

Matt


Im trying to deploy the following class:

public with sharing class SkipSearchController{

    // The SOQL without the order and limit
        private String soql {get;set;}
    
    // The collection of Skip Companys to get
        public List<Skip_Supplier__c> suppliers {get;set;}
    
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
                public String sortField {
                        get  { if (sortField == null) {sortField = 'Postcode_Prefix__c'; } return sortField;  }
                        set;
                }
    
        // format the soql for display on the visualforce page
                public String debugSoql {
                        get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
                        set;
                }
    
        // init the controller and display some sample data when the page loads
                public SkipSearchController() {
                        soql = 'select Postcode_Prefix__c, X2_Yard__c, X2_Yard_Enclosed__c, X2_Yard_Plasterboard__c, X3_Yard__c, X3_Yard_Enclosed__c, X3_Yard_Plasterboard__c, X4_Yard__c, X4_Yard_Enclosed__c, X4_Yard_Plasterboard__c, X5_Yard__c, X5_Yard_Enclosed__c, X5_Yard_Plasterboard__c, X6_Yard__c, X6_Yard_Enclosed__c, X6_Yard_Plasterboard__c, X8_Yard__c, X8_Yard_Enclosed__c, X8_Yard_Plasterboard__c, X10_Yard__c, X10_Yard_Enclosed__c, X10_Yard_Plasterboard__c, X12_Yard__c, X12_Yard_Enclosed__c, X12_Yard_Plasterboard__c, X14_Yard__c, X14_Yard_Enclosed__c, X14_Yard_Plasterboard__c, X16_Yard__c, X16_Yard_Enclosed__c, X16_Yard_Plasterboard__c, Supplier_Name__c  from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                runQuery();
                }
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                try {
                        suppliers = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
                } catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                }
        }
            
        // runs the search with parameters passed via Javascript
                public PageReference runSearch() {
                        String Postcode = Apexpages.currentPage().getParameters().get('Postcode');
                        String Supplier = Apexpages.currentPage().getParameters().get('Supplier');
            
           soql = 'select Postcode_Prefix__c, X2_Yard__c, X2_Yard_Enclosed__c, X2_Yard_Plasterboard__c, X3_Yard__c, X3_Yard_Enclosed__c, X3_Yard_Plasterboard__c, X4_Yard__c, X4_Yard_Enclosed__c, X4_Yard_Plasterboard__c, X5_Yard__c, X5_Yard_Enclosed__c, X5_Yard_Plasterboard__c, X6_Yard__c, X6_Yard_Enclosed__c, X6_Yard_Plasterboard__c, X8_Yard__c, X8_Yard_Enclosed__c, X8_Yard_Plasterboard__c, X10_Yard__c, X10_Yard_Enclosed__c, X10_Yard_Plasterboard__c, X12_Yard__c, X12_Yard_Enclosed__c, X12_Yard_Plasterboard__c, X14_Yard__c, X14_Yard_Enclosed__c, X14_Yard_Plasterboard__c, X16_Yard__c, X16_Yard_Enclosed__c, X16_Yard_Plasterboard__c, Supplier_Name__c  from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                        if (!Postcode.equals(''))
                                soql += ' and Postcode_Prefix__c LIKE \''+String.escapeSingleQuotes(Postcode)+'%\'';
                        if (!Supplier.equals(''))
                                soql += ' and Supplier_Name__c LIKE \''+String.escapeSingleQuotes(Supplier)+'%\'';
                
                        // run the query again
                        runQuery();
 
                        return null;
                }

    
}

 But i am getting the follwoing error:

API Name:AdvVFWebinarViewStateExtension.testSaveFailedBecauseOfOpportunityValidationRu...
Type: Class
Line 123
Column: 1
Problem: Failure Message: "System.AssertException: Assertion Failed: Should not have been redirected.", Failure Stack Trace: "Class.AdvVFWebinarViewStateExtension.testSaveFailedBecauseOfOpportunityValidationRule: line 123, column 1"

Hello,

I've been looking in to conditional formatting within my table. I have a vague understanding of conditional formatting to make the fields change colour due to pre-defined values.

What I’m looking to achieve is the lowest value out of the column to be highlighted. Any ideas on how to go about this?

I'm trying to make some code that will add up the total value of a select field within a list i have created. I then want to subtract it from a set value. But i just keep getting an error. Can anyone please advise?

public with sharing class Total{

    Private integer allowance=252;
    public integer total_used;
    
    public Total(){
        total_used = [select sum (Hours_Used__c) FROM Holiday_Request__c WHERE Staff_Memeber__r.Name = 'Dan'];
    }
    
    Public Integer gettotal_used() {
        return total_used;
    }
    
    Public Integer getAvailable() {
        return 252-21;
    }
}

 

Hello,

 

I’m using a class to dynamically update and display data from OpportunityLineItem.

 

I’ve got the data coming through fine; i now want to tweak the filer of the SOQL search to make sure the object is related to an actual customer. I’ve run my query through the editor and it tests fine but when i place it in the actual code i get the following error: line 29 expecting a semi-colon, found 'Waste'. 

 

Any help would be most appreciated !

 

Here is my code:

public with sharing class WasteSheetController{

    //The SOQL without the order and limit
    private String soql{get;set;}
    
    //The collection of Products
    public List<OpportunityLineItem> products {get;set;}
    
    //The current sort direction
    public String sortDir {
        get{if(sortDir == null){sortDir = 'asc';} return sortDir;}
        set;
    }
        
    //Sort the data by Opportunity
    public String sortField {
        get{if(sortField == null){sortField ='Opportunity.Name';} return sortField;}
        set;
    }
        
    // format the soql for display on the visualforce page
    public String debugSoql {
        get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 999'; }
        set;
    }

    // init the controller and display some sample data when the page loads
    public WasteSheetController() {
        soql = 'select Id, Opportunity.Name, PricebookEntry.Product2.Name, Delivered__c, Contact_Sent__c, Contract_Signed__c, Ordered__c, Order_Confirmed__c, Opportunity.Postcode__c from OpportunityLineitem WHERE Opportunity.StageName='Waste Sale!'AND Opportunity.Name !=null';
        runQuery();
    }
    
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
        // run the query again
        runQuery();
    }
    
    // runs the actual query
    public void runQuery() {
        try {
            products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 999');
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Something has gone wrong this the search!'));
        }
    }
        
    // runs the search with parameters passed via Javascript
    public PageReference runSearch() {
        String Opportunity = Apexpages.currentPage().getParameters().get('Opportunity');
        
        soql = 'select Id, Opportunity.Name, PricebookEntry.Product2.Name, Delivered__c, Contact_Sent__c, Contract_Signed__c, Ordered__c, Order_Confirmed__c, Opportunity.Postcode__c from OpportunityLineitem WHERE Opportunity.StageName='Waste Sale!'AND Opportunity.Name !=null';
            if (!Opportunity.equals(''))
                soql += ' and Opportunity.Name LIKE \''+String.escapeSingleQuotes(Opportunity)+'%\'';

                
        //Run the query again
        runQuery();
        
        return null;
    }
}

 

 

Hi,

 

I’m new to APEX classes and I’m trying to move one from my Sandbox to my Production but i keep getting the following error "Average test coverage across all Apex Classes and Triggers is 59%, at least 75% test coverage is required.” I have searched the internet and read many forums but i just can grasp how to implement a test class to increase my coverage. 

 

Here is my code. Any help would be much appreciated! 

 

public with sharing class SkipSearchController{

    // The SOQL without the order and limit
        private String soql {get;set;}
    
    // The collection of Skip Companys to get
        public List<Skip_Supplier__c> suppliers {get;set;}
    
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
                public String sortField {
                        get  { if (sortField == null) {sortField = 'Postcode_Prefix__c'; } return sortField;  }
                        set;
                }
    
        // format the soql for display on the visualforce page
                public String debugSoql {
                        get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
                        set;
                }
    
        // init the controller and display some sample data when the page loads
                public SkipSearchController() {
                        soql = 'select Postcode_Prefix__c, Supplier_Name__c from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                runQuery();
                }
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                try {
                        suppliers = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
                } catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                }
        }
            
        // runs the search with parameters passed via Javascript
                public PageReference runSearch() {
                        String Postcode = Apexpages.currentPage().getParameters().get('Postcode');
                        String Supplier = Apexpages.currentPage().getParameters().get('Supplier');
            
           soql = 'select Postcode_Prefix__c, Supplier_Name__c from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                        if (!Postcode.equals(''))
                                soql += ' and Postcode_Prefix__c LIKE \''+String.escapeSingleQuotes(Postcode)+'%\'';
                        if (!Supplier.equals(''))
                                soql += ' and Supplier_Name__c LIKE \''+String.escapeSingleQuotes(Supplier)+'%\'';
                
                        // run the query again
                        runQuery();
 
                        return null;
                }
            
}

 Thanks,

Matt

Hello,

 

First time writing here so my apologies if I’m not as in depth / clear about my issue.

 

I’ve hit a brick wall with my formulas with my desired solution hitting its character limit. My work around was to involve a workflow rule that would complete a field update to determine if the "Commission cut-off date" exceeded the date of "Product added date"

 

I have the workflow rule created but i need it to evaluate the rule and run on a daily basis. Is it possible for me to use APEX or anything like that to automate a trigger for the workflow to run?

Any help would be greatly appreciated!!


Matt Tindall

Hello,

I am tring to use a dyamic query to pull a value from a related object depending on the PRODUCT and SUPPLIER used.

From what i can see the trigger is working to an extent. The "Message__c" field is being populated but getting alot more info than required. See the code used below.
 
trigger GetBinWeight on OpportunityLineItem (before update) {    
    for (OpportunityLineItem binWeight : Trigger.new) {        
        
        string SupplierID = binWeight.Waste_Supplier_ID__c;
        string WeightField = binWeight.Weight_Field_To_Use__c;
        
        List<Waste_Supplier__c> myList = Database.query('SELECT ' + WeightField + ' FROM Waste_Supplier__c WHERE Waste_Supplier__c.ID = :SupplierID limit 1');        
        string TheValue = string.valueOf(myList);
                
        binWeight.Message__c = TheValue;
        
    }
}
The result in "Message__c" is: (Waste_Supplier__c:{X1100_generalwaste_weight_nonefood__c=54545.00, Id=a09L00000056MbdIAE})

The correct result is in there and it is "54545.00"

Can anyone advise how i can change this?

Thanks,

Matt
 
Hello,

I am trying to create a trigger that will select the quantity of products that an opportunity has using a specific criteria.

The issue I'm having is:

1) I am un sure on how to make the query string match the opportunity from the list.
2) The string i am using is giving the following error "Illegal assignment from LIST<aggregateResult> to Decimal

Here is the code i am trying to use:

trigger CountWasteBins on Opportunity (after UPDATE) {
// List all customers
list<Opportunity> CustomerList = [SELECT id, General_Waste_Containers__c FROM Opportunity];

// Update all customers from the list
public void UpdateField()
{
for(Opportunity o : CustomerList)
{
o.General_Waste_Containers__c = [SELECT sum(Quantity) FROM OpportunityLineItem WHERE PricebookEntry.Product2.Family = 'General Waste'];

}
}

public void UpdateCustomerList()
{
// Update List
update CustomerList;
}
}

Hello,

 

I am trying to put an IF statement into my Class that determines if an Aggregate Result is NULL then place a 0 in its place.

Iv tried a few different ideas and just can't get it to work.

 

Public Integer getShowJanuarySales() {
    if (ShowJanuarySales > 0){
        return ShowJanuarySales;
    } else {
        return 1;
    }
 

 

Iv got the following statement that works fine as long as a record exists and I know that it changes the value for me. But if I replace the "> 0" with "== null" I just get an error on my page saying it can't reference a null object.

Anyone got any ideas?

Matt

Hello,

I am using IF statements to change the colour of text determined on its value. I have it working to show either "RED"  if the value is below 15 and Green thereafter.

 

<font size="6" color="{!IF((ShowNovemberSales<15),"RED","GREEN")}">{!ShowNovemberSales}</font>

 I'd like to add in an extra colour and that is if the value is GREATER than 15 but LOWER than 26 to show orange. 

Can anyone tell me how i write this as im having no luck!

Thanks,

Matt

Iv been trying to write my test code for the following class and i just cant seem to get my head around it.

public with sharing class Total{
	// Staff Variables
		Private integer staff_allowance=252;
    	public integer staff_total_used;
    	public List<Holiday__c> staff_holidays {get;set;}
    
    // The SOQL without the order and limit
        private String soql {get;set;}
        
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
		public String sortField {
			get  { if (sortField == null) {sortField = 'Leave_Work__c'; } return sortField;  }
			set;
		}
    
	// format the soql for display on the visualforce page
		public String debugSoql {
			get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
			set;
		}
    
	// init the controller and display some sample data when the page loads
		public Total() {
			soql = 'SELECT Staff_Memeber__c, Leave_Work__c, Return_to_Work__c, Hours_Used__c, Reason__c, Status__c FROM Holiday__c WHERE Staff_Memeber__c=';
			runQuery();
            
		List<AggregateResult> results=[select sum (Hours_Used__c) FROM Holiday__c WHERE Staff_Memeber__c = 'staff'];
		decimal staff_temp = (decimal)results[0].get('expr0');
		staff_total_used = staff_temp.intvalue();
                    
		}
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                	try {
                        staff_holidays = Database.query(soql + '\'staff\'' + ' order by ' + sortField + ' ' + sortDir + ' limit 100');
                	} catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                	}
        		}
                
		// The number of hours a staff member is allowed 
    		Public Integer getstaff_allowance() {
        		return staff_allowance;
    		}
    
    	// The total numer or hours already used.
   	 		Public Integer getstaff_total_used() {
        		return staff_total_used;
    		}
            
		// The total number of of hours allowed minus the total number of hours used.
    		Public Integer getstaff_Available() {
        		return staff_allowance-staff_total_used;
    		}
            
		// A working day is based on 9 hours. Divide the available hours by 9 to show the number of whole days available.
    		public integer getstaff_Daysleft() { 
        		return (staff_allowance-staff_total_used)/9;   
    		}
    
}

 For the purpose of this example im just using one staff member and just refferencing as "staff". Can anyone point me in the right direction with this one. Self taught myself APEX so still learning but getting abit of preasure off the boss now ha.

Thanks,

Matt


Im trying to deploy the following class:

public with sharing class SkipSearchController{

    // The SOQL without the order and limit
        private String soql {get;set;}
    
    // The collection of Skip Companys to get
        public List<Skip_Supplier__c> suppliers {get;set;}
    
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
                public String sortField {
                        get  { if (sortField == null) {sortField = 'Postcode_Prefix__c'; } return sortField;  }
                        set;
                }
    
        // format the soql for display on the visualforce page
                public String debugSoql {
                        get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
                        set;
                }
    
        // init the controller and display some sample data when the page loads
                public SkipSearchController() {
                        soql = 'select Postcode_Prefix__c, X2_Yard__c, X2_Yard_Enclosed__c, X2_Yard_Plasterboard__c, X3_Yard__c, X3_Yard_Enclosed__c, X3_Yard_Plasterboard__c, X4_Yard__c, X4_Yard_Enclosed__c, X4_Yard_Plasterboard__c, X5_Yard__c, X5_Yard_Enclosed__c, X5_Yard_Plasterboard__c, X6_Yard__c, X6_Yard_Enclosed__c, X6_Yard_Plasterboard__c, X8_Yard__c, X8_Yard_Enclosed__c, X8_Yard_Plasterboard__c, X10_Yard__c, X10_Yard_Enclosed__c, X10_Yard_Plasterboard__c, X12_Yard__c, X12_Yard_Enclosed__c, X12_Yard_Plasterboard__c, X14_Yard__c, X14_Yard_Enclosed__c, X14_Yard_Plasterboard__c, X16_Yard__c, X16_Yard_Enclosed__c, X16_Yard_Plasterboard__c, Supplier_Name__c  from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                runQuery();
                }
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                try {
                        suppliers = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
                } catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                }
        }
            
        // runs the search with parameters passed via Javascript
                public PageReference runSearch() {
                        String Postcode = Apexpages.currentPage().getParameters().get('Postcode');
                        String Supplier = Apexpages.currentPage().getParameters().get('Supplier');
            
           soql = 'select Postcode_Prefix__c, X2_Yard__c, X2_Yard_Enclosed__c, X2_Yard_Plasterboard__c, X3_Yard__c, X3_Yard_Enclosed__c, X3_Yard_Plasterboard__c, X4_Yard__c, X4_Yard_Enclosed__c, X4_Yard_Plasterboard__c, X5_Yard__c, X5_Yard_Enclosed__c, X5_Yard_Plasterboard__c, X6_Yard__c, X6_Yard_Enclosed__c, X6_Yard_Plasterboard__c, X8_Yard__c, X8_Yard_Enclosed__c, X8_Yard_Plasterboard__c, X10_Yard__c, X10_Yard_Enclosed__c, X10_Yard_Plasterboard__c, X12_Yard__c, X12_Yard_Enclosed__c, X12_Yard_Plasterboard__c, X14_Yard__c, X14_Yard_Enclosed__c, X14_Yard_Plasterboard__c, X16_Yard__c, X16_Yard_Enclosed__c, X16_Yard_Plasterboard__c, Supplier_Name__c  from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                        if (!Postcode.equals(''))
                                soql += ' and Postcode_Prefix__c LIKE \''+String.escapeSingleQuotes(Postcode)+'%\'';
                        if (!Supplier.equals(''))
                                soql += ' and Supplier_Name__c LIKE \''+String.escapeSingleQuotes(Supplier)+'%\'';
                
                        // run the query again
                        runQuery();
 
                        return null;
                }

    
}

 But i am getting the follwoing error:

API Name:AdvVFWebinarViewStateExtension.testSaveFailedBecauseOfOpportunityValidationRu...
Type: Class
Line 123
Column: 1
Problem: Failure Message: "System.AssertException: Assertion Failed: Should not have been redirected.", Failure Stack Trace: "Class.AdvVFWebinarViewStateExtension.testSaveFailedBecauseOfOpportunityValidationRule: line 123, column 1"

I'm trying to make some code that will add up the total value of a select field within a list i have created. I then want to subtract it from a set value. But i just keep getting an error. Can anyone please advise?

public with sharing class Total{

    Private integer allowance=252;
    public integer total_used;
    
    public Total(){
        total_used = [select sum (Hours_Used__c) FROM Holiday_Request__c WHERE Staff_Memeber__r.Name = 'Dan'];
    }
    
    Public Integer gettotal_used() {
        return total_used;
    }
    
    Public Integer getAvailable() {
        return 252-21;
    }
}

 

Hello,

 

I’m using a class to dynamically update and display data from OpportunityLineItem.

 

I’ve got the data coming through fine; i now want to tweak the filer of the SOQL search to make sure the object is related to an actual customer. I’ve run my query through the editor and it tests fine but when i place it in the actual code i get the following error: line 29 expecting a semi-colon, found 'Waste'. 

 

Any help would be most appreciated !

 

Here is my code:

public with sharing class WasteSheetController{

    //The SOQL without the order and limit
    private String soql{get;set;}
    
    //The collection of Products
    public List<OpportunityLineItem> products {get;set;}
    
    //The current sort direction
    public String sortDir {
        get{if(sortDir == null){sortDir = 'asc';} return sortDir;}
        set;
    }
        
    //Sort the data by Opportunity
    public String sortField {
        get{if(sortField == null){sortField ='Opportunity.Name';} return sortField;}
        set;
    }
        
    // format the soql for display on the visualforce page
    public String debugSoql {
        get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 999'; }
        set;
    }

    // init the controller and display some sample data when the page loads
    public WasteSheetController() {
        soql = 'select Id, Opportunity.Name, PricebookEntry.Product2.Name, Delivered__c, Contact_Sent__c, Contract_Signed__c, Ordered__c, Order_Confirmed__c, Opportunity.Postcode__c from OpportunityLineitem WHERE Opportunity.StageName='Waste Sale!'AND Opportunity.Name !=null';
        runQuery();
    }
    
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
        // run the query again
        runQuery();
    }
    
    // runs the actual query
    public void runQuery() {
        try {
            products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 999');
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Something has gone wrong this the search!'));
        }
    }
        
    // runs the search with parameters passed via Javascript
    public PageReference runSearch() {
        String Opportunity = Apexpages.currentPage().getParameters().get('Opportunity');
        
        soql = 'select Id, Opportunity.Name, PricebookEntry.Product2.Name, Delivered__c, Contact_Sent__c, Contract_Signed__c, Ordered__c, Order_Confirmed__c, Opportunity.Postcode__c from OpportunityLineitem WHERE Opportunity.StageName='Waste Sale!'AND Opportunity.Name !=null';
            if (!Opportunity.equals(''))
                soql += ' and Opportunity.Name LIKE \''+String.escapeSingleQuotes(Opportunity)+'%\'';

                
        //Run the query again
        runQuery();
        
        return null;
    }
}

 

 

Hi,

 

I’m new to APEX classes and I’m trying to move one from my Sandbox to my Production but i keep getting the following error "Average test coverage across all Apex Classes and Triggers is 59%, at least 75% test coverage is required.” I have searched the internet and read many forums but i just can grasp how to implement a test class to increase my coverage. 

 

Here is my code. Any help would be much appreciated! 

 

public with sharing class SkipSearchController{

    // The SOQL without the order and limit
        private String soql {get;set;}
    
    // The collection of Skip Companys to get
        public List<Skip_Supplier__c> suppliers {get;set;}
    
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
                public String sortField {
                        get  { if (sortField == null) {sortField = 'Postcode_Prefix__c'; } return sortField;  }
                        set;
                }
    
        // format the soql for display on the visualforce page
                public String debugSoql {
                        get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
                        set;
                }
    
        // init the controller and display some sample data when the page loads
                public SkipSearchController() {
                        soql = 'select Postcode_Prefix__c, Supplier_Name__c from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                runQuery();
                }
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                try {
                        suppliers = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
                } catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                }
        }
            
        // runs the search with parameters passed via Javascript
                public PageReference runSearch() {
                        String Postcode = Apexpages.currentPage().getParameters().get('Postcode');
                        String Supplier = Apexpages.currentPage().getParameters().get('Supplier');
            
           soql = 'select Postcode_Prefix__c, Supplier_Name__c from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                        if (!Postcode.equals(''))
                                soql += ' and Postcode_Prefix__c LIKE \''+String.escapeSingleQuotes(Postcode)+'%\'';
                        if (!Supplier.equals(''))
                                soql += ' and Supplier_Name__c LIKE \''+String.escapeSingleQuotes(Supplier)+'%\'';
                
                        // run the query again
                        runQuery();
 
                        return null;
                }
            
}

 Thanks,

Matt

Hello,

 

First time writing here so my apologies if I’m not as in depth / clear about my issue.

 

I’ve hit a brick wall with my formulas with my desired solution hitting its character limit. My work around was to involve a workflow rule that would complete a field update to determine if the "Commission cut-off date" exceeded the date of "Product added date"

 

I have the workflow rule created but i need it to evaluate the rule and run on a daily basis. Is it possible for me to use APEX or anything like that to automate a trigger for the workflow to run?

Any help would be greatly appreciated!!


Matt Tindall