• Jamsie
  • NEWBIE
  • 33 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 12
    Replies
Hi everyone,

I'm trying to output the contents of a wrapper class object based on a self-referncing heirarchy. I want to represent this in a fixed number of columns with additional items wrapping as follows:

User-added image

The wrapper is defined as:
 
public class CapabilityHierarchy {
        public  CapabilityHierarchy(Capability__c c){
            this.capability = c;
        }
        public Capability__c capability {get;set;}
        public List<CapabilityHierarchy> child_list {get;set;}       
    }

I have tried useing apex:repeat to render the levels but this leads to all output in a single cell when using an apex:pageblocksection or apex:panelgrid.  I've also tried using a span with defined width but this did not work either.

The markup for the basic output of the hierachies is detailed below.  Any help is much appreciated.
 
<apex:page standardController="Capability__c" extensions="CapabilitiesMatrixController" recordSetVar="capabilities"> 
    <apex:repeat var="ch1" value="{!hierarchy}">
        <h2>Level 1: {!ch1.capability.Title__c}</h2>
        <apex:repeat var="ch2" value="{!ch1.child_list}">  
            <apex:outputText value="Level 2: {!ch2.capability.Title__c}" styleClass=""/>
            <apex:repeat var="ch3" value="{!ch2.child_list}">
                <apex:outputText value="{!ch3.capability.Title__c}"/>
            </apex:repeat>
        </apex:repeat>
    </apex:repeat>          
</apex:page>

Thanks,
James.
 

Hi everyone,

 

I am trying to style rows in a table of Tasks based upon the due date and time of the tasks.

 

<apex:page showHeader="false" controller="atTaskListController">
<style type="text/css">
    .normalPriority{font-weight:bold; background-color: #FFFFCC;}
    .highPriority{font-weight:bold; background-color: #FFFFCC;}
    .critical Priority{font-weight:bold; background-color: #FFFFCC;}
</style>

 <apex:outputPanel id="taskList">
        <apex:pageBlock title="Callback Task List" >
             <apex:pageBlockTable value="{!tasks}" var="t">
                 <apex:column headerValue="Task"> <apex:outputLink value="/{!t.id}" target="_parent"> {!t.Task_ID__c}</apex:outputLink></apex:column>
                 <apex:column headerValue="Subject"><apex:outputLink value="/{!t.id}"> {!t.Subject}</apex:outputLink></apex:column>
                 <apex:column value="{!t.ActivityDate}" styleClass="{!style}"/>
                 <apex:column value="{!t.Due_Time__c}" />
                 <apex:column value="{!t.Priority}"/>
                 <apex:column value="{!t.Status}"/>
                 <apex:column value="{!t.whatid}"/>
                 <apex:column value="{!t.OwnerId}"/>
             </apex:pageBlockTable>
         </apex:pageBlock>
     </apex:outputPanel>
</apex:page>

 

 

public with sharing class atTaskListController {
    private List<Task> tasks = new List<Task>();
    private Task thisTask {get;set;}
    Map<Id, String> styleMap = new Map<Id, String>();
    
    public atTaskListController () {
        Schema.Describesobjectresult r = Task.sObjectType.getDescribe();
        Map<String, Schema.RecordTypeInfo> rtMap = r.getRecordTypeInfosByName();
        Id tRt = rtMap.get('Callback Request').getRecordTypeId();
        tasks = [select id, whoid, whatid,OwnerId, Subject, Priority, Task_ID__c,Due_Time__c, Due_Date_Time__c, ActivityDate, Status from Task 
                 where OwnerId= :UserInfo.getUserId() AND RecordTypeId=:tRt AND (Status!='Cancelled' OR Status!='Completed')];
                 
        for(Task tk: tasks){
            if(System.now()>=tk.ActivityDate){
                styleMap.put(tk.id, 'overdue');
            }else if(System.now()>=tk.Due_Date_Time__c.addHours(-2)){
                styleMap.put(tk.id, 'criticalPriority');
            }else if(System.now()>=tk.Due_Date_Time__c.addHours(-4)){
                styleMap.put(tk.id, 'highPriority');
            }else{
                styleMap.put(tk.id, 'normalPriority');
            }
        }                    
    }
    public List<Task> getTasks(){
        return tasks;
    }
     public String getStyle() {
        return styleMap.get(thisTask.Id);
    }
}

My problem is that I cannot figure out how to get a the task 't' from the page into the controller.  I'd like to pass it to getStyle(Task t) but cannot work out how to do this.  I cannot rely upon user interaction to do this, it must just happen.

 

Any help much appreciated.

Cheers,

James.

  • February 24, 2012
  • Like
  • 0

Hi everyone.

 

I wish to grant a group of users the Manage Cases permission.  However, I do not want to allow them to delete Cases. Therefore, I have written a Trigger (see code below) to constrain the delete Case permission to Sys Admins and the API.  This works well when users work through the GUI.

 

However, when the users click on a custom button which causes a custom controller to delete a Case they are returned the error from the Trigger.

 

I can see that it is my call to  UserInfo.getProfileId(); that is causing the problem. 

 

Is there any way to know that the Trigger is has been called from within a controller an therefore permit the deletion?

 

Many thanks,

James.

 

trigger preventUnauthorisedCaseDeletion on Case (before delete) {

    System.debug('-- Prevent Case Deletion | Trigger Called');

    List<String> pNames = new List<String>{'System Administrator', 'APIOnly'};
    List<Profile> profiles = new List<Profile>([select id, Name from Profile where name in :pNames]);

    for(Case c : Trigger.old){
        Boolean authorised=false;        
        Id userProfileId = UserInfo.getProfileId();
        System.debug('-- Prevent Case Deletion | Current User: ' + UserInfo.getName());
        for(Profile p : profiles){
            if(userProfileID == p.Id){
                authorised = true;
                System.debug('-- Prevent Case Deletion | Current User OK: ' + UserInfo.getName());
                break;
            }
        }
        if(!authorised){
            System.debug('-- Prevent Case Deletion | Current User UNAUTHORISED: ' + UserInfo.getName());
            c.addError('You do not have sufficient permission to delete a Case. If you have good reason to have this Case deleted please raise a Helpdesk incident.');
        }
    }
}

 

  • January 18, 2012
  • Like
  • 0

Hi Everyone.

 

I've built a page to allow users to select a Case Record Type from a favourites list or all Case Record Types.  It works well except the All Case Types list shows all the Case Record Types in our org rather than those normally accessible to the current user.

 

My question: how can I access the list of Case Record Types available to the user from their Profile in my controller?

 

Thanks in advance,

James.



  • August 17, 2011
  • Like
  • 0

Hi all,

 

I just discovered a problem where I was using some Apex to set a Task due date based upon a service level agreement.  I was using...

 

t.Due_Date_Time__c =  BusinessHours.add(bh.id, t.CreatedDate, SLA_hours * 60 * 60 * 1000L);

 

The BusinessHours class applies daylight savings time but the Task CreatedDate is expressed in GMT.  Therefore I need to convert CreatedDate to the local Datetime.  I could not find an API call to achieve this in one step so built a method in a utility class:

 

    public static Datetime getLocalDateTime(Datetime z)
    {    
        Datetime l = z.Date(); //local date at 00:00:00
        l = l.addHours(z.hour());
        l = l.addMinutes(z.minute());
        l = l.addSeconds(z.second());
        
        return l;
    }

 

Applying this to my original code gives:

 

t.Due_Date_Time__c =  BusinessHours.add(bh.id, Utility.getLocalDateTime(t.CreatedDate), SLA_hours * 60 * 60 * 1000L);

 

This fixed my bug .

 

I hope you find it useful.

  • April 07, 2011
  • Like
  • 0

Hi there,

 

I have built a trigger (on insert) for a custom object (Mail Item) that sets the owner to be a particular queue depending on the recordtype selected during creation.

 

I am now trying to write the test class.  My problem is that I cannot work out how to create a new record type and assign it to my test created Mail Item object.

 

I can't rely upon a particular record type being in the system so cannot run a query on the record  types.

 

Any help is much appreciated.

Thanks,

James.

  • April 21, 2010
  • Like
  • 0

I am trying to use a same VF component more than once in a VF page. I can see that the last used component alone works fine and the others give no response. 

 

Could anyone please tell if there is a problem in using the same component twice? 

 

Below are the generic code with standard objects for your convenience:

 

Component :

 <apex:component controller="ContactEmailController">

<apex:actionFunction action="{!dispFunc}" name="callFunc"/>
<apex:inputField value="{!opp.accountId}" onchange="callFunc();"/>
{!accnt.Name}
</apex:component>

 

Component Controller :

public class ContactEmailController {


public Account accnt{get;set;}
public Opportunity opp{get;set;}

public PageReference dispFunc(){
if(opp.AccountId!=null)
accnt = [select id, name from Account where id=:opp.AccountId];
return null;
}

public ContactEmailController(){
accnt = new Account();
opp = new Opportunity();
}
}

 

Page using the component :

<apex:page >
<apex:form >
<c:ContactEmail />
</apex:form>
<apex:form >
<c:ContactEmail />
</apex:form>
</apex:page>

 

I am trying to get this working for a long time now. Please help.

Thanks in advance. 

 

Hi everyone,

 

I am trying to style rows in a table of Tasks based upon the due date and time of the tasks.

 

<apex:page showHeader="false" controller="atTaskListController">
<style type="text/css">
    .normalPriority{font-weight:bold; background-color: #FFFFCC;}
    .highPriority{font-weight:bold; background-color: #FFFFCC;}
    .critical Priority{font-weight:bold; background-color: #FFFFCC;}
</style>

 <apex:outputPanel id="taskList">
        <apex:pageBlock title="Callback Task List" >
             <apex:pageBlockTable value="{!tasks}" var="t">
                 <apex:column headerValue="Task"> <apex:outputLink value="/{!t.id}" target="_parent"> {!t.Task_ID__c}</apex:outputLink></apex:column>
                 <apex:column headerValue="Subject"><apex:outputLink value="/{!t.id}"> {!t.Subject}</apex:outputLink></apex:column>
                 <apex:column value="{!t.ActivityDate}" styleClass="{!style}"/>
                 <apex:column value="{!t.Due_Time__c}" />
                 <apex:column value="{!t.Priority}"/>
                 <apex:column value="{!t.Status}"/>
                 <apex:column value="{!t.whatid}"/>
                 <apex:column value="{!t.OwnerId}"/>
             </apex:pageBlockTable>
         </apex:pageBlock>
     </apex:outputPanel>
</apex:page>

 

 

public with sharing class atTaskListController {
    private List<Task> tasks = new List<Task>();
    private Task thisTask {get;set;}
    Map<Id, String> styleMap = new Map<Id, String>();
    
    public atTaskListController () {
        Schema.Describesobjectresult r = Task.sObjectType.getDescribe();
        Map<String, Schema.RecordTypeInfo> rtMap = r.getRecordTypeInfosByName();
        Id tRt = rtMap.get('Callback Request').getRecordTypeId();
        tasks = [select id, whoid, whatid,OwnerId, Subject, Priority, Task_ID__c,Due_Time__c, Due_Date_Time__c, ActivityDate, Status from Task 
                 where OwnerId= :UserInfo.getUserId() AND RecordTypeId=:tRt AND (Status!='Cancelled' OR Status!='Completed')];
                 
        for(Task tk: tasks){
            if(System.now()>=tk.ActivityDate){
                styleMap.put(tk.id, 'overdue');
            }else if(System.now()>=tk.Due_Date_Time__c.addHours(-2)){
                styleMap.put(tk.id, 'criticalPriority');
            }else if(System.now()>=tk.Due_Date_Time__c.addHours(-4)){
                styleMap.put(tk.id, 'highPriority');
            }else{
                styleMap.put(tk.id, 'normalPriority');
            }
        }                    
    }
    public List<Task> getTasks(){
        return tasks;
    }
     public String getStyle() {
        return styleMap.get(thisTask.Id);
    }
}

My problem is that I cannot figure out how to get a the task 't' from the page into the controller.  I'd like to pass it to getStyle(Task t) but cannot work out how to do this.  I cannot rely upon user interaction to do this, it must just happen.

 

Any help much appreciated.

Cheers,

James.

  • February 24, 2012
  • Like
  • 0

Hi Everyone.

 

I've built a page to allow users to select a Case Record Type from a favourites list or all Case Record Types.  It works well except the All Case Types list shows all the Case Record Types in our org rather than those normally accessible to the current user.

 

My question: how can I access the list of Case Record Types available to the user from their Profile in my controller?

 

Thanks in advance,

James.



  • August 17, 2011
  • Like
  • 0

I have very simple VF Page rendered as a pdf with a section where I set inline style with margins using the following code:

 

<div style="margin-left:250px; margin-top:250px;">
 <apex:panelGrid columns="1" width="100%" >                       
    
        <apex:outputText value="Some Text" id="some text"/>
                
</apex:panelGrid>
</div>

 

The margin left property worked, however the margin-top property did not.  Could someone shed some light on this?

 

Thanks!

 

In my apex code, system.now() returns the current Datetime based on a GMT calendar. My aim is to get the date time value in my local time zone.Since we have day light saving, I didn't think  about manipulating the time difference.

 

I would appreciate your suggestions.

 

Under personal information, I have set the time zone as "Time Zone(GMT-05:00) Eastern Daylight Time (America/New_York)".

 

 

 

 

Hi ALL 

 

I am trying to write a trigger to update Casecomment  depending on the Task Description and here is my code

trigger UpdateCaseCom on Task (after insert) {

List<CaseComment> casecom = new List<CaseComment>();

for (Task t : Trigger.new)
{
  if (t.subject=='Call'){
    

   CaseComment cc = new CaseComment();
    
    cc.ParentId = t.WhatId;
    cc.CommentBody = t.Description;
     casecom.add(cc);
  }

update casecom;
  }

}

 

 

This code gets saved but when i try to save the Task it gives me the error

 

 

 

Apex trigger UpdateCaseCom caused an unexpected exception, contact your administrator: UpdateCaseCom: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.UpdateCaseCom: line 17, column 1

 

 

I have a number of custom objects that I used in a salesforce.com organization. Many of these objects use auto-numbered Name fields.

The problem occurs when running Apex tests. Although the data created during the tests is never committed, creating new records in objects with auto-numbering increments the auto number. Because of the recursive nature of the tests (and some behind the scenes testing whenever new code is deployed from the Force.com IDE), my users are getting disconcerting jumps in things like order numbers, purchase requisition numbers, inventory numbers, etc. I tell them that the numbers are truly meaningless, but missing numbers is still a point of concern.

So I have a few questions.

Is there any programmatic way to find out what the "next number" is for an object?

Is there any programmatic way to suspend, and then resume, auto numbering?

Is this something I just need to get my users to live with?

Comments are appreciated.
Hello Everyone,

I hope you can help me on this..Im working with singleEmail to send an email to a particular sales representative on every territory. but every time I invoked my trigger via update of my objects, it returns an exception. The error is: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.\.: Trigger.Notify_Rep_Trigger: line 90, column 21

my code is written below:

Account territory = [select Territory_Name__c from Account where Id =:data.Account_ID__c];
           
            if(territory.Territory_Name__c != null)
            {
               
                List<string> splitID = territory.Territory_Name__c.split(';', -1);
                Set<string> tID = new Set<string>();
                tID.clear();
               
                List<Territory> territoryId = [Select id From Territory where name in :splitID];
               
                List<UserTerritory> usersId = [Select UserId From UserTerritory where territoryid in :territoryId];
               
                for(integer x=0; x < usersId.size(); x++)
                {
                        tID.add(usersId[x].UserId);
                }
               
                List<User> emailAdd = [select Id, email from User where Id in :tID];
               
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                List <String> Addresses = new List<String>();
           
                for(integer i=0; i < emailAdd.size(); i++)
                {
                    //String[] toAddresses = new String[] {emailAdd[i].email};
       
                    //mail.setToAddresses(toAddresses);
                    mail.setCcAddresses(ccAddresses);
                   
                    mail.setBccSender(true);
                    mail.setUseSignature(false);
                    mail.setSaveAsActivity(false);
                   
                    String toTargetObjects = (string)emailAdd[i].Id;
                   
                    system.debug('target object deb:'+toTargetObjects);
                    system.debug('data id deb:'+data.Id);
                   
                    mail.setTargetObjectId(toTargetObjects);
                    mail.setWhatId(toTargetObjects);
       
                    mail.setTemplateId(templateId);
                   
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                }
            }
        }

any suggestion? I would really appreciate it if you can help me on this.


Thanks in advance,

Wilson




Message Edited by wilson34 on 11-21-2008 01:50 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:53 AM
Hi, All, I tried to get the comments that user entered in the approval process page, i created a trigger on my object, here is part of the code:
 
Code:
if (objNew.Status__c  == 'Declined') 
      && 
      trigger.IsAfter)
     {
      
      ProcessInstance[] instances = [Select p.CreatedDate, p.Id, 
      (Select Comments, StepStatus From Steps where StepStatus = 'Rejected') 
      from ProcessInstance p where TargetObjectId = : objNew.Id];
      
      string comment = '';
      for(ProcessInstance step :instances )
      {
       
       if(step.Steps.Size() > 0) // make sure it has step and the step status is 'Rejected'
     {
      comment = step.Steps[0].Comments;
     }
    }

 // start create new task...
 Task t = new Task();
 t.Description = coment;
 ....
 insert t;

}

 
the newObj.Status__c is updated thru the field update in the approval action
 
the issue here is the comment is always blank as step.Steps.Size()  is always 0, looks like the processInstanceStep is not inserted until this trigger is finished
 
so how can i get the comments that user entered in the approval page
  • October 22, 2008
  • Like
  • 0