• Ritchieb
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 13
    Replies

Hi All,

 

I have made a custom object called RAG_Status__c as a child of the Master object Acctounts, the relationship is called Account__C.

 

My custom object has the following fields, Active__c (checkbox), Effective_Date__c (formula - Date/Time with created date in as the formula).

 

I wish to flag only the most recent child of an Account as active and flag all other child objects as inactive. I found a post here that seems to do what I need, but I have not been able to get it to work.

 

The post is here: http://boards.developerforce.com/t5/Apex-Code-Development/Trigger-to-Update-Status/td-p/264273/highlight/true

 

Can anyone tell me what I am doing wrong? This saves and is active but doesnt amend the records as expected?

 

My code i have amended is here; 

 

trigger RAGinactiveActive on RAG_Status__C(after insert, after update) {

    if(!Trigger.isExecuting){ //check that the trigger isnt already executing
    

Set<Id> emtoupdate = new Set<Id> ();

if (Trigger.isInsert || Trigger.isUpdate ) {
for (RAG_Status__C c: Trigger.New) {
emtoupdate.add(c.Account__c);
}
}

if (Trigger.isDelete) {
for (RAG_Status__C c: Trigger.Old) {
emtoupdate.add(c.Account__c);
}
}

List<RAG_Status__C> ctxsToUpdate = new List<RAG_Status__C>{};

boolean firstRecord = true;

for(RAG_Status__C ctx : [Select Id, Active__c, Effective_Date__c from RAG_Status__C where Account__c =: emtoupdate ORDER BY Effective_Date__c DESC])
{
if(firstRecord)
{
ctx.Active__c = True;
firstRecord = false;
}
else
ctx.Active__c = False;
 
ctxsToUpdate.add(ctx);
 
}
if(ctxsToUpdate != null && !ctxsToUpdate.IsEmpty())
Database.update(ctxsToUpdate);
 
}
}

 

 

 

 

 

Hi All,

 

I am overwriting the case detail page with a tabbed style visualforce page. I have had various problems with related lists not being supported by apex code. I have so far rebuilt related emails and the caseComments lists but am strugling with "CaseArticles". When I view the page via the customer portal I get the error below.

 

CaseArticles' is not a valid child relationship name for entity Case

 

Code

 

<apex:tab label="Related Articles"  name="Articles" id="tabCaseArticles2">
         <apex:relatedList subject="{!case}"  list="CaseArticles" />
</apex:tab>-->

 

When using the default case detail page customer portal users can see the related articles list. But when I use the code above it falls over. Ive looked up the name of the list in the API WSDL file and it is correct. Users have permissions to the page, article types ect. Without the code the Portal users can veie the same page fine.

 

Any ideas how to get round this?

Hi All,

 

I am new to apex code and have managed. to get an apex class to redirect profiles to two different pages dependent on an if statement. I now need to create a test class. Would anyone be able to help create one?

 

Here is the code;

 

public class overrideCon {
   String recordId;
   
public overrideCon(ApexPages.StandardController 
       controller) {recordId = controller.getId();}

public PageReference redirect() {
  Profile p = [select name from Profile where id = 
               :UserInfo.getProfileId()];
  if ('Customer Portal User'.equals(p.name) 
      || 'Partner Portal User'.equals(p.name) 
      || 'Customer Portal Manager Custom'.equals(p.name)) 
      {
      //If Portal User show Portal Page
       PageReference customPage =  Page.portalCasePage;
       customPage.setRedirect(true);
       customPage.getParameters().put('id', recordId);
       return customPage;
      } else {
      //If NOT Portal User show Standard Page
       PageReference customPage2 =  Page.standardCasePage;
       customPage2.setRedirect(true);
       customPage2.getParameters().put('id', recordId);
       return customPage2;
    
      }
   }
}

Hi All,

 

I am trying to build a simple pie chart with visual force / Apex. THe below code saves without errors but does not produce a chart. Can anyone point out what I am doing wrong?

 

Apex class;

 

This should be creating the pie chart data grouping cases by status.

 

public with sharing class CasesPieController {

public CasesPieController ()
{
}

public List<AggregateResult> getCasesByStatus()
{
    AggregateResult[] result = [SELECT COUNT(id) cnt, Status FROM Case GROUP BY Status];
    return result;
}



}

 

Visual Force page;

 

This should be a simple page with one block and one chart. The block displays but the chart doesnt at all.

 

<apex:page controller="CasesPieController" title="Pie Chart">
<apex:pageBlock >
<apex:pageBlockSection title="Cases by Status">
<apex:pageBlockSectionItem >
<apex:chart data="[!CasesByStatus]" height="400" width="380">
<apex:pieSeries labelField="id" dataField="cnt">
<apex:chartLabel display="rotate" field="cnt"/>
</apex:pieSeries>
</apex:chart>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

 

Blank Chart

 

Thanks in advance if anyone is able to help :).

Hi All,

 

I have made a custom object called RAG_Status__c as a child of the Master object Acctounts, the relationship is called Account__C.

 

My custom object has the following fields, Active__c (checkbox), Effective_Date__c (formula - Date/Time with created date in as the formula).

 

I wish to flag only the most recent child of an Account as active and flag all other child objects as inactive. I found a post here that seems to do what I need, but I have not been able to get it to work.

 

The post is here: http://boards.developerforce.com/t5/Apex-Code-Development/Trigger-to-Update-Status/td-p/264273/highlight/true

 

Can anyone tell me what I am doing wrong? This saves and is active but doesnt amend the records as expected?

 

My code i have amended is here; 

 

trigger RAGinactiveActive on RAG_Status__C(after insert, after update) {

    if(!Trigger.isExecuting){ //check that the trigger isnt already executing
    

Set<Id> emtoupdate = new Set<Id> ();

if (Trigger.isInsert || Trigger.isUpdate ) {
for (RAG_Status__C c: Trigger.New) {
emtoupdate.add(c.Account__c);
}
}

if (Trigger.isDelete) {
for (RAG_Status__C c: Trigger.Old) {
emtoupdate.add(c.Account__c);
}
}

List<RAG_Status__C> ctxsToUpdate = new List<RAG_Status__C>{};

boolean firstRecord = true;

for(RAG_Status__C ctx : [Select Id, Active__c, Effective_Date__c from RAG_Status__C where Account__c =: emtoupdate ORDER BY Effective_Date__c DESC])
{
if(firstRecord)
{
ctx.Active__c = True;
firstRecord = false;
}
else
ctx.Active__c = False;
 
ctxsToUpdate.add(ctx);
 
}
if(ctxsToUpdate != null && !ctxsToUpdate.IsEmpty())
Database.update(ctxsToUpdate);
 
}
}

 

 

 

 

 

Hi All,

 

I am overwriting the case detail page with a tabbed style visualforce page. I have had various problems with related lists not being supported by apex code. I have so far rebuilt related emails and the caseComments lists but am strugling with "CaseArticles". When I view the page via the customer portal I get the error below.

 

CaseArticles' is not a valid child relationship name for entity Case

 

Code

 

<apex:tab label="Related Articles"  name="Articles" id="tabCaseArticles2">
         <apex:relatedList subject="{!case}"  list="CaseArticles" />
</apex:tab>-->

 

When using the default case detail page customer portal users can see the related articles list. But when I use the code above it falls over. Ive looked up the name of the list in the API WSDL file and it is correct. Users have permissions to the page, article types ect. Without the code the Portal users can veie the same page fine.

 

Any ideas how to get round this?

Hi All,

 

I am trying to build a simple pie chart with visual force / Apex. THe below code saves without errors but does not produce a chart. Can anyone point out what I am doing wrong?

 

Apex class;

 

This should be creating the pie chart data grouping cases by status.

 

public with sharing class CasesPieController {

public CasesPieController ()
{
}

public List<AggregateResult> getCasesByStatus()
{
    AggregateResult[] result = [SELECT COUNT(id) cnt, Status FROM Case GROUP BY Status];
    return result;
}



}

 

Visual Force page;

 

This should be a simple page with one block and one chart. The block displays but the chart doesnt at all.

 

<apex:page controller="CasesPieController" title="Pie Chart">
<apex:pageBlock >
<apex:pageBlockSection title="Cases by Status">
<apex:pageBlockSectionItem >
<apex:chart data="[!CasesByStatus]" height="400" width="380">
<apex:pieSeries labelField="id" dataField="cnt">
<apex:chartLabel display="rotate" field="cnt"/>
</apex:pieSeries>
</apex:chart>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

 

Blank Chart

 

Thanks in advance if anyone is able to help :).

Hello,

 

I have created a workflow rule that will alert a specific department when a change is made to the Account Status field.  The alert works fine, but the only thing is that I don't want the email alert to trigger if the Account Status is changed to a blank field.  We have three options in the picklist, but we also allow for the field to be left empty even after it has been populated.  The workflow alert triggers is the formula evaluates to TRUE.

 

Here is the basic formula I have. 

 

ISCHANGED( Account_Status__c )

 

Thanks in advance.

 

I am setting up custom VF templates to display our SF Knowledge articles. I have included the VF component knowledge:articleCaseToolbar and set up the parameters for caseID and articleID. The component renders correctly with the case information but the "Attach" and "Attach and Return Case" toolbar is not being rendered.

 

I am using the given template from the VF documentation and have tried a variety of IDs associated with the article:

 

<knowledge:articleCaseToolbar rendered="{!$CurrentPage.parameters.caseId != null}" caseId="{!$CurrentPage.parameters.caseId}" articleId="{!$CurrentPage.parameters.id}"/><br/>

 

Page is a standard controller for article type "Solution__kav" and I have a articleRendererToolBar on the page that renders fine with the Solution__kav.KnowledgeArticleid as the "articleID" parameter.

 

I have tried setting "articleID" to:

 

  • $CurrentPage.parameters.id
  • Solution__kav.KnowledgeArticleid
  • Solution__kav.MasterVersionID

I even tried passing in a static article ID to no avail.

 

Does anyone have any information on setting up this tag, if the Attach buttons are even standard functionality as part of this VF tag, or if I am going something wrong with my setup?


Thanks!

Recently I was working on a requirement which required overriding the Case detail page with a visualforce page. Problem crept when the related list comonent didnt worked for Case Comments and History. So I decided to write my own code to display the related lists.

I was finally able to write my own code to display the related list. It implements all the function that standard related list of Case Comments provide. In order to make it reusable, I made it as a component so that in other pages I just need to pass the Case Id and I will get the complete list of Case Comments.

 Heres the code finally :

 1. Component Code

 

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

<!-- Component Body -->
<apex:componentBody >
<apex:form >
<apex:pageBlock title="Case Comments" >
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!NewComment}" value="New"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!Comments}" var="comment">
<apex:column headerValue="Action">
<apex:outputLink value="/{!comment.cComment.Id}/e?parent_id={!caseId}&retURL=/{!caseId}">Edit</apex:outputLink>&nbsp | &nbsp
<apex:commandLink action="{!deleteComment}" value="Del">
<apex:param name="CommentId_d" value="{!comment.cComment.Id}"/>
</apex:commandLink>&nbsp | &nbsp
<apex:commandLink action="{!makePublicPrivate}" value="{!comment.PublicPrivateAction}">
<apex:param name="CommentId_p" value="{!comment.cComment.Id}" />
</apex:commandLink>
</apex:column>
<apex:column headerValue="Public" value="{!comment.cComment.IsPublished}" />
<apex:column headerValue="Comments">
<apex:outputText escape="false" value="{!comment.commentText}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:componentBody>
</apex:component>

 

 2. Apex Code

public with sharing class CaseCommentsComponentController {

public Id caseId {get; set;}
public cComments[] comments{
get{
List<cComments> comments = new List<cComments>();
for(CaseComment comment : [Select LastModifiedDate, LastModifiedBy.Id, LastModifiedBy.Name, IsPublished, CreatedDate, CreatedBy.Id, CreatedBy.Name, CommentBody From CaseComment c where ParentId = :caseId order by c.LastModifiedDate desc])
{
cComments tempcComment = new cComments();
tempcComment.cComment = comment;

// Build String to display.
tempcComment.commentText = '<b>Created By: <a href=\'/' + comment.CreatedBy.Id + '\'>' + comment.CreatedBy.Name + '</a> (' + comment.CreatedDate.format() + ') | ';
tempcComment.commentText += 'Last Modified By: <a href=\'/' + comment.LastModifiedBy.Id + '\'>' + comment.LastModifiedBy.Name + '</a> (' + comment.LastModifiedDate.format() + ')</b><br>';
tempcComment.commentText += comment.CommentBody;

if(comment.IsPublished)
tempcComment.PublicPrivateAction = 'Make Private';
else
tempcComment.PublicPrivateAction = 'Make Public';
//Add to list
comments.add(tempcComment);
}
return comments;
}

set;
}

public PageReference NewComment()
{
PageReference pr = new PageReference('/00a/e?parent_id='+ caseId + '&retURL=%2F' + caseId);
pr.setRedirect(true);
return pr;
}

public PageReference deleteComment()
{
Id commentId = ApexPages.currentPage().getParameters().get('CommentId_d');

for(cComments Comment : comments)
{
if(Comment.cComment.Id == commentId)
{
delete Comment.cComment;
break;
}
}

PageReference pg = new PageReference('/' + caseId);
pg.setRedirect(true);
return pg;
}

public PageReference makePublicPrivate()
{
Id commentId = ApexPages.currentPage().getParameters().get('CommentId_p');
for(cComments Comment : comments)
{
if(Comment.cComment.Id == commentId)
{
Comment.cComment.IsPublished = !Comment.cComment.IsPublished;
if(Comment.cComment.IsPublished)
Comment.PublicPrivateAction = 'Make Private';
else
Comment.PublicPrivateAction = 'Make Public';

update Comment.cComment;
break;
}
}
PageReference pg = new PageReference('/' + caseId);
pg.setRedirect(true);
return pg;
}

public class cComments {

public CaseComment cComment {get; set;}
public String commentText {get; set;}
public String PublicPrivateAction {get; set;}
}
}

 Hope it is helpful to you.

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

Message Edited by Rajesh Shah on 10-16-2009 08:03 PM