function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in 

Ideas Regarding Trigger

trigger feeditemnofication on FeedItem (after update,after insert) {
   for (feeditem F : Trigger.new)
    {       
        if(Trigger.isInsert)
        {

                feeditem EE = [Select body,parentid from feeditem where Id = :F.Id];  
                opportunity op=[select id,ownerid from opportunity where id=:EE.parentid] ;
                User U= [select id,Email,Name from user where id =:op.ownerid ];
                 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {U.email};                  
                mail.setToAddresses(toAddresses);                  
                mail.setSubject('Record Feed Notification to record  owner' );                
                mail.setPlainTextBody('Hello,' + '\n\n' +'Please consider the following feed'+' '+'\n\n'+'Subject :'+F.body );
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }

       }
}

In this parentid will of any thing like accound id ,opportunity id,quote id,userid--- i need to send email to the record owner when feed is posted .how i can write the code as global way (or) we need to write it seperately (if account id,if oppid,if quoteid).it woud be great it would have some sample code.
Swati GSwati G
Hi,

Check if you can use type of in query. You will have to get it enabled by contacting salesforce.

http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_typeof.htm


Cory CowgillCory Cowgill
You can use the Schema Describe Methods to get back Record ID Prefix information. 

With that information you can check the RecordID, and if it starts with the Prefix you can determine the type.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_namespace_Schema.htm

Here is a sample code for using this in some Apex:

http://corycowgill.blogspot.com/2011/01/building-dynamic-soql-select-all-query.html


You code will look similar to:
for(Schema.SObjectType objType : sobjects)
        {
            objDescribe = objType.getDescribe();
            String sobjectPrefix = objDescribe.getKeyPrefix();
            if(id != null && sobjectPrefix != null && id.startsWith(sobjectPrefix))


Cory CowgillCory Cowgill
Note: My above information is a bit old (BEFORE they gave TYPE in SOQL). But it still works. You should try and use the SOQL Type if you can get it enabled and it works for your use case, etc.