• dfpitt
  • NEWBIE
  • 70 Points
  • Member since 2011

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

How can I create in APEX a DateTime for 8am in a specific timezone (not specifically the user's timezone nor GMT)

I need to then save that on a DateTime field, so I need this to be a DateTime variable not a string

Thanks in Advance
  • February 20, 2014
  • Like
  • 0

Hello,

 

I have been looking at an unusual situation.

 

I'm editing a record, specifically a lookup field on the record (which has up to this point been null). I have an action support (onchange) on the field that triggers a rerender on a picklist field that gets its options from a function in the controller that uses the lookup field value in a SOQL query.

 

The problem is that the value of the lookup field is still NULL when the query runs in the function.

 

However, if I fill in the lookup field, save and edit again, this time if I change the lookup field, the value IS up to date in the controller when I go and do the query.

 

What can be causing this? what can I do?

 

How can I get the value in the input field in a reliable way?

 

Here is the APEX Page and the Controller. (nPrescripcion.Medicamento__c is the lookup field that is not up to date in the controller when I run the query, I know this based on a system.debug statement)

 

<apex:page standardController="Prescripcion_Paciente__c" showHeader="false" sidebar="false" extensions="PrescripcionExtension">
    <apex:form style="padding-left:25px;padding-right:25px;padding-top:25px;">
        <apex:pageBlock title="Prescripción" tabstyle="Tratamiento__c"  mode="edit" >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" /> 
                <apex:commandButton action="{!cancel}" value="Cancelar" id="btn_Cancel"/>
                </apex:commandButton> 
            </apex:pageBlockButtons>  
            <apex:pageBlockSection id="MedicamentoVE" title="Medicamento" showHeader="true" collapsible="false" columns="2" >
                <apex:inputField label="Principio Activo" id="iPrincipioActivo"  required="true" value="{!Prescripcion_Paciente__c.Medicamento__c}">
                    <apex:actionSupport event="onchange" reRender="iMarca1,iMarca2" />
                </apex:inputField>
                <apex:selectList value="{!Prescripcion_Paciente__c.Marca_Comercial_1__c}" size="1" id="iMarca1" required="false">
                    <apex:selectOptions value="{!MarcasComerciales}"/>
                </apex:selectList>
            </apex:pageBlockSection>     
        </apex:pageBlock>
    </apex:form>  
</apex:page>

 

public class PrescripcionExtension {
    private Prescripcion_Paciente__c nPrescripcion;
    public ApexPages.StandardController stdCtrl { set; get; }
   
    public PrescripcionExtension (ApexPages.StandardController controller) {
        this.nPrescripcion= (Prescripcion_Paciente__c)controller.getRecord();
        stdCtrl=controller;
    }
    
    public List<SelectOption> getMarcasComerciales()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--Ninguna--'));
        options.add(new SelectOption('Otra','Otra'));
        system.debug(nPrescripcion.medicamento__c);
        Tratamiento__c[] nMeds = [Select marcas__c from Tratamiento__c where id=:nPrescripcion.medicamento__c];
        if (nMeds.size()>0){
            if (nMeds[0].marcas__c!=null && nMeds[0].marcas__c!='')
            {
                String[] marcas = nMeds[0].marcas__c.split(';');
                for (Integer j=0;j<marcas.size();j++)
                {
                  options.add(new SelectOption(marcas[j],marcas[j]));
                }
            }
        }
        return options;
    }
}

 

 

 

Hello,

 

Is there a way to remove the "Name at Company" text from the Home Tab?

  • March 15, 2013
  • Like
  • 0

Hello,

 

I have a few sensitive fields in a custom object that whenever they are changed a workflow rule sends out a VF Email.

 

This VF email, among other things, prints the field history table for the record in the email.

 

When I make a change in one of these fields, the email is sent. But, the printed field history table is missing the most recent change.

 

It feels like the workflow rule is being executed before the new change is inserted into the field history table. Anybody knows if this assumption is right? and if so, what can I do to get an email with the fully updated field history, without resorting to a time-based workflow rule, which will have me wait for at least an hour to get the email.

 

thanks in advance

 

dfpitt

 

  • February 15, 2012
  • Like
  • 0

Hello,

 

I have a function in an APEX controller that changes the data in a custom field and updates the custom object.

 

I'm trying to call it from a VF page, without having the page refresh. I tried:

- Calling it from an APEX:CommandButton

- Calling it from javascript using an APEX:ActionFunction

     <apex:actionFunction name="the_function" action="{!Function}" id="action_thefunction"/>

 

In both cases, the APEX function runs and then the VF page refreshes.

 

How can I avoid the refresh?

  • January 20, 2012
  • Like
  • 0

Hello,

 

I have a VF page that simply shows the detail of a custom object with inline editing enabled. I added an apex button that is calling the {!save} method. But, if i change a field and click the button, the page simply refreshes and I lose the changes. Why is the {!save} method not saving?

 

<apex:page standardController="CustomObject__c" showHeader="false" sidebar="false" >
    <apex:form >
        <apex:commandButton action="{!save}" value="TEST SAVE" id="TESTSAVE" />
        <apex:detail inlineEdit="true" relatedList="true" relatedListHover="true" />
    </apex:form>
   
</apex:page>

  • January 03, 2012
  • Like
  • 0

How can I import an image into salesforce via the API?

 

I want to be able to import the image via the API and attach it to a custom object. Once attached, I already have a VF page in place that shows the Image.

 

Any help would be greatly appreciated.

 

Daniel

  • December 22, 2011
  • Like
  • 0

Hello,

 

I have an email template that shows information from a custom object and from a related list to that custom object. I want to be able to hide the table headers whenever the related list has no records. I have tried using <apex: outputpanel rendered...> but it has n't worked, as I haven't been able to get the size of the list, so that if the outputpanel is rendered when the size is greater than 0.

 

Any ideas would be greatly appreciated.

  • November 17, 2011
  • Like
  • 0

Hello,

 

How can I change the salutation message shown on the homepage?

 

In english it makes sense as it says: "Name at CompanyName"

 

But in spanish it doesn't make sense as it says: "Name a las CompanyName"

 

any suggestions?

  • November 01, 2011
  • Like
  • 0

I have 3 custom objects: A, B and C.

 

B: Has a master-detail relationship with A

C: Has a master detail relationship with B and a lookup relationship with A

 

If I am viewing a record of a custom object type B and I create from there a NEW record of type C, it automatically fills in the field that relates C to B, but the field that relates C to A is empty. Given that B is connected to a specific A, i would like that A to be related by default to C.

 

How can I do this? Does this need to be a new custom button?

  • October 26, 2011
  • Like
  • 0

Hello,

 

I'm fairly new to force.com.

 

I have a customer_c custom object and a waitlist_c custom object. I want to have a button in the Customer tab that when clicked creates a record in the waitlist_c custom object with the customer id and a timestamp.

 

Can anybody help me get started on this?

  • October 11, 2011
  • Like
  • 0

Hello,

 

I'm brand new to APEX, I need some help.

 

I have a custom object called Patient__c and a custom object called EMR__c, I want to automatically create an EMR record when i create a patient, with just the patient field filled, the rest should be blank (and none other EMR fields are setup as required fields).

 

I created the trigger below, but I get the following error when saving a patient (the new patient's name is John Smith):

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger insert_EMR caused an unexpected exception, contact your administrator: insert_EMR: execution of AfterInsert caused by: System.StringException: Invalid id: John Smith: Trigger.insert_EMR: line 7, column 82

 

trigger insert_EMR on Patient__c (after insert) {

List<EMR__c> ListA = new List<EMR__c>();

for (Patient__c pat : trigger.new)
   {
    EMR__c emr1= new EMR__c(Patient__c=pat.name);
    ListA.add(ante);
    insert ListA;
   }
}

 

any ideas would be appreciated,

 

thanks

  • October 11, 2011
  • Like
  • 0
Hello,

How can I create in APEX a DateTime for 8am in a specific timezone (not specifically the user's timezone nor GMT)

I need to then save that on a DateTime field, so I need this to be a DateTime variable not a string

Thanks in Advance
  • February 20, 2014
  • Like
  • 0

Hello,

 

I have been looking at an unusual situation.

 

I'm editing a record, specifically a lookup field on the record (which has up to this point been null). I have an action support (onchange) on the field that triggers a rerender on a picklist field that gets its options from a function in the controller that uses the lookup field value in a SOQL query.

 

The problem is that the value of the lookup field is still NULL when the query runs in the function.

 

However, if I fill in the lookup field, save and edit again, this time if I change the lookup field, the value IS up to date in the controller when I go and do the query.

 

What can be causing this? what can I do?

 

How can I get the value in the input field in a reliable way?

 

Here is the APEX Page and the Controller. (nPrescripcion.Medicamento__c is the lookup field that is not up to date in the controller when I run the query, I know this based on a system.debug statement)

 

<apex:page standardController="Prescripcion_Paciente__c" showHeader="false" sidebar="false" extensions="PrescripcionExtension">
    <apex:form style="padding-left:25px;padding-right:25px;padding-top:25px;">
        <apex:pageBlock title="Prescripción" tabstyle="Tratamiento__c"  mode="edit" >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" /> 
                <apex:commandButton action="{!cancel}" value="Cancelar" id="btn_Cancel"/>
                </apex:commandButton> 
            </apex:pageBlockButtons>  
            <apex:pageBlockSection id="MedicamentoVE" title="Medicamento" showHeader="true" collapsible="false" columns="2" >
                <apex:inputField label="Principio Activo" id="iPrincipioActivo"  required="true" value="{!Prescripcion_Paciente__c.Medicamento__c}">
                    <apex:actionSupport event="onchange" reRender="iMarca1,iMarca2" />
                </apex:inputField>
                <apex:selectList value="{!Prescripcion_Paciente__c.Marca_Comercial_1__c}" size="1" id="iMarca1" required="false">
                    <apex:selectOptions value="{!MarcasComerciales}"/>
                </apex:selectList>
            </apex:pageBlockSection>     
        </apex:pageBlock>
    </apex:form>  
</apex:page>

 

public class PrescripcionExtension {
    private Prescripcion_Paciente__c nPrescripcion;
    public ApexPages.StandardController stdCtrl { set; get; }
   
    public PrescripcionExtension (ApexPages.StandardController controller) {
        this.nPrescripcion= (Prescripcion_Paciente__c)controller.getRecord();
        stdCtrl=controller;
    }
    
    public List<SelectOption> getMarcasComerciales()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--Ninguna--'));
        options.add(new SelectOption('Otra','Otra'));
        system.debug(nPrescripcion.medicamento__c);
        Tratamiento__c[] nMeds = [Select marcas__c from Tratamiento__c where id=:nPrescripcion.medicamento__c];
        if (nMeds.size()>0){
            if (nMeds[0].marcas__c!=null && nMeds[0].marcas__c!='')
            {
                String[] marcas = nMeds[0].marcas__c.split(';');
                for (Integer j=0;j<marcas.size();j++)
                {
                  options.add(new SelectOption(marcas[j],marcas[j]));
                }
            }
        }
        return options;
    }
}

 

 

 

Hello,

 

Is there a way to remove the "Name at Company" text from the Home Tab?

  • March 15, 2013
  • Like
  • 0

Hello,

 

I have a few sensitive fields in a custom object that whenever they are changed a workflow rule sends out a VF Email.

 

This VF email, among other things, prints the field history table for the record in the email.

 

When I make a change in one of these fields, the email is sent. But, the printed field history table is missing the most recent change.

 

It feels like the workflow rule is being executed before the new change is inserted into the field history table. Anybody knows if this assumption is right? and if so, what can I do to get an email with the fully updated field history, without resorting to a time-based workflow rule, which will have me wait for at least an hour to get the email.

 

thanks in advance

 

dfpitt

 

  • February 15, 2012
  • Like
  • 0

Hello,

 

I have a function in an APEX controller that changes the data in a custom field and updates the custom object.

 

I'm trying to call it from a VF page, without having the page refresh. I tried:

- Calling it from an APEX:CommandButton

- Calling it from javascript using an APEX:ActionFunction

     <apex:actionFunction name="the_function" action="{!Function}" id="action_thefunction"/>

 

In both cases, the APEX function runs and then the VF page refreshes.

 

How can I avoid the refresh?

  • January 20, 2012
  • Like
  • 0

Hello,

 

I have a VF page that simply shows the detail of a custom object with inline editing enabled. I added an apex button that is calling the {!save} method. But, if i change a field and click the button, the page simply refreshes and I lose the changes. Why is the {!save} method not saving?

 

<apex:page standardController="CustomObject__c" showHeader="false" sidebar="false" >
    <apex:form >
        <apex:commandButton action="{!save}" value="TEST SAVE" id="TESTSAVE" />
        <apex:detail inlineEdit="true" relatedList="true" relatedListHover="true" />
    </apex:form>
   
</apex:page>

  • January 03, 2012
  • Like
  • 0

How can I import an image into salesforce via the API?

 

I want to be able to import the image via the API and attach it to a custom object. Once attached, I already have a VF page in place that shows the Image.

 

Any help would be greatly appreciated.

 

Daniel

  • December 22, 2011
  • Like
  • 0

Why my javascript does not work ?

 

Here is what I tested:

 

(1) create a custom component 'test' ---type:  HTML Area, ticked "show HTML",  content:   <script> alert('testing....);</script>

(2) add this component to my default home page layout

(3) check "show custom sidebar components on all pages"

 

(4) click on any TAB,  the component only display the name "test" on the sidebar, no javascript running

(5) same thing if the javascript is like

<script>

function init() {
   alert("testing...");
}
window.onload = init;

</script>

 

Any help will be greatly appreciated.

Hello,

 

I have an email template that shows information from a custom object and from a related list to that custom object. I want to be able to hide the table headers whenever the related list has no records. I have tried using <apex: outputpanel rendered...> but it has n't worked, as I haven't been able to get the size of the list, so that if the outputpanel is rendered when the size is greater than 0.

 

Any ideas would be greatly appreciated.

  • November 17, 2011
  • Like
  • 0
I have a VF email template that displays the related list great. However, I want to supress the entire section (including the header) if there are no rows returned. How would I go about achieving this?
Here is the existing code.
Thanks
<messaging:emailTemplate subject="New Subscription for {!relatedTo.Account.Name}" recipientType="Contact" relatedToType="ServiceContract">
    <messaging:htmlEmailBody >


        <span class="sectionTitle">SUBSCRiPTION DETAIL</span><br/>
        <apex:panelGrid columns="2">
       
            <apex:outputLabel for="CustomerName" value="End Customer:"/>
            <apex:outputText id="CustomerName" value="{!relatedTo.Account.Name}"/>
            <apex:outputLabel for="CustomerID" value="Account ID:"/>
            <apex:outputText id="CustomerID" value="{!relatedTo.Account.Customer_ID__c}"/>
            <apex:outputLabel for="PONumber" value="PO Number: "/>
            <apex:outputText id="PONumber" value="{!relatedTo.PO__c}"/>
 
         </apex:panelGrid>

        <p>
            &nbsp;
        </p>  
           
<span class="sectionTitle">Support</span><br/>

<table border="0" cellspacing="0" cellpadding="4" class="list">
    <tr>
        <th>Serial Number</th>
        <th>Product</th>
        <th>Type</th>
        <th>Start Date</th>
        <th>End Date</th>
    </tr>
    <apex:repeat var="SN" value="{!relatedTo.ContractLineItems}">
       <apex:outputPanel layout="none" rendered="{!SN.PricebookEntry.Product2.License_Feature__r.Name  == Support'}">    
    <tr>
        <td> {!SN.Asset.Name} </td>
        <td> {!SN.PricebookEntry.Product2.Name} </td>
        <td> {!SN.PricebookEntry.Product2.Level__c} </td>                
        <td> {!month(SN.StartDate)}/{!day(SN.StartDate)}/{!year(SN.StartDate)} </td>
        <td> {!month(SN.EndDate)}/{!day(SN.EndDate)}/{!year(SN.EndDate)} </td>
    </tr>
       </apex:outputPanel>    
    </apex:repeat>
</table>

     
</messaging:htmlEmailBody>
</messaging:emailTemplate>

 

I have created a trigger to prevent users from deleting an Account if a field is populated. However, instead of the error message appearing on the Account page I get this:

 

 

Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "This Account has a Community Code therefore it can not be deleted". 

Clickto return to the previous page.

 

 

Do I need a  "catch"?

 

My trigger:

  trigger CommunityCode on Account  (before delete)
  {
    if(System.Trigger.IsDelete)
        {
for (Account a : Trigger.old) 
if (a.Community_Code__c != Null) {
a.addError ('This Account has a Community Code therefore it can not be deleted');
}
}
}

 

  • October 21, 2011
  • Like
  • 0
Hey someone tell me the way to add a letterhead that has been created in a visualforce email template.Thanks in advance.I have seen that only in html we can add letterhead.Is there any way to add the same letterhead in visualforce  email template
  • November 21, 2009
  • Like
  • 0

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions