• WeylandYutanie
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi again!  I would like to try something like the following on a custom object I created (feed tracking is active for properties).

 

--  When a custom object is created/updated, I would like to push the chatter post to a specific Group.

 

To do this, I believe I will need to do the following:

1) Set up an Apex Trigger under:  Setup-->Customize-->Chatter-->Triggers

 

But I am not sure how to code this.  Are there any examples online that I could refernce?  It would be great to not have the chatter area on the custom object's tab and only sends feed updates to the Group.

 

Many thanks,

Weyland

Hi,  I have two classes with a master-detail relationship. It's currently set up so that object2 points to object1 and can access properties like this:

 

obj2.obj1__r.property

 

Object 2 also has a status field.  When I set that field to say 'Done', I would like to change the master-detail relationship so that it points to a completely new object.  The purpose of this: I would basically like to archive object2 so it doesn't show up in a list when I look at the object1 Tab.

 

I'm not sure how to go about this.  I think I can just query for the ID of the appropriate object1 and do the following:

 

LIST<object1> object1IDs = [SELECT id FROM object1 WHERE name = 'Done'];

for (object 2 myvar: trigger.old)

myvar.obj1__c = ID;

 

But I know this is wrong, any hints?

 

Thanks!

~Weyland

Hi again, another error I am running into.  I have a collection of objects that I want to update a numeric paramer.  Error I get is:

 

UpdateOtherSpotEntries: execution of BeforeDelete
caused by: System.DmlException: Update failed. First exception on row 0 with id a03E0000001AS6HIAW; first error: DUPLICATE_VALUE, duplicate value found: LineNum__c duplicates value on record with id: a03E0000001AS8h: []
Trigger.UpdateOtherSpotEntries: line 17, column 5

 

Here is my code, I think I don't have a good understanding of what exactly the SELECT function does for me.  Doesn't it get me a List all objects with status = 'Pending' that I can loop through and modify?  Since I queried the LineNum__c parameter, I should be able to set to new values. 

 

Many thanks,

Weyland

 

trigger UpdateOtherSpotEntries on Place_in_Line__c (before delete) {

    LIST<Place_in_Line__c> AllPending = [SELECT LineNum__c FROM Place_in_Line__c WHERE Place_in_Line__c.Status__c = 'Pending'];

    if (AllPending.size() > 0)
    {
        for (Place_in_Line__c ToUpdate : AllPending )
        {
            if (ToUpdate.LineNum__c > 2)
                 ToUpdate.LineNum__c = ToUpdate.LineNum__c - 1;
        }
       
    }
    update AllPending;
}

 

Hi, I am getting the following error when trying to update a field on the before deletion of an object:

LeavingTheLine: execution of BeforeDelete
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.LeavingTheLine: line 5, column 9

I must be missing something really obvious. Any help appreciated.

Weyland


Code:
1 trigger LeavingTheLine on Place_in_Line__c (before delete) 
2 {
3     for (Place_in_Line__c SpotInLine : Trigger.old)
4     {
5          SpotInLine.Group_Leader_Line__r.Number_of_People_in_Line__c = 1;
6     }
7 }



Hi again, another error I am running into.  I have a collection of objects that I want to update a numeric paramer.  Error I get is:

 

UpdateOtherSpotEntries: execution of BeforeDelete
caused by: System.DmlException: Update failed. First exception on row 0 with id a03E0000001AS6HIAW; first error: DUPLICATE_VALUE, duplicate value found: LineNum__c duplicates value on record with id: a03E0000001AS8h: []
Trigger.UpdateOtherSpotEntries: line 17, column 5

 

Here is my code, I think I don't have a good understanding of what exactly the SELECT function does for me.  Doesn't it get me a List all objects with status = 'Pending' that I can loop through and modify?  Since I queried the LineNum__c parameter, I should be able to set to new values. 

 

Many thanks,

Weyland

 

trigger UpdateOtherSpotEntries on Place_in_Line__c (before delete) {

    LIST<Place_in_Line__c> AllPending = [SELECT LineNum__c FROM Place_in_Line__c WHERE Place_in_Line__c.Status__c = 'Pending'];

    if (AllPending.size() > 0)
    {
        for (Place_in_Line__c ToUpdate : AllPending )
        {
            if (ToUpdate.LineNum__c > 2)
                 ToUpdate.LineNum__c = ToUpdate.LineNum__c - 1;
        }
       
    }
    update AllPending;
}

 

Hi, I am getting the following error when trying to update a field on the before deletion of an object:

LeavingTheLine: execution of BeforeDelete
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.LeavingTheLine: line 5, column 9

I must be missing something really obvious. Any help appreciated.

Weyland


Code:
1 trigger LeavingTheLine on Place_in_Line__c (before delete) 
2 {
3     for (Place_in_Line__c SpotInLine : Trigger.old)
4     {
5          SpotInLine.Group_Leader_Line__r.Number_of_People_in_Line__c = 1;
6     }
7 }