• JoshTonks
  • NEWBIE
  • 165 Points
  • Member since 2016
  • RAM Tracking

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 29
    Questions
  • 19
    Replies
I have a command button that creates a record and when it is saving it freezes for a few seconds whilst it is executing. I cannot figure a way to display that it is saving so people dont just reclicking the button. Ive seen people display a gif whilst saving but im unable to find a way to replicate this function or even display in text that it is saving
 
<apex:form style="margin: 10px; color:#322c4f">
                                    <span style="font-size:1.25em">Request callback</span>    
                                    <table style="color:#322c4f">
                                    <tr>
                                        <td colspan="2" style="color:#322c4f">
                                            User:
                                        </td>
                                        <td style="color:#322c4f">
                                            {!$User.FirstName} {!$User.LastName}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" style="color:#322c4f">
                                            Date &#038; Time: 
                                        </td>
                                        <td style="color:#322c4f">
                                            <apex:outputText value="{0,date,dd/MM/yyyy HH:mm}"><apex:param value="{!NOW()}" /></apex:outputText>
                                        </td>
                                    </tr>
                                    <tr>
                                    </tr>
                                    <tr>
                                    <td colspan="2" style="color:#322c4f">
                                    Interested In:
                                    </td>
                                    <td style="color:#322c4f">
                                    DashCams
                                    </td>
                                    </tr>
                                    </table>
                                    <br/>
                                     <span style="padding-left: 1px">Contact:
                                    <apex:selectList multiselect="false" value="{!selectedContact}" size="1">
                                    <apex:selectOptions value="{!contacts}">
                                    </apex:selectOptions>
                                    </apex:selectList><br/>
                                
                                    Notes:<br/>
                                    <apex:inputTextarea value="{!Notes}" rows="3" style="width:50%; border: 1px solid #322c4f; color: #322c4f; margin-left:2px" /></span>
                                    <apex:commandButton styleClass="logger" value="Save" action="{!save}" style="width:25%;float: right; margin-top:40px;border: 1px solid #322c4f; color:white; padding: 10px 5px"/>
                                </apex:form>

 
Im writing a batch class I have written some previously without issue however when i am writing this this and only 42% coverage. What im trying to do check a box on records that hit the contract end date today which runs a process. It all works just cannot figure out what i need to do get it to test successfully.

This is my Class
 
global class DDBatchUpdate implements Database.Batchable<sObject> {
    Date TODAY = Date.today();
    String DDACTIVE = 'Active';
    global Database.QueryLocator start(Database.BatchableContext BC) { 
        String query = 'SELECT Id FROM DD_Agreement__c WHERE DD_Status__c =: DDACTIVE AND Rolling_End_Date__c = TODAY';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<DD_Agreement__c> DDList) {
        for(DD_Agreement__c DD : DDList)
        {        
            DD.id = DD.id;
            DD.Trigger_Builder__c = TRUE;
        }
        try {
            
            update DDList;
        } catch(Exception e) {
            System.debug(e);
        }
    }   
    global void finish(Database.BatchableContext BC) {
        
  }
}

This is my test class which is only getting 42% coverage It is nearly all the content in global void execute. It is probably something simple im missing.
 
@isTest
private class DDBatchUpdateTest {

static testmethod void test() {

List<DD_Agreement__c> DDList = new List<DD_Agreement__c>(); 
for (Integer i=0;i<200;i++) { 
    DDList.add(new DD_Agreement__c(Trigger_Builder__c=TRUE,DD_Status__c='Active')); 
}
insert DDList;

Test.startTest();
DDBatchUpdate c = new DDBatchUpdate();
Database.executeBatch(c);
Test.stopTest();
    
DD_Agreement__c[] DDUpdatedList = [SELECT Id,Trigger_Builder__c FROM DD_Agreement__c];
System.assert(DDUpdatedList[0].Id != null); 
}
}

Thank you in advance.

 
I have written a Batch Class which is called by a Scheduable class I have written. Im still trying to get my head round tests classes.

I have a test class for the Batch Class. But i dont know how to do write a test class where the schedulable class is calling a Batch Class. This is my Schedule class can someone explain to me what im actually testing for on this one because like I said i fully understand test classes.
 
global class OrderBatchEditScheduler implements Schedulable{
    global void execute(SchedulableContext sc)
    {
       
        OrderDailyBatchEdit b = new OrderDailyBatchEdit();
      
        Database.executebatch(b,200);
    }
   
}

 
I have writen a Batchable class that works in Sandbox. Im trying to write a test class for this and am really struggling to make headway. 

This is my Class 
global class HealthUpdaterBatchable implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) { 
        String query = 'SELECT Id FROM HealthScore__c';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<HealthScore__c> hsList) {
        for(HealthScore__c hs : hsList)
        {        
            hs.id = hs.id;
        }
        try {
        	
            update hsList;
        } catch(Exception e) {
            System.debug(e);
        }
    }   
    global void finish(Database.BatchableContext BC) {
    	
  }
}
This is my test class so far 
private class HealthUpdaterBatchableTest {

static testmethod void test() {

HealthScore__c[] hsList = new List();
for (Integer i=0;i<200;i++) {
HealthScore__c m = new Healthscore__c();
hsList.add(m);
}
insert hsList;

Test.startTest();
HealthUpdaterBatchable c = new HealthUpdaterBatchable();
Database.executeBatch(c);
Test.stopTest();
    
HealthScore__c[] hsUpdatedList = [SELECT Id FROM HealthScore__c];
System.assert(hsUpdatedList[0]);
}
}
Im getting a few errors
  • Expecting < but was ( -Line 6
  •  Invalid type: HealthScore - Line 18
  •  Method does not exist or incorrect signature: void assert(Healthscore) from the type System. - Line 19.
Any advice or assistance is very much appreciated 
 
Im trying to do a count in apex on Events that were marked as cancelled for opportunities that were generated from referrals I know how to build the counts but don't know how or if its possible to combine the two. This is what ive got so far. But im not sure if you can use the WhatId for what im needing.
 
Date THIS_MONTH = System.today().toStartOfMonth();
Date NEXT_MONTH = THIS_MONTH.addMonths(1).addDays(0);
String IsRef = '%'+ 'Referral' +'%';

    public Integer getRefOpps(){
    return [SELECT Count()
            FROM Opportunities
            WHERE Opp_Enquiry_Source__c LIKE IsRef AND CloseDate => THIS_MONTH && CloseDate < NEXT_MONTH AND Stage !=: 'Closed Won' OR Stage !=: 'Completed' 
            ];
     }

    public Integer getCanxRefTask(){
    return [SELECT Count()
            FROM Event
            WHERE AND X1st_Appointment_With_Director__c = TRUE AND ActivityDate >= THIS_MONTH AND ActivityDate < NEXT_MONTH Outcome__c =: 'Cancelled by Them'
            ];
     }

Thank you in advance.
 
I was hoping someone could help me. I have a controller extension which saves the record and then redirects the person away from the page. This is for our customers fo a customer feedback this all works for me but I have no idea how i would write a test class for the extension as I have done test classes for other things before but this I cannot get my head around any guidance would be much appreciated. This is my extension below im using www.google.com as a placeholder as I havn't got the page built just yet for the redirect.
 
public with sharing class CSATExtension
{
   ApexPages.StandardController stdCtrl;
   // extension constructor
   public CSATExtension(ApexPages.StandardController std)
   {
      stdCtrl=std;
   }

   public PageReference save()
   {
      stdCtrl.save();
      PageReference pr = new PageReference('http://www.google..com/');
      pr.setRedirect(true);
      return pr;
   }
}

 
Hi,

Im looking to see if there are any tutorials around that shows you how to query a picklist field on an object against a metadata label and output the value of the custom metadata

Example 
Picklist Option
Term: 12 Month

So we would take the 12 Month from the picklist and look for 12 Month in custom metadata term number and then output the value of 12. It didnt used to be an issue however as our company will offer any length of term the formula we were using cannot hold all the term numbers. Which results in us having to update the Formula on a daily basis.

Ive tried to find a tutorial online cannot find anything so if anyone knows a tutorial along those lines I would be very grateful.

Many Thanks In Advance
 
Hi Folk
Im looking for a little help, I was just putting something together for cost saved which we record on individual contacts
List<Contact> CostSaved;
        public List<Contact> getCostSaved() {
               	CostSaved = [SELECT Account_ID__c, SUM(Savings_per_week__c)
                			 FROM Contact, Contact.Account
                			 WHERE Account.Name = 'ram test'
                			 GROUP BY Account_ID__c];
            	return CostSaved;
        }
I am getting Illegal assignment from List<AggregateResult> to List<Contact> im obviously missing something I just cant figure out what.
 
Hi,

I am trying o do a record count on a specific criteria which i have working. However the issue I have is I dont know how to write a test class for it. Ive mainly worked with lists up until now which i can write a test class for. I have attached the apex class below would someone be able to give me some direction on what i need to put in the test class.
 
public class UnitCount {

    public Integer getC2630Counter(){
    	return [SELECT count()
                FROM Unit_Value__c
                WHERE Unit_Type__c =: 'LMU-2630' AND Stock_Status__c =: 'OFFICE' AND Account__c = '0010E00000DHfef' AND Status__c =: 'New Stock'
                ];
	}
}

 
Im trying to create some simple counters. It is going to be more filtered down then this but im getting an error on the 3 and 9 line Variable does not exist: Integer. I think im missing something out because im sure that ive written something similar many moons ago.
public class StatusCheck {
    public Integer getCaseCounter(){
    	return (Integer) = [SELECT count()
                          	FROM Case
                          	WHERE Type =: 'Install'
                          	];
	}
    public Integer getOppCounter(){				
    	return (Integer) = [SELECT count()
                          	FROM Opportunity
                          	WHERE Type =: 'New Business'
                         	];
    						

	}
}

 
Im still learning and i must be doing something wrong im getting an Illegal assignment from List to List on the following code on line 7. Also on a second note does anyone have a link for any books on apex or courses that cover the list functionality please.
 
public with sharing class monthlylist {
	public list<Opportunity> Monthly;
    Date startOfMonth = Date.today().toStartOfMonth();
	Date startOfNextMonth = startOfMonth.addMonths(1);
    
    public list<Opportunity> Monthly(){
    Monthly = [SELECT Owner.Name, COUNT(id)
               FROM Opportunity
              WHERE StageName = :'Closed Won, Complete' AND CloseDate >= :startOfMonth AND CloseDate < :startOfNextMonth AND UK_Canada__c = 'UK'
              GROUP BY Owner.Name];
    return Monthly;
}
}

 
Im trying to write a test class for the below code. Ive written test classes before for things but for the life of me I cannot figure out how to get this to work with it. I feel like im missing something obvious. My apex class is below. The public list is passing the rest isnt.
public with sharing class CAengineerInvoices {

  List<Service_Booking__c> CAengineerInvoices;
      Service_Booking__c NetTotal;
      Service_Booking__c GrossTotal;
    
    public List <Service_Booking__c> getCAengineerInvoices(){
      CAengineerInvoices = [SELECT   Eng_Qty__c, CA_Gross_Amount__c, CA_Gross_Total_VF__c, Description_Of_Work__c, Description_of_Additional_work__c,Service_Company_Name__c, Company_Name__c, Registration_s__c, Name, Booking_Date_Time__c, CA_Eng_Net_Price__c, KM_Over__c, CA_Tax_Amount__c,Gross_Amount__c, Booking_Date_Time_Fomrula__c
                     FROM Service_Booking__c
                     WHERE Booking_Confirmed__c = True AND Service_Company__c = :ApexPages.currentPage().getParameters().get('Id')];
      return CAengineerInvoices;
    }

	public Service_Booking__c getNetTotal() {
       NetTotal = new Service_Booking__c(CA_Eng_Net_Price__c = 0);
       
       for(Service_Booking__c CAI : getCAengineerInvoices()){
           NetTotal.CA_Eng_Net_Price__c += CAI.CA_Eng_Net_Price__c;
           }
           return NetTotal;
      }


	public Service_Booking__c getGrossTotal() {
       GrossTotal = new Service_Booking__c(CA_Gross_Total_VF__c = 0);
       
       for(Service_Booking__c GT : getCAengineerInvoices()){
           GrossTotal.CA_Gross_Total_VF__c += GT.CA_Gross_Total_VF__c;
           }
           return GrossTotal;
      }
	public Account getAccount() {
        return [SELECT Id, Name FROM Account
                WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];
    }
}

 
Im fairly new to apex im only just getting into it.

I have written the following but Im still trying to get my head round writing a test class and would be grateful for any assistance on doing so. Im sure ill eventually get my head round this.
 
public class CaseCon {
    List<case> CaseCon;
        public List<case> getCaseCon() {
            CaseCon = [SELECT Account.Name, Owner.Name, CaseNumber
                       FROM Case
                       WHERE Urgent__c = :TRUE];
            return CaseCon;
        }
}

 
Hi I was hoping someone would be able to give me a little advice or point me in the right direction if the information is already documented somewhere. Im looking to build some functionality onto an object where the quantity of a quantity field would define the quantity of records to create. Similar to how payment schedule works on products. So if I specified 10 in quantity box it would create 10 related object records.