• VT-
  • NEWBIE
  • 10 Points
  • Member since 2018

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

Hi,

When cloning a FeedItem :

FeedItem item = f.Clone(false,true);
insert item;

The Body property lose all @Mentions and /RecordLinks. It is converted as plain text.

I found this KB explaining how to post @Mentions in a FeedItem. I could look for @Mention and /RecordLinks in the body and "convert" them. But it would not work in situation where multiple records have the same name.

There was an old topic on this with no answers and a lot of things changed since. Has anyone found a solution ?

Regards,

VT.

  • September 10, 2018
  • Like
  • 0
Hi,

I'm trying to write an Apex code which will create a chatter post on an account when someone post on an opportunity related to this account.
I'm not very experienced in Apex, this is where I am so far :
 
trigger Post_to_parent on FeedItem (after insert) {
  
    for (feeditem f : trigger.new){
        String ParentID = f.ParentId;

        if (ParentID.startsWith('006')){
            List<Opportunity> lstOppts = [select AccountID from Opportunity where id=:f.parentid];
            FeedItem item = new FeedItem(
            parentId = lstOppts[0].id,
            body = '<p>test clone</p>',
            isRichText = true);
            
            insert item;      
        }
    }
}
It fails because it loops recursively. I don't understand why since it create a post only when the chatter post is related to an opportunity and the code itself create a chatter post related to an account.

Could anyone give me a clue on what is going wrong ?

Thanks.

VT.

 
  • September 09, 2018
  • Like
  • 0

Hi,

When cloning a FeedItem :

FeedItem item = f.Clone(false,true);
insert item;

The Body property lose all @Mentions and /RecordLinks. It is converted as plain text.

I found this KB explaining how to post @Mentions in a FeedItem. I could look for @Mention and /RecordLinks in the body and "convert" them. But it would not work in situation where multiple records have the same name.

There was an old topic on this with no answers and a lot of things changed since. Has anyone found a solution ?

Regards,

VT.

  • September 10, 2018
  • Like
  • 0
Hi,

I'm trying to write an Apex code which will create a chatter post on an account when someone post on an opportunity related to this account.
I'm not very experienced in Apex, this is where I am so far :
 
trigger Post_to_parent on FeedItem (after insert) {
  
    for (feeditem f : trigger.new){
        String ParentID = f.ParentId;

        if (ParentID.startsWith('006')){
            List<Opportunity> lstOppts = [select AccountID from Opportunity where id=:f.parentid];
            FeedItem item = new FeedItem(
            parentId = lstOppts[0].id,
            body = '<p>test clone</p>',
            isRichText = true);
            
            insert item;      
        }
    }
}
It fails because it loops recursively. I don't understand why since it create a post only when the chatter post is related to an opportunity and the code itself create a chatter post related to an account.

Could anyone give me a clue on what is going wrong ?

Thanks.

VT.

 
  • September 09, 2018
  • Like
  • 0
HI All,
i need some help
i am stuck at there part where i am not able to save the data from the page to the database, and the strange part is, that with my below code i am able to clear the challange
below is my code 

CampingList.cmp
<aura:component controller="CampingListController">
    
    <aura:attribute name="items" type="Camping_Item__c[]"/>
    <aura:attribute name="newItem" type="Camping_Item__c" default="{'Name':'',
                                                                   'Quantity__c':0,
                                                                   'Price__c':0,
                                                                   'Packed__c':false,
                                                                   'sobjectType':'Camping_Item__c'}"/>
  <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    
    <c:campingHeader />
    
    <!-- NEW Item entry FORM -->
    <lightning:layout >
        <lightning:layoutItem padding="around-small" size="6">
            <!-- CREATE NEW Item -->
            <div aria-labelledby="newCampaingform">
                <!-- BOXED AREA -->
                <fieldset class="slds-box slds-theme--default slds-container--small">
                    <legend id="newCampaingform" class="slds-text-heading--small 
                      slds-p-vertical--medium">
                      Add Expense
                    </legend>
                    
                    <!-- CREATE NEW EXPENSE FORM -->
                    <form class="slds-form--stacked">
                         <!-- For Name Field -->
        <lightning:input aura:id="expenseform" label="Camping Name"
                         name="expensename"
                         value="{!v.newItem.Name}"
                         required="true"/>
        <!-- For Quantity Field -->
        <lightning:input type="number" aura:id="campingform" label="Quantity"
                         name="expenseamount"
                         min="1"
                         value="{!v.newItem.Quantity__c}"
                         messageWhenRangeUnderflow="Enter minimum 1 Quantity"/>
         <!-- For Price Field -->
        <lightning:input aura:id="campingform" label="Price"
                         formatter="currency"
                         name="expenseclient"
                         value="{!v.newItem.Price__c}"
                          />
         <!-- For Check Box -->
        <lightning:input type="checkbox" aura:id="campingform" label="Packed"  
                         name="expreimbursed"
                         checked="{!v.newItem.Packed__c}"/>
        
        <lightning:button label="Create Camping" 
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.createItem}"/>
                    </form>
                </fieldset>
            </div>
        </lightning:layoutItem>
    </lightning:layout>
    <!-- ITERATIING ITEM LISTS -->
    <div class="slds-card slds-p-top--medium">
        
        <c:campingHeader />
        
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="item">
                    <c:campingListItem item="{!item}"/>
                </aura:iteration>
            </div>
        </section>
    </div>    
    <!-- / ITERATIING ITEM LISTS -->
</aura:component>


CampingListController.js
({     
      doInit: function(component, event, helper) {
        
        // Create the action
        var action = component.get("c.getItems");
        
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.items", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        
        // Send action off to be executed
        $A.enqueueAction(action);
        },
        
    createItem: function(component, event, helper) {
        var newCamping = component.get("v.newItem");
        helper.createItem(component, newCamping);
    }
              
})


CampingListHelper.js
({
    createItem: function(component, camping) {
        
        var action = component.get("c.saveItem");
        action.setParams({
            "item": camping
        });
        action.setCallback(this, function(response){
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            var campings = component.get("v.items");
            campings.push(response.getReturnValue());
            component.set("v.items", campings);
        }
        });
        $A.enqueueAction(action);
    }
})


CampingListController
public with sharing class CampingListController{

    @AuraEnabled
    public static List<Camping_Item__c> getItems(){
    
        return [Select id, name, Packed__c, Price__c, Quantity__c from Camping_Item__c];
    }
    
    @AuraEnabled
    public static Camping_Item__c saveItem(Camping_Item__c Item){
    
        upsert Item;
        return Item;
    }

}