• Cypher
  • NEWBIE
  • 25 Points
  • Member since 2012

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

All-

I have a LARGE VF page on Quote with multiple sections.  One of the sections (near the bottom 2/3rds of the page) renders approvals in an object.  Each approval record has a series of buttons (approve, reject, etc.).  When users click on one of these buttons, they are directed to another form to fill out the necessary information and, when complete, they return to the quote thorugh a PageReference in an Apex class.  The issue is, when returning to the quote, it automatically returns to the TOP of the quote page.  Is there a way to make them return to the approvals section of the Quote VF page when they are being directed to the QUOTE page from the Apex Class?  Any help on how to do it?

  • October 15, 2013
  • Like
  • 0

With the advent of the Winter '14 release, I was attempting to update my standalone Force.com IDE.  I could not get it to work from the Force.com wlecome page (was getting an adnsandbox.com error) OR from the Updates page.  SO, I unistalled the IDE completely and then downloaded the newest Force.com IDE for Mac OSX.  I am on version 10.8.5 with JRE 7_40.  

When attempting to install with Pulse, I set up the proxy correctly, but I get these errors:

 

Pulse has been unable to create a plan for Force.com IDE.  Please check the details below to diagnose the issue.  If problems persist, contact Pulse support via the forums at www.poweredbypulse.com.

 

This profile can not be resolved because required software could not be located.
Could not locate installable unit: com.genuitec.pulse2.common.properties.offline 0.0.0
Could not locate installable unit: pulse.com.salesforce.ide.product.ini.e34 0.0.0
Could not locate installable unit: org.eclipse.help.feature.group 1.1.0
Could not locate installable unit: org.eclipse.cvs.feature.group 1.1.0
Could not locate installable unit: com.salesforce.ide.feature.feature.group 0.0.0
Could not locate installable unit: org.eclipse.jdt.feature.group 3.5.0
Could not locate installable unit: org.eclipse.rcp.feature.group 3.5.0
Could not locate installable unit: org.eclipse.platform.feature.group 3.5.0
Could not locate installable unit: com.genuitec.pulse2.client.targetcfg.dropins.feature.group 2.5.0
Could not locate installable unit: pulse.com.salesforce.ide.product.group 0.0.0
Could not locate installable unit: org.eclipse.wst.xml_ui.feature.feature.group 0.0.0
Could not locate installable unit: org.eclipse.equinox.p2.user.ui.feature.group 1.1.0
Could not load update site: http://downloads.poweredbypulse.com/downloads/products/pulse/client25
Could not load update site: http://eclipse.poweredbypulse.com/downloads/aux/eclipse-mirror/eclipse/updates/3.5
Could not load update site: http://eclipse.poweredbypulse.com/downloads/aux/eclipse-mirror/releases/galileo
Could not load update site: http://eclipse.poweredbypulse.com/downloads/partners/force.com
Could not load update site: http://eclipse.poweredbypulse.com/downloads/products/pulse/mirrors
Could not load update site: http://www.adnsandbox.com/tools/ide/latest
Could not load update site: http://www.poweredbypulse.com/pulse/download/live

 

I have NO IDEA what to do or to fix it AND NOW, I don't have an IDE at all.  I don't WANT to install Eclipse and I prefer not to develop in the developer console OR the UI.  Anyone know how to solve this issue?

  • October 10, 2013
  • Like
  • 0

I have a SOQL query that I need to create that has to traverse 4 obejects with various relationships:

Quote is a child of Opportunity

Account is a lookup on Opportunity

Custom Account Team is a child of Account

 

I am starting on Quote - I need to find the sum of a value Y on all quotes where:

QuoteFlg is TRUE AND

Quote ProductLine <> 'Big Products' AND

Parent Opportunity Status = 'Won" AND

Parent Opportunity Type = 'Sale' AND
Parent Opportunity WinDate = THIS_YEAR AND

Parent Opportunity Account IS IN (Select Accounts FROM Custom Account Team at where at.Primary_flg = true and at.userId = UserID on the quote (Actually a userid from an apex page).

 

In SQL, I would do this:

SELECT SUM(Y)

FROM Quote q

INNER JOIN Opportuntiy o on o.Id = q.Opportunity_Id

WHERE q.QuoteFlg='Y'

AND q.ProductLine <> 'Big Products'

AND o.Status = 'Won'

AND o.Type = 'Sale'

AND o.WinDate Between [beginning of year] and [end of year]

AND o.AccountId IN

(SELECT at.AccountId FROM Account_Team at

WHERE at.Primary_Flg = 'Y'

AND at.UserId := variable)

 

Can someone tell me how to do this in SOQL?  I am tired of all of my gesitculations:  I have used relationships, and more, to no avail.

 

 

All-

I have created a visual force page that uses a standard controller extension.  The page esentially looks up the NAME of the record and then performs a search on all chatter posts for that string.  Here is the Page:

<apex:page standardController="Asset_cust__c" extensions="ChatterUpdatesController" >

<style type="text/css">
.boldlink {color:#015ba7;font-weight:bold;text-decoration:none;vertical-align:top;}
.link {color:#015ba7;text-decoration:none;vertical-align:top;}
.addComment {color:#015ba7;text-decoration:none;font-size:0.92em;padding-left:5px;}
.feedimage {width:45px;height:45px;}
.groupimage {width:20px;height:20px;}
.commentimage {width:30px;height:30px;}
.dateTime {color:#7D7D84;font-size:0.92em;padding-right:5px;padding-bottom:4px;}
.feedbackground {vertical-align: top;padding-top:8px;padding-bottom:8px;padding-right:8px;border-bottom:#dee4e9 1px solid;}
.commentbackground {vertical-align: top;padding:4px;background-color: #eff7fa;border-top:#dee4e9 1px solid;}
.line {line-height:15px;white-space:normal;}
.bodytext {vertical-align:top;margin-left:2px;}
</style>

<apex:outputText rendered="{!feeds.size == 0}">No records found.</apex:outputText>

<apex:outputpanel layout="block" style="overflow:auto;width:750px;height:500px">
<apex:dataTable value="{!feeds}" var="f" id="theTable" border="0" rendered="{!feeds.size > 0}">

<apex:column styleClass="feedbackground" > <apex:image id="profileImage" url="{!f.image}" styleClass="feedimage" /> </apex:column>

<apex:column styleClass="feedbackground" >
<apex:image id="groupImage" url="{!f.groupImage}" styleClass="groupimage" rendered="{!f.groupName!=null}" />
<apex:outputLink styleClass="boldlink" value="/{!f.groupId}" target="_parent" rendered="{!f.groupName!=null}"> {!f.groupName} </apex:outputLink>
<apex:outputText styleClass="line" rendered="{!f.groupName!=null}"> </apex:outputText>
<apex:outputLink styleClass="link" value="/{!f.createdById}" target="_parent" rendered="{!f.groupName!=null}"> {!f.createdByName} </apex:outputLink>
<apex:outputLink styleClass="boldlink" value="/{!f.createdById}" target="_parent" rendered="{!f.groupName==null}"> {!f.createdByName} </apex:outputLink>
<apex:outputText styleClass="bodytext" value="{!f.body}" />

<apex:panelGrid columns="3" cellpadding="0" cellspacing="0" style="padding-top:4px;padding-bottom:4px;">
<apex:outputLink styleClass="link" value="/{!f.feedId}" target="_parent">
<!-- apex:outputText styleClass="dateTime" value="{0,date,MMMM dd, yyyy 'at' hh:mm a}" > <apex:param value="{!f.feedDate}" />
/apex:outputText -->
<apex:outputText styleClass="dateTime" value="{!f.formattedFeedDate}" />
</apex:outputLink>
<!-- apex:outputText > </apex:outputText>
<apex:outputLink styleClass="addComment" value="/"> Comment </apex:outputLink-->
</apex:panelGrid>

<apex:dataTable value="{!f.comments}" var="c" border="0" >

<apex:column styleClass="commentbackground" > <apex:image id="profileImage" url="{!c.image}" styleClass="commentimage" /></apex:column>

<apex:column styleClass="commentbackground">
<apex:outputLink styleClass="boldlink" value="!c.createdById}" target="_parent"> {!c.createdByName} </apex:outputLink>
<apex:outputText styleClass="bodytext" value="{!c.body}" />

<apex:panelGrid columns="1" cellpadding="0" cellspacing="0" style="padding-top:4px;padding-bottom:4px;" >
<!-- apex:outputText styleClass="dateTime" value="{0,date,MMMM dd, yyyy 'at' hh:mm a}" ><apex:param value="{!c.feedDate}" /> </apex:outputText -->
<apex:outputText styleClass="dateTime" value="{!c.formattedFeedDate}" />
</apex:panelGrid>
</apex:column>

</apex:dataTable>

</apex:column>

</apex:dataTable>
</apex:outputpanel>
</apex:page>

 Here is the controller:

/*
* ClassName: ChatterUpdatesController
* CreatedBy: Richard D. Grubb II
* LastModifiedBy: Richard D. Grubb II
* LastModifiedOn: 24 Apr 2012
* CalledFrom: Asset_VF_Page.page VisualForce Page
* Description: This class looks up the current Asset Object and performs a
* Search through Chatter to return all instances of the Asset Name in a VF page.
* ---------------------------------------
* Revision History
* 24 Apr 2012 – Initial Creation (Richard D. Grubb II)
*/

public with sharing class ChatterUpdatesController {

private final Asset_cust__c c;
public List<Feed> feeds;
public Map<Id,User> uls;
String AssetId = '';

// Constructor with one parameter
public ChatterUpdatesController(ApexPages.StandardController stdController) {
Id cid = stdController.getId();

//lookup asset name
c = [select Name from Asset_cust__c where Id =: cid];

feeds = new List<Feed>();
uls = new Map<Id,User>();

}

public List<Feed> getFeeds() {
feeds = new List<Feed>();
//search by asset name
//serch by row id and any child objects
String curId = c.Name;
String srchString = '(\" *' +curId+'\") or (\"'+curId+'* \")';
System.debug(srchString);


Set<Id> userIdSet = new Set<Id>();
Set<Id> groupIdSet = new Set<Id>();

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

Map<Id,List<Feed>> feedCommentsMap = new Map<Id,List<Feed>>();
String keyPrefix = CollaborationGroup.sObjectType.getDescribe().getKeyPrefix();

Integer i=0;
System.debug('id ' + curId);

//sosl search on feeditem and feedcomment to get all feeds and comments that match the search string
for (List<SObject> ls : [FIND :srchString IN ALL FIELDS RETURNING FeedItem(Type, Title, ParentId, LinkUrl,
Id, CreatedDate, CreatedById, CreatedBy.Name, Body
order by CreatedDate desc limit 50),
FeedComment (Id, FeedItemId, ParentId, CreatedById, CreatedBy.Name, CreatedDate, CommentBody
order by FeedItemId,CreatedDate asc limit 50) ]) {

System.debug('results ' + ls);

Integer sortId = 0;
for (SObject lsitem : ls) {
if (i==0) {
FeedItem item = (FeedItem) lsitem;
feedId.add(item.Id);
}
if (i==1) {
FeedComment item = (FeedComment) lsitem;
feedId.add(item.FeedItemId);
}
}
i++;
}

//query to fetch feeditems for comments that matched the search string
for (FeedItem item : [select Id,ParentId,CreatedById,CreatedBy.Name,Body,CreatedDate,
(select Id,CreatedById,CreatedBy.Name,CommentBody,CreatedDate,FeedItemId from FeedComments
order by CreatedDate asc)
from FeedItem where Id in: feedId order by LastModifiedDate desc]) {

Feed f = new Feed(item.CreatedById, item.CreatedBy.Name, item.Body, item.CreatedDate);
f.setFeedId(item.Id);
f.parentId = item.ParentId;
feeds.add(f);

userIdSet.add(item.CreatedById);
if (('' + item.Parentid).substring(0,3) == keyPrefix) {
groupIdSet.add(item.ParentId);
f.groupId = item.ParentId;
}


if (item.FeedComments != null) {
for (FeedComment fc : item.FeedComments) {
Feed fi = new Feed(fc.CreatedById, fc.CreatedBy.Name, fc.CommentBody, fc.CreatedDate);
fi.setFeedId(fc.FeedItemId);
if (feedCommentsMap.containsKey(fc.FeedItemId)) {
List<Feed> cfeeds = feedCommentsMap.get(fc.FeedItemId);
cfeeds.add(fi);
} else {
List<Feed> cfeeds = new List<Feed>();
cfeeds.add(fi);
feedCommentsMap.put(fc.FeedItemId, cfeeds);
}

userIdSet.add(fc.CreatedById);
}
}
}

uls = new Map<Id, User>([select Id,SmallPhotoUrl from User where Id in: userIdSet]);
Map<Id,CollaborationGroup> cgMap = new Map<Id,CollaborationGroup>([select Id, name, SmallPhotoUrl from CollaborationGroup
where Id in: groupIdSet]);

//set the image and group name
for (Feed f : feeds) {
if (f != null) {
Id createdById = f.createdById;
User u = uls.get(createdById);
if (u != null) {
f.image = u.SmallPhotoUrl;
}
Id parentId = f.ParentId;
CollaborationGroup g = cgMap.get(parentId);
if (g != null) {
f.groupImage = g.SmallPhotoUrl;
f.groupName = g.Name;
}
List<Feed> cfeeds = feedCommentsMap.get(f.FeedId);
if (cfeeds != null) {
for (Feed cf : cfeeds) {
Id cfCreatedById = cf.createdById;
User cu = uls.get(cfCreatedById);
if (cu != null) {
cf.image = cu.SmallPhotoUrl;
}
}
}
f.setComments(cfeeds);
}
}

return feeds;
}

public class Feed {
public Id feedId {get;set;}
public String createdByName {get;set;}
public String body {get;set;}
public DateTime feedDate {get;set;}
public String formattedFeedDate {get;set;}
public String image {get;set;}
public Id createdById {get;set;}
public String groupName {get;set;}
public String groupImage {get;set;}
public Id groupId {get;set;}
public String parentId;

public List<Feed> comments {get;set;}

public Feed(Id createdById, String createdByName, String body, DateTime feedDate) {
this.createdById = createdById;
this.createdByName = createdByName;
this.body = body;
this.feedDate = feedDate;
this.formattedFeedDate = feedDate.format('MMMMM dd, yyyy \'at\' hh:mm a');

comments = new List<Feed>();
}

public String getImage() {
return image;
}

public String getGroupName() {
return groupName;
}

public void setComments(List<Feed> comments) {
this.comments = comments;
}

public void setFeedId(Id fid) {
this.feedId = fid;
}
}
}

 I have noticed that when I enter a new chatter post with the information, it takes about 30 seconds before it will show up in the results of the Visual Force Page (this may or may not be relevant).

I began writing a test class, but it only covers 28% of the code.  I think the issue is, when the SOSL query runs, it is returning 0 rows...even though they are explicitly coded in the test class.  I thought maybe it was this 30 second delay so I wrote REAL chatter posts with the information I needed.  The test class cannot find those either.  Here is the test class:

@istest (SeeAllData=true)
public class Chatter_VF {
public static testMethod void Asset_VF_Test()
{
PageReference pg = Page.Asset_VF_Page;
Test.setCurrentPage(pg);

//Create Dummy Data for Test Purposes
Asset_cust__c Aircraft = new Asset_cust__c(Name = 'RDG123');
insert Aircraft;

CollaborationGroup grp = new CollaborationGroup();
grp.Name = 'Air India Teting Group XXXXYYYY';
grp.CollaborationType = 'Public';
insert grp;
FeedItem chat = new FeedItem();
FeedItem chat2 = new FeedItem();
FeedComment comm = new FeedComment();
FeedComment comm2 = new FeedComment();
chat.Body = 'This is a test for Engine ESN111 and Aircraft RDG123';
chat.ParentId = grp.Id;
insert chat;
comm.CommentBody = 'Aircraft RDG123';
comm.FeedItemId = chat.Id;
insert comm;
comm2.CommentBody = 'super test for Aircraft RDG123';
comm2.FeedItemId = chat.Id;
insert comm2;
chat2.Body = 'This is the second Feed Item for Aircraft RDG123';
chat2.ParentId = grp.Id;
insert chat2;

ApexPages.StandardController controller = new ApexPages.StandardController(Aircraft);
ChatterUpdatesController cont = new ChatterUpdatesController(controller);
cont.getFeeds();

}
}

Does anyone know what I am doing wrong?  Or, is it impossible to query Chatter results in test classes because they aren't "real"?  Please, any help is most appreciated. 

I am new to Apex, so my coding is terrible - I am looking for some help.  According to the Chatter code recipes, I can add a feeditem like this:

//Adding a Text post
02FeedItem post = new FeedItem();
03post.ParentId = oId; //eg. Opportunity id, custom object id..
04post.Body = 'Enter post text here';
05

insert post;

but, it does NOT appear to work on a custom object's feed  For example

 

List<Aircraft_Engine__c> Engine = New List<Aircraft_Engine__c>();
Engine = [SELECT Id from Aircraft_Engine__c where Name =: sHashtag limit 1];

Aircraft_Engine__Feed EngineFeed = new Aircraft_Engine__Feed();

EngineFeed.ParentId = 'TEST'; //HERE IS THE ERROR
EngineFeed.Body = sText;
insert EngineFeed;

 

 

the code won;t compile at the line above and has the error: "Save Error: Field is not writeable: Aircraft_Engine__Feed.ParentId

 

Any ideas?

  • March 02, 2012
  • Like
  • 0

I am writing an apex trigger on User to check when a user updates their status with a particular hashtag.  Using the string in the hashtag, I want to look up a record on a custom object and then MOVE the UserUpdate to the Object's Chatter Feed.   First question: has anyone done this and second, does anyone have a quick code snippet to assist me?

 

Thanks for all your help.

  • March 02, 2012
  • Like
  • 0

All-

I am trying to write some Apex code that triggers when a User is set to Inactive.  When the user is set to inactive, I want to assign all cases currently owned by the user to the user's manager.

 

Here is the code I am using:

trigger trgCaseReassignment on User (after update) {

for(User usr:Trigger.new)
{
if (usr.IsActive == false){
String Manager = usr.ManagerId;
String uId = usr.Id;
List<Case> caserec = New List<Case>();
caserec = [SELECT c.Id, c.OwnerId from Case c where c.OwnerId =: uId FOR UPDATE];

if (caserec != null && caserec.size()>0){
for (Case c:caserec){
System.Debug('In Code');
System.Debug('*' + c.OwnerId + '*');
c.OwnerId = Manager;
System.Debug('*' + c.OwnerId + '*');

}//for (Case...)

}// if(caserec...)

}//if (usr.IsActive..)
}//for (User...)

}//class

 

I can tell from the logs that the correct User Id and Manager Id and Cases are found, but the case record is NOT updated.  Am I unaware of some restriction that is occuring?

 

Also, is there a way to make the Apex code RUN AS a System Admin, and not with the restrictions of the user?

  • February 21, 2012
  • Like
  • 0

All-

I have a LARGE VF page on Quote with multiple sections.  One of the sections (near the bottom 2/3rds of the page) renders approvals in an object.  Each approval record has a series of buttons (approve, reject, etc.).  When users click on one of these buttons, they are directed to another form to fill out the necessary information and, when complete, they return to the quote thorugh a PageReference in an Apex class.  The issue is, when returning to the quote, it automatically returns to the TOP of the quote page.  Is there a way to make them return to the approvals section of the Quote VF page when they are being directed to the QUOTE page from the Apex Class?  Any help on how to do it?

  • October 15, 2013
  • Like
  • 0

With the advent of the Winter '14 release, I was attempting to update my standalone Force.com IDE.  I could not get it to work from the Force.com wlecome page (was getting an adnsandbox.com error) OR from the Updates page.  SO, I unistalled the IDE completely and then downloaded the newest Force.com IDE for Mac OSX.  I am on version 10.8.5 with JRE 7_40.  

When attempting to install with Pulse, I set up the proxy correctly, but I get these errors:

 

Pulse has been unable to create a plan for Force.com IDE.  Please check the details below to diagnose the issue.  If problems persist, contact Pulse support via the forums at www.poweredbypulse.com.

 

This profile can not be resolved because required software could not be located.
Could not locate installable unit: com.genuitec.pulse2.common.properties.offline 0.0.0
Could not locate installable unit: pulse.com.salesforce.ide.product.ini.e34 0.0.0
Could not locate installable unit: org.eclipse.help.feature.group 1.1.0
Could not locate installable unit: org.eclipse.cvs.feature.group 1.1.0
Could not locate installable unit: com.salesforce.ide.feature.feature.group 0.0.0
Could not locate installable unit: org.eclipse.jdt.feature.group 3.5.0
Could not locate installable unit: org.eclipse.rcp.feature.group 3.5.0
Could not locate installable unit: org.eclipse.platform.feature.group 3.5.0
Could not locate installable unit: com.genuitec.pulse2.client.targetcfg.dropins.feature.group 2.5.0
Could not locate installable unit: pulse.com.salesforce.ide.product.group 0.0.0
Could not locate installable unit: org.eclipse.wst.xml_ui.feature.feature.group 0.0.0
Could not locate installable unit: org.eclipse.equinox.p2.user.ui.feature.group 1.1.0
Could not load update site: http://downloads.poweredbypulse.com/downloads/products/pulse/client25
Could not load update site: http://eclipse.poweredbypulse.com/downloads/aux/eclipse-mirror/eclipse/updates/3.5
Could not load update site: http://eclipse.poweredbypulse.com/downloads/aux/eclipse-mirror/releases/galileo
Could not load update site: http://eclipse.poweredbypulse.com/downloads/partners/force.com
Could not load update site: http://eclipse.poweredbypulse.com/downloads/products/pulse/mirrors
Could not load update site: http://www.adnsandbox.com/tools/ide/latest
Could not load update site: http://www.poweredbypulse.com/pulse/download/live

 

I have NO IDEA what to do or to fix it AND NOW, I don't have an IDE at all.  I don't WANT to install Eclipse and I prefer not to develop in the developer console OR the UI.  Anyone know how to solve this issue?

  • October 10, 2013
  • Like
  • 0

I have a SOQL query that I need to create that has to traverse 4 obejects with various relationships:

Quote is a child of Opportunity

Account is a lookup on Opportunity

Custom Account Team is a child of Account

 

I am starting on Quote - I need to find the sum of a value Y on all quotes where:

QuoteFlg is TRUE AND

Quote ProductLine <> 'Big Products' AND

Parent Opportunity Status = 'Won" AND

Parent Opportunity Type = 'Sale' AND
Parent Opportunity WinDate = THIS_YEAR AND

Parent Opportunity Account IS IN (Select Accounts FROM Custom Account Team at where at.Primary_flg = true and at.userId = UserID on the quote (Actually a userid from an apex page).

 

In SQL, I would do this:

SELECT SUM(Y)

FROM Quote q

INNER JOIN Opportuntiy o on o.Id = q.Opportunity_Id

WHERE q.QuoteFlg='Y'

AND q.ProductLine <> 'Big Products'

AND o.Status = 'Won'

AND o.Type = 'Sale'

AND o.WinDate Between [beginning of year] and [end of year]

AND o.AccountId IN

(SELECT at.AccountId FROM Account_Team at

WHERE at.Primary_Flg = 'Y'

AND at.UserId := variable)

 

Can someone tell me how to do this in SOQL?  I am tired of all of my gesitculations:  I have used relationships, and more, to no avail.

 

 

All-

I have created a visual force page that uses a standard controller extension.  The page esentially looks up the NAME of the record and then performs a search on all chatter posts for that string.  Here is the Page:

<apex:page standardController="Asset_cust__c" extensions="ChatterUpdatesController" >

<style type="text/css">
.boldlink {color:#015ba7;font-weight:bold;text-decoration:none;vertical-align:top;}
.link {color:#015ba7;text-decoration:none;vertical-align:top;}
.addComment {color:#015ba7;text-decoration:none;font-size:0.92em;padding-left:5px;}
.feedimage {width:45px;height:45px;}
.groupimage {width:20px;height:20px;}
.commentimage {width:30px;height:30px;}
.dateTime {color:#7D7D84;font-size:0.92em;padding-right:5px;padding-bottom:4px;}
.feedbackground {vertical-align: top;padding-top:8px;padding-bottom:8px;padding-right:8px;border-bottom:#dee4e9 1px solid;}
.commentbackground {vertical-align: top;padding:4px;background-color: #eff7fa;border-top:#dee4e9 1px solid;}
.line {line-height:15px;white-space:normal;}
.bodytext {vertical-align:top;margin-left:2px;}
</style>

<apex:outputText rendered="{!feeds.size == 0}">No records found.</apex:outputText>

<apex:outputpanel layout="block" style="overflow:auto;width:750px;height:500px">
<apex:dataTable value="{!feeds}" var="f" id="theTable" border="0" rendered="{!feeds.size > 0}">

<apex:column styleClass="feedbackground" > <apex:image id="profileImage" url="{!f.image}" styleClass="feedimage" /> </apex:column>

<apex:column styleClass="feedbackground" >
<apex:image id="groupImage" url="{!f.groupImage}" styleClass="groupimage" rendered="{!f.groupName!=null}" />
<apex:outputLink styleClass="boldlink" value="/{!f.groupId}" target="_parent" rendered="{!f.groupName!=null}"> {!f.groupName} </apex:outputLink>
<apex:outputText styleClass="line" rendered="{!f.groupName!=null}"> </apex:outputText>
<apex:outputLink styleClass="link" value="/{!f.createdById}" target="_parent" rendered="{!f.groupName!=null}"> {!f.createdByName} </apex:outputLink>
<apex:outputLink styleClass="boldlink" value="/{!f.createdById}" target="_parent" rendered="{!f.groupName==null}"> {!f.createdByName} </apex:outputLink>
<apex:outputText styleClass="bodytext" value="{!f.body}" />

<apex:panelGrid columns="3" cellpadding="0" cellspacing="0" style="padding-top:4px;padding-bottom:4px;">
<apex:outputLink styleClass="link" value="/{!f.feedId}" target="_parent">
<!-- apex:outputText styleClass="dateTime" value="{0,date,MMMM dd, yyyy 'at' hh:mm a}" > <apex:param value="{!f.feedDate}" />
/apex:outputText -->
<apex:outputText styleClass="dateTime" value="{!f.formattedFeedDate}" />
</apex:outputLink>
<!-- apex:outputText > </apex:outputText>
<apex:outputLink styleClass="addComment" value="/"> Comment </apex:outputLink-->
</apex:panelGrid>

<apex:dataTable value="{!f.comments}" var="c" border="0" >

<apex:column styleClass="commentbackground" > <apex:image id="profileImage" url="{!c.image}" styleClass="commentimage" /></apex:column>

<apex:column styleClass="commentbackground">
<apex:outputLink styleClass="boldlink" value="!c.createdById}" target="_parent"> {!c.createdByName} </apex:outputLink>
<apex:outputText styleClass="bodytext" value="{!c.body}" />

<apex:panelGrid columns="1" cellpadding="0" cellspacing="0" style="padding-top:4px;padding-bottom:4px;" >
<!-- apex:outputText styleClass="dateTime" value="{0,date,MMMM dd, yyyy 'at' hh:mm a}" ><apex:param value="{!c.feedDate}" /> </apex:outputText -->
<apex:outputText styleClass="dateTime" value="{!c.formattedFeedDate}" />
</apex:panelGrid>
</apex:column>

</apex:dataTable>

</apex:column>

</apex:dataTable>
</apex:outputpanel>
</apex:page>

 Here is the controller:

/*
* ClassName: ChatterUpdatesController
* CreatedBy: Richard D. Grubb II
* LastModifiedBy: Richard D. Grubb II
* LastModifiedOn: 24 Apr 2012
* CalledFrom: Asset_VF_Page.page VisualForce Page
* Description: This class looks up the current Asset Object and performs a
* Search through Chatter to return all instances of the Asset Name in a VF page.
* ---------------------------------------
* Revision History
* 24 Apr 2012 – Initial Creation (Richard D. Grubb II)
*/

public with sharing class ChatterUpdatesController {

private final Asset_cust__c c;
public List<Feed> feeds;
public Map<Id,User> uls;
String AssetId = '';

// Constructor with one parameter
public ChatterUpdatesController(ApexPages.StandardController stdController) {
Id cid = stdController.getId();

//lookup asset name
c = [select Name from Asset_cust__c where Id =: cid];

feeds = new List<Feed>();
uls = new Map<Id,User>();

}

public List<Feed> getFeeds() {
feeds = new List<Feed>();
//search by asset name
//serch by row id and any child objects
String curId = c.Name;
String srchString = '(\" *' +curId+'\") or (\"'+curId+'* \")';
System.debug(srchString);


Set<Id> userIdSet = new Set<Id>();
Set<Id> groupIdSet = new Set<Id>();

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

Map<Id,List<Feed>> feedCommentsMap = new Map<Id,List<Feed>>();
String keyPrefix = CollaborationGroup.sObjectType.getDescribe().getKeyPrefix();

Integer i=0;
System.debug('id ' + curId);

//sosl search on feeditem and feedcomment to get all feeds and comments that match the search string
for (List<SObject> ls : [FIND :srchString IN ALL FIELDS RETURNING FeedItem(Type, Title, ParentId, LinkUrl,
Id, CreatedDate, CreatedById, CreatedBy.Name, Body
order by CreatedDate desc limit 50),
FeedComment (Id, FeedItemId, ParentId, CreatedById, CreatedBy.Name, CreatedDate, CommentBody
order by FeedItemId,CreatedDate asc limit 50) ]) {

System.debug('results ' + ls);

Integer sortId = 0;
for (SObject lsitem : ls) {
if (i==0) {
FeedItem item = (FeedItem) lsitem;
feedId.add(item.Id);
}
if (i==1) {
FeedComment item = (FeedComment) lsitem;
feedId.add(item.FeedItemId);
}
}
i++;
}

//query to fetch feeditems for comments that matched the search string
for (FeedItem item : [select Id,ParentId,CreatedById,CreatedBy.Name,Body,CreatedDate,
(select Id,CreatedById,CreatedBy.Name,CommentBody,CreatedDate,FeedItemId from FeedComments
order by CreatedDate asc)
from FeedItem where Id in: feedId order by LastModifiedDate desc]) {

Feed f = new Feed(item.CreatedById, item.CreatedBy.Name, item.Body, item.CreatedDate);
f.setFeedId(item.Id);
f.parentId = item.ParentId;
feeds.add(f);

userIdSet.add(item.CreatedById);
if (('' + item.Parentid).substring(0,3) == keyPrefix) {
groupIdSet.add(item.ParentId);
f.groupId = item.ParentId;
}


if (item.FeedComments != null) {
for (FeedComment fc : item.FeedComments) {
Feed fi = new Feed(fc.CreatedById, fc.CreatedBy.Name, fc.CommentBody, fc.CreatedDate);
fi.setFeedId(fc.FeedItemId);
if (feedCommentsMap.containsKey(fc.FeedItemId)) {
List<Feed> cfeeds = feedCommentsMap.get(fc.FeedItemId);
cfeeds.add(fi);
} else {
List<Feed> cfeeds = new List<Feed>();
cfeeds.add(fi);
feedCommentsMap.put(fc.FeedItemId, cfeeds);
}

userIdSet.add(fc.CreatedById);
}
}
}

uls = new Map<Id, User>([select Id,SmallPhotoUrl from User where Id in: userIdSet]);
Map<Id,CollaborationGroup> cgMap = new Map<Id,CollaborationGroup>([select Id, name, SmallPhotoUrl from CollaborationGroup
where Id in: groupIdSet]);

//set the image and group name
for (Feed f : feeds) {
if (f != null) {
Id createdById = f.createdById;
User u = uls.get(createdById);
if (u != null) {
f.image = u.SmallPhotoUrl;
}
Id parentId = f.ParentId;
CollaborationGroup g = cgMap.get(parentId);
if (g != null) {
f.groupImage = g.SmallPhotoUrl;
f.groupName = g.Name;
}
List<Feed> cfeeds = feedCommentsMap.get(f.FeedId);
if (cfeeds != null) {
for (Feed cf : cfeeds) {
Id cfCreatedById = cf.createdById;
User cu = uls.get(cfCreatedById);
if (cu != null) {
cf.image = cu.SmallPhotoUrl;
}
}
}
f.setComments(cfeeds);
}
}

return feeds;
}

public class Feed {
public Id feedId {get;set;}
public String createdByName {get;set;}
public String body {get;set;}
public DateTime feedDate {get;set;}
public String formattedFeedDate {get;set;}
public String image {get;set;}
public Id createdById {get;set;}
public String groupName {get;set;}
public String groupImage {get;set;}
public Id groupId {get;set;}
public String parentId;

public List<Feed> comments {get;set;}

public Feed(Id createdById, String createdByName, String body, DateTime feedDate) {
this.createdById = createdById;
this.createdByName = createdByName;
this.body = body;
this.feedDate = feedDate;
this.formattedFeedDate = feedDate.format('MMMMM dd, yyyy \'at\' hh:mm a');

comments = new List<Feed>();
}

public String getImage() {
return image;
}

public String getGroupName() {
return groupName;
}

public void setComments(List<Feed> comments) {
this.comments = comments;
}

public void setFeedId(Id fid) {
this.feedId = fid;
}
}
}

 I have noticed that when I enter a new chatter post with the information, it takes about 30 seconds before it will show up in the results of the Visual Force Page (this may or may not be relevant).

I began writing a test class, but it only covers 28% of the code.  I think the issue is, when the SOSL query runs, it is returning 0 rows...even though they are explicitly coded in the test class.  I thought maybe it was this 30 second delay so I wrote REAL chatter posts with the information I needed.  The test class cannot find those either.  Here is the test class:

@istest (SeeAllData=true)
public class Chatter_VF {
public static testMethod void Asset_VF_Test()
{
PageReference pg = Page.Asset_VF_Page;
Test.setCurrentPage(pg);

//Create Dummy Data for Test Purposes
Asset_cust__c Aircraft = new Asset_cust__c(Name = 'RDG123');
insert Aircraft;

CollaborationGroup grp = new CollaborationGroup();
grp.Name = 'Air India Teting Group XXXXYYYY';
grp.CollaborationType = 'Public';
insert grp;
FeedItem chat = new FeedItem();
FeedItem chat2 = new FeedItem();
FeedComment comm = new FeedComment();
FeedComment comm2 = new FeedComment();
chat.Body = 'This is a test for Engine ESN111 and Aircraft RDG123';
chat.ParentId = grp.Id;
insert chat;
comm.CommentBody = 'Aircraft RDG123';
comm.FeedItemId = chat.Id;
insert comm;
comm2.CommentBody = 'super test for Aircraft RDG123';
comm2.FeedItemId = chat.Id;
insert comm2;
chat2.Body = 'This is the second Feed Item for Aircraft RDG123';
chat2.ParentId = grp.Id;
insert chat2;

ApexPages.StandardController controller = new ApexPages.StandardController(Aircraft);
ChatterUpdatesController cont = new ChatterUpdatesController(controller);
cont.getFeeds();

}
}

Does anyone know what I am doing wrong?  Or, is it impossible to query Chatter results in test classes because they aren't "real"?  Please, any help is most appreciated. 

I am new to Apex, so my coding is terrible - I am looking for some help.  According to the Chatter code recipes, I can add a feeditem like this:

//Adding a Text post
02FeedItem post = new FeedItem();
03post.ParentId = oId; //eg. Opportunity id, custom object id..
04post.Body = 'Enter post text here';
05

insert post;

but, it does NOT appear to work on a custom object's feed  For example

 

List<Aircraft_Engine__c> Engine = New List<Aircraft_Engine__c>();
Engine = [SELECT Id from Aircraft_Engine__c where Name =: sHashtag limit 1];

Aircraft_Engine__Feed EngineFeed = new Aircraft_Engine__Feed();

EngineFeed.ParentId = 'TEST'; //HERE IS THE ERROR
EngineFeed.Body = sText;
insert EngineFeed;

 

 

the code won;t compile at the line above and has the error: "Save Error: Field is not writeable: Aircraft_Engine__Feed.ParentId

 

Any ideas?

  • March 02, 2012
  • Like
  • 0

All-

I am trying to write some Apex code that triggers when a User is set to Inactive.  When the user is set to inactive, I want to assign all cases currently owned by the user to the user's manager.

 

Here is the code I am using:

trigger trgCaseReassignment on User (after update) {

for(User usr:Trigger.new)
{
if (usr.IsActive == false){
String Manager = usr.ManagerId;
String uId = usr.Id;
List<Case> caserec = New List<Case>();
caserec = [SELECT c.Id, c.OwnerId from Case c where c.OwnerId =: uId FOR UPDATE];

if (caserec != null && caserec.size()>0){
for (Case c:caserec){
System.Debug('In Code');
System.Debug('*' + c.OwnerId + '*');
c.OwnerId = Manager;
System.Debug('*' + c.OwnerId + '*');

}//for (Case...)

}// if(caserec...)

}//if (usr.IsActive..)
}//for (User...)

}//class

 

I can tell from the logs that the correct User Id and Manager Id and Cases are found, but the case record is NOT updated.  Am I unaware of some restriction that is occuring?

 

Also, is there a way to make the Apex code RUN AS a System Admin, and not with the restrictions of the user?

  • February 21, 2012
  • Like
  • 0