• Simon Baird
  • NEWBIE
  • 30 Points
  • Member since 2014
  • Operations Manager
  • Aged Foot Care

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 11
    Replies
Hi all,
I am trying to divide to numbers produced from aggregate result in an apex class. Am able to retrive the values (tx and wd) and present them on the VF page widget but would like to divide one by the other and present the result.i.e. tx/wd

public AggregateResult[] AvTx{
        get {
            return [SELECT SUM(Working_Days__c)wd,SUM(Total_Treatments__c)tx FROM Session__c WHERE Session_Completed__c = true AND OwnerID = :u AND Date__c >= :dtps AND (Session_Coverage_Type__c = 'Regular' OR Session_Coverage_Type__c = 'Regular Rescheduled') AND Session_Type__c != 'Emergency' AND Exclude_Session_From_Pod_Tier_Average__c = false];
            }

<apex:page controller="OpenSessionsList" readOnly="true">
   <apex:pageBlock >
        <apex:pageBlockTable value="{!AvTx}" var="r">
            <apex:column >
            <apex:facet name="header">Average Treatments</apex:facet>
             {!r['wd']}
             </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>    
</apex:page>
Ok guys I've got a humdinger here. I have a visualforce page (Session__c) that has a controller extension to update related fields on another object (Account). On the visualforce page I also have a command button using the URLFOR syntax to create a record of another object type (Patient__c). When I reference the fields in the controller extension on the visualforce page and try to create the new record (Patient__c) it doesn't recognise the default field values i.e. checkbox ticked. When I remove these fields from the visualforce page code the field default values are recognised once more.The page is for a custom object called Session__c with an extension to update fields on Account with an apex:CommandButton to create a new Patient__c record. I can't replicate it in our sandbox environment either!

 
Hi all,

I am trying to add some text to a field by pulling it from its parent record using a Onclick Javascipt button. Getting the URL no longer exists on refresh. Note the button is a custom button called from a VF page use apex:commandbutton
 
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 

var c = new sforce.SObject("Patient_Session__c"); 
c.id ="{!Patient_Session__c.Id}";
var pgn = "{!Patient__c.Patient_Progress_Note__c}";
c.Treatment_Notes__c = pgn;

sforce.connection.update([c]); 
window.location= '/{!Patient_Session__c.Id}';

 
Hi there,

I need to limit the number of records returned from this query. When i use the LIMIT clause before the last semi colon I get an error "mismatched input expecting semi colon". Any thoughts guys?

 public List<Event> start(){
      String query = 'Select Id,IsRecurrence,Event_Processed__c,Allowance_Type__c,Session_Coverage_Type__c,Session_Type__c,Message_from_Office_to_Podiatrist__c,Additional_Message_From_Office_to_Pod__c,Subject,OwnerId,owner.Name,WhatId,startdatetime,of_Session_Sharing_Day__c,Wing_1__c,Wing_2__c,Wing_3__c,Wing_4__c,Wing_5__c,Wing_6__c,Wing_7__c,Wing_8__c,Wing_9__c,Rooms_1__c,Rooms_2__c,Rooms_3__c,Rooms_4__c FROM Event WHERE Do_Not_Create_Session__c = false AND IsRecurrence = false AND Event_Processed__c = false AND RecordType.Name IN :lstEventRecordTypes AND What.RecordType.Name IN :lstAccountRecordTypes AND Owner.Title IN :lstOwnerTitles AND ActivityDate = NEXT_N_DAYS :'+ lastNumberOfDays ; 
      return Database.query(query);
I am using the code from the developer pages to mass update records from a list view. It works great in most instances except when it comes to checkbox fields. If I mass update records and check a checkbox field then update them again but update a different field it unchecks the previously checked boxes. None of the other fields on the page get updated unless they have new data inserted just seems to be with the checkbox fields. I am assuming it is because it is seeing them as field change but technically they should not be. Has anyone seen this behaviour before?

Here's the VF markup and controller extension i have used
http://www.salesforce.com/docs/developer/pages/Content/pages_compref_inputField.htm
Hi there, I have created a visualforce page to update records from a list view. I am able to retrieve the fields for editing but when I save it doesn't update the record. The fields I am trying to update are related to the Patient_Session__c object via a lookup relationship. Here's the VF markup

<apex:page standardcontroller="Patient_Session__c" recordSetVar="ProgressNotes" tabStyle="Patient_Session__c" sidebar="false">
<pbe:PageBlockTableEnhancerADV targetPbTableIds="Info" paginate="true" defaultPageSize="100" pageSizeOptions="5,10,20,30,40,50,100" />
  <style type="text/css">
        .myClass { width: 300px; }
    </style>
<h1>Mass Edit Patients</h1>
<apex:form >
    <apex:pageblock >
    <apex:pagemessages />
       <apex:pageBlockButtons >        
        <apex:commandButton value="Quick Save" action="{!quicksave}"/>
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Details" columns="1">
    <apex:pageBlockTable value="{!selected}" var="pgn" id="details">
        <apex:column headervalue="First Name">
            <apex:outputField value="{!pgn.Patient__r.First_Name__c}"/>
        </apex:column>
        <apex:column headervalue="Last Name">
            <apex:outputField value="{!pgn.Patient__r.Last_Name__c}"/>
        </apex:column>
        <apex:column headervalue="Patient Description">
            <apex:outputField value="{!pgn.Patient__r.Patient_Description__c}"/>
        </apex:column>
        <apex:column headervalue="Active">
            <apex:inputField value="{!pgn.Patient__r.Active__c}"/>
        </apex:column>
            </apex:pageBlockTable>
            </apex:pageBlockSection>   
        </apex:pageBlock>
    </apex:form>        
</apex:page>
I need help with a controller extension to retrieve and update parent records from a list view. We have a child object called Patient_Session__c that has a lookup to parent called Patient_c and want to use a visualforce page to update the parent records in mass edit mode from a list view of the child records.  Here's the extension I am using:

public with sharing class updatePatientInfo {
    public Patient_Session__c pgn;
    public Patient__c patient;

    public updatePatientInfo(ApexPages.StandardController controller) {
        this.pgn = (Patient_Session__c)controller.getRecord();
        this.patient = [SELECT Id,Name,Patient_Description__c,A_1__c,A_Frequency__c,B_1__c,B1_Frequency__c,B2_Frequency__c,C_1__c,C1_Frequency__c,C2_Frequency__c,D_1__c,D1_Frequency__c,D2_Frequency__c,X__c FROM Patient__c WHERE ID = :ApexPages.currentPage().getParameters().get('id')];
    }

    public PageReference saveRecord() {
        
    update patient;
    update pgn;  
        return null;
    }
 }

Here's the visualforcepage

<apex:page controller="updatePatientInfo" tabStyle="Patient_Session__c" sidebar="false">
<pbe:PageBlockTableEnhancerADV targetPbTableIds="details," paginate="true" defaultPageSize="100" pageSizeOptions="5,10,20,30,40,50,100" />
  <style type="text/css">
        .myClass { width: 300px; }
    </style>
<h1>Mass Edit Patients</h1>
<apex:form >
    <apex:pageblock >
    <apex:pagemessages />
       <apex:pageBlockButtons >        
        <apex:commandButton value="Quick Save" action="{!quicksave}"/>
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Details" columns="1">
    <apex:pageBlockTable value="{!selected}" var="pgn" id="details">
        <apex:column headervalue="First Name">
            <apex:inputField value="{!pgn.Patient__r.Patient_Description__c}"/>
        </apex:column>
            </apex:pageBlockTable>
            </apex:pageBlockSection>   
        </apex:pageBlock>
    </apex:form>        
</apex:page>

When I try to save the visualforce page I get this error
 "Error: Unknown constructor 'updatePatientInfo.updatePatientInfo()"

I am new to apex so any help would be greatly appreciated
Hi all, I am fairly new to apex coding and have created a scheduled class that checks a number of records to fit a criteria then performs a simple update to a checkbox field. The problem is I am getting the Apex CPU time limit exceeded as it is checking through over 5000 records. I believe I need to set this up as a batch to make it work. Can someone help me convert this code to a batch

global class SalesInvoicePaid implements Schedulable {

// Execute method
global void execute(SchedulableContext SC) {

// Code to be executed when the schedule class wakes up
    List <c2g__codaInvoice__c> siv = [SELECT ID, Paid__c
                           FROM c2g__codaInvoice__c
                           WHERE c2g__PaymentStatus__c = 'Paid' AND Paid__c = False AND c2g__InvoiceDate__c > 2014-07-01];        

    for(c2g__codaInvoice__c s: siv){
        s.Paid__c = true;           
    }
    update(siv);




// this section of code will abort the current schedule job
try {
system.abortJob(sc.getTriggerId());
} catch (exception e) {system.debug('#### schedule job exception while aborting:' + e);}


// reschedule the job
system.debug('#### schedule job executing');
scheduleNow();

}


global static void scheduleNow() {

// this section of code will schedule the next execution 1 minute from now
datetime thisTime = system.now().addHours(24);
integer minute = thisTime.minute();
integer second = thisTime.second();
integer hour = thisTime.hour();
integer year = thisTime.year();
integer month = thisTime.month();
integer day = thisTime.day();

String timeStamp = second + ' ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ? ' + year;
string jobName = 'SalesInvoicePaid';

SalesInvoicePaid p = new SalesInvoicePaid();
system.schedule(jobName, timeStamp , p);

}
}
Hi all,

I need some help with a trigger that attaches the date time to a field when an attachment is added to a custom object (patient__c). The trigger works fine when attaching a file to the patient record but when you try and attach a file to any other object it throws the error "Invalid id value for this SObject type"
Below is the trigger

trigger LastAttach on Attachment (After insert) {
    list<patient__c> ptlist= new  list<patient__c>() ;
    Patient__c ac= new Patient__c();
    for (attachment a : trigger.new ){
   
        ptlist.add( new Patient__c(Id=a.ParentID, Attachment_Added__c= System.now()));
   
            }
  //}
    update ptlist;
    }
Hi there,

I was hoping someone could shed some light on why this button won't fire when added to a list view. It works fine when added as a detail page button and used on one record. Basically I want to reduce the value of a field by 1 when the button is clicked. I am hoping to add it to a related object's list view so our users can select multiple records to apply the change to.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}

var records = {!GETRECORDIDS($ObjectType.Patient__c)};
if (records[0] == null) {

alert("Please select at least one record to update.");}
else {

var update_patient = new sforce.SObject("Patient__c");
update_patient.id = "{!Patient__c.Id}";
update_patient.Claims_remaining__c = {!Patient__c.Claims_Remaining__c} - 1;
result = sforce.connection.update([update_patient]);
}

window.location.reload();
Hi all,
I am trying to divide to numbers produced from aggregate result in an apex class. Am able to retrive the values (tx and wd) and present them on the VF page widget but would like to divide one by the other and present the result.i.e. tx/wd

public AggregateResult[] AvTx{
        get {
            return [SELECT SUM(Working_Days__c)wd,SUM(Total_Treatments__c)tx FROM Session__c WHERE Session_Completed__c = true AND OwnerID = :u AND Date__c >= :dtps AND (Session_Coverage_Type__c = 'Regular' OR Session_Coverage_Type__c = 'Regular Rescheduled') AND Session_Type__c != 'Emergency' AND Exclude_Session_From_Pod_Tier_Average__c = false];
            }

<apex:page controller="OpenSessionsList" readOnly="true">
   <apex:pageBlock >
        <apex:pageBlockTable value="{!AvTx}" var="r">
            <apex:column >
            <apex:facet name="header">Average Treatments</apex:facet>
             {!r['wd']}
             </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>    
</apex:page>
Ok guys I've got a humdinger here. I have a visualforce page (Session__c) that has a controller extension to update related fields on another object (Account). On the visualforce page I also have a command button using the URLFOR syntax to create a record of another object type (Patient__c). When I reference the fields in the controller extension on the visualforce page and try to create the new record (Patient__c) it doesn't recognise the default field values i.e. checkbox ticked. When I remove these fields from the visualforce page code the field default values are recognised once more.The page is for a custom object called Session__c with an extension to update fields on Account with an apex:CommandButton to create a new Patient__c record. I can't replicate it in our sandbox environment either!

 
Hi there,

I need to limit the number of records returned from this query. When i use the LIMIT clause before the last semi colon I get an error "mismatched input expecting semi colon". Any thoughts guys?

 public List<Event> start(){
      String query = 'Select Id,IsRecurrence,Event_Processed__c,Allowance_Type__c,Session_Coverage_Type__c,Session_Type__c,Message_from_Office_to_Podiatrist__c,Additional_Message_From_Office_to_Pod__c,Subject,OwnerId,owner.Name,WhatId,startdatetime,of_Session_Sharing_Day__c,Wing_1__c,Wing_2__c,Wing_3__c,Wing_4__c,Wing_5__c,Wing_6__c,Wing_7__c,Wing_8__c,Wing_9__c,Rooms_1__c,Rooms_2__c,Rooms_3__c,Rooms_4__c FROM Event WHERE Do_Not_Create_Session__c = false AND IsRecurrence = false AND Event_Processed__c = false AND RecordType.Name IN :lstEventRecordTypes AND What.RecordType.Name IN :lstAccountRecordTypes AND Owner.Title IN :lstOwnerTitles AND ActivityDate = NEXT_N_DAYS :'+ lastNumberOfDays ; 
      return Database.query(query);
I am using the code from the developer pages to mass update records from a list view. It works great in most instances except when it comes to checkbox fields. If I mass update records and check a checkbox field then update them again but update a different field it unchecks the previously checked boxes. None of the other fields on the page get updated unless they have new data inserted just seems to be with the checkbox fields. I am assuming it is because it is seeing them as field change but technically they should not be. Has anyone seen this behaviour before?

Here's the VF markup and controller extension i have used
http://www.salesforce.com/docs/developer/pages/Content/pages_compref_inputField.htm
Hi there, I have created a visualforce page to update records from a list view. I am able to retrieve the fields for editing but when I save it doesn't update the record. The fields I am trying to update are related to the Patient_Session__c object via a lookup relationship. Here's the VF markup

<apex:page standardcontroller="Patient_Session__c" recordSetVar="ProgressNotes" tabStyle="Patient_Session__c" sidebar="false">
<pbe:PageBlockTableEnhancerADV targetPbTableIds="Info" paginate="true" defaultPageSize="100" pageSizeOptions="5,10,20,30,40,50,100" />
  <style type="text/css">
        .myClass { width: 300px; }
    </style>
<h1>Mass Edit Patients</h1>
<apex:form >
    <apex:pageblock >
    <apex:pagemessages />
       <apex:pageBlockButtons >        
        <apex:commandButton value="Quick Save" action="{!quicksave}"/>
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Details" columns="1">
    <apex:pageBlockTable value="{!selected}" var="pgn" id="details">
        <apex:column headervalue="First Name">
            <apex:outputField value="{!pgn.Patient__r.First_Name__c}"/>
        </apex:column>
        <apex:column headervalue="Last Name">
            <apex:outputField value="{!pgn.Patient__r.Last_Name__c}"/>
        </apex:column>
        <apex:column headervalue="Patient Description">
            <apex:outputField value="{!pgn.Patient__r.Patient_Description__c}"/>
        </apex:column>
        <apex:column headervalue="Active">
            <apex:inputField value="{!pgn.Patient__r.Active__c}"/>
        </apex:column>
            </apex:pageBlockTable>
            </apex:pageBlockSection>   
        </apex:pageBlock>
    </apex:form>        
</apex:page>
I need help with a controller extension to retrieve and update parent records from a list view. We have a child object called Patient_Session__c that has a lookup to parent called Patient_c and want to use a visualforce page to update the parent records in mass edit mode from a list view of the child records.  Here's the extension I am using:

public with sharing class updatePatientInfo {
    public Patient_Session__c pgn;
    public Patient__c patient;

    public updatePatientInfo(ApexPages.StandardController controller) {
        this.pgn = (Patient_Session__c)controller.getRecord();
        this.patient = [SELECT Id,Name,Patient_Description__c,A_1__c,A_Frequency__c,B_1__c,B1_Frequency__c,B2_Frequency__c,C_1__c,C1_Frequency__c,C2_Frequency__c,D_1__c,D1_Frequency__c,D2_Frequency__c,X__c FROM Patient__c WHERE ID = :ApexPages.currentPage().getParameters().get('id')];
    }

    public PageReference saveRecord() {
        
    update patient;
    update pgn;  
        return null;
    }
 }

Here's the visualforcepage

<apex:page controller="updatePatientInfo" tabStyle="Patient_Session__c" sidebar="false">
<pbe:PageBlockTableEnhancerADV targetPbTableIds="details," paginate="true" defaultPageSize="100" pageSizeOptions="5,10,20,30,40,50,100" />
  <style type="text/css">
        .myClass { width: 300px; }
    </style>
<h1>Mass Edit Patients</h1>
<apex:form >
    <apex:pageblock >
    <apex:pagemessages />
       <apex:pageBlockButtons >        
        <apex:commandButton value="Quick Save" action="{!quicksave}"/>
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Details" columns="1">
    <apex:pageBlockTable value="{!selected}" var="pgn" id="details">
        <apex:column headervalue="First Name">
            <apex:inputField value="{!pgn.Patient__r.Patient_Description__c}"/>
        </apex:column>
            </apex:pageBlockTable>
            </apex:pageBlockSection>   
        </apex:pageBlock>
    </apex:form>        
</apex:page>

When I try to save the visualforce page I get this error
 "Error: Unknown constructor 'updatePatientInfo.updatePatientInfo()"

I am new to apex so any help would be greatly appreciated
Hi all, I am fairly new to apex coding and have created a scheduled class that checks a number of records to fit a criteria then performs a simple update to a checkbox field. The problem is I am getting the Apex CPU time limit exceeded as it is checking through over 5000 records. I believe I need to set this up as a batch to make it work. Can someone help me convert this code to a batch

global class SalesInvoicePaid implements Schedulable {

// Execute method
global void execute(SchedulableContext SC) {

// Code to be executed when the schedule class wakes up
    List <c2g__codaInvoice__c> siv = [SELECT ID, Paid__c
                           FROM c2g__codaInvoice__c
                           WHERE c2g__PaymentStatus__c = 'Paid' AND Paid__c = False AND c2g__InvoiceDate__c > 2014-07-01];        

    for(c2g__codaInvoice__c s: siv){
        s.Paid__c = true;           
    }
    update(siv);




// this section of code will abort the current schedule job
try {
system.abortJob(sc.getTriggerId());
} catch (exception e) {system.debug('#### schedule job exception while aborting:' + e);}


// reschedule the job
system.debug('#### schedule job executing');
scheduleNow();

}


global static void scheduleNow() {

// this section of code will schedule the next execution 1 minute from now
datetime thisTime = system.now().addHours(24);
integer minute = thisTime.minute();
integer second = thisTime.second();
integer hour = thisTime.hour();
integer year = thisTime.year();
integer month = thisTime.month();
integer day = thisTime.day();

String timeStamp = second + ' ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ? ' + year;
string jobName = 'SalesInvoicePaid';

SalesInvoicePaid p = new SalesInvoicePaid();
system.schedule(jobName, timeStamp , p);

}
}
Hi all,

I need some help with a trigger that attaches the date time to a field when an attachment is added to a custom object (patient__c). The trigger works fine when attaching a file to the patient record but when you try and attach a file to any other object it throws the error "Invalid id value for this SObject type"
Below is the trigger

trigger LastAttach on Attachment (After insert) {
    list<patient__c> ptlist= new  list<patient__c>() ;
    Patient__c ac= new Patient__c();
    for (attachment a : trigger.new ){
   
        ptlist.add( new Patient__c(Id=a.ParentID, Attachment_Added__c= System.now()));
   
            }
  //}
    update ptlist;
    }