• humble learner
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Hi All,

 

I am trying to create a trigger on Feed Item to prevent unauthorized users to post. Unfortunately, I am getting following error on all Feed:

 

caused by: System.FinalException: SObject row does not allow errors

 My code is below:

public class ChatterPrevent{
    public static void CheckUserAccess(List<FeedItem> FeedPrevent){
        Set<id> licensetype = new Set<id>();
        Set<id> isfeedenabled = new set<id>();
        //Map<id,User> nocommentorpost = new Map<id,User>();
        Set<id> nocommentorpost = new Set<id>();
        Set<id> commentonly = new Set<id>();
        //Map<id,String> userstatforchatteranswer = new Map<id,String>();
        List<UserLicense> AllPartnerUsers = [SELECT Id,Name FROM UserLicense where name = 'Partner Community'];
        
        /*for(FeedItem fi: FeedPrevent){
        	isfeedenabled.add(fi.CreatedById);
        }*/
        
        for(UserLicense UL:AllPartnerUsers){
        	licensetype.add(UL.id);
        }
        List<User> unauthorizedusers = [SELECT Id,isActive, user.profile.userlicenseid,name,Community_Chatter_Permissions__c,Community_Chatter_Answers_permissions__c
                                        FROM User where user.profile.userlicenseid in: licensetype and isActive = true];
        for(User U:unauthorizedusers){
            if(U.Community_Chatter_Permissions__c == 'Cannot Post or Comment'){
        		//nocommentorpost.put(U.id,U);
                nocommentorpost.add(U.id);
            }
            else if(U.Community_Chatter_Permissions__c == 'Can Comment Only'){
            	commentonly.add(U.id);
            }
        }
        System.debug('id'+unauthorizedusers);
        
        
        List<FeedItem> getAllFeed = [select id,InsertedbyId from FeedItem where InsertedbyId in:nocommentorpost];
        //System.debug(getAllFeed);
        
        for(User fu:[select id from User where id in:nocommentorpost]){
            for(FeedItem fi:getAllFeed){
                if(fu.id==fi.InsertedById){
                    System.debug(fi.Id);
                	fi.adderror('You are not Authorized to Post or Comment');
                }
            }
        }
    }
    
    
}

 

I am new to Apex any direction will be greatly appreciated....

 

Thank you.

Hi Everyone,

 

I am new to Salesforce platform and need some help on the following Issue. Any co-operation would be appreciated:

 

I want to have a trigger to prevent some users to post any question or reply to any question on chatter answer. I believe chatter and chatter answer are two separate objects ( correct me if I am wrong please). Now which object my trigger should be on as I can not see an object named chatter answer in salesforce?

 

Thanks for your help.

Hello Everyone,

 

I am new to salesforce and apex and still trying to learn the trade. I was wondering if someone could have a look and point me towards the right direction on the error I am getting:

 

I am capturing the Id and fields in a Map from an external webservice in the following format:

list<String> resultlist = new list<string>();
Map<String, list<string>> resultMap = new Map<String, list<String>>{};


resultMap.put(MSId,resultlist);// MSId is the id(key) and mslist are string values



 

Now I have to compare the Id with salesforce record Id and insert the fields into the record. I have taken following approach which is resulting in an error :

List<Me__c> Ms = [select id, name, quantity__c, amount__c, target__c where name in:resultMap.keyset()];//name is the id in this case
        system.debug(Ms);
        for(Me__c m: Ms){
            //for(List<String> mapvalues:msmap.values()){ did not work??
            for(String mapvalues:resultMap.keyset()){
                //System.debug(mapvalues.costscore);
                m.amount__c = Double.valueof(resultMap.get(m.name).amount);//error....Initial term of field expression must be a concrete sobject
            }
        }

 Now What am I not doing right here?? Or how can I achieve my goal?

 

I know there are a lot of Pros here. It's very clear to them...

 

Thanks everyone. 

 

 

Hello Everyone,

 

I am new to salesforce and apex and still trying to learn the trade. I was wondering if someone could have a look and point me towards the right direction on the error I am getting:

 

I am capturing the Id and fields in a Map from an external webservice in the following format:

list<String> resultlist = new list<string>();
Map<String, list<string>> resultMap = new Map<String, list<String>>{};


resultMap.put(MSId,resultlist);// MSId is the id(key) and mslist are string values



 

Now I have to compare the Id with salesforce record Id and insert the fields into the record. I have taken following approach which is resulting in an error :

List<Me__c> Ms = [select id, name, quantity__c, amount__c, target__c where name in:resultMap.keyset()];//name is the id in this case
        system.debug(Ms);
        for(Me__c m: Ms){
            //for(List<String> mapvalues:msmap.values()){ did not work??
            for(String mapvalues:resultMap.keyset()){
                //System.debug(mapvalues.costscore);
                m.amount__c = Double.valueof(resultMap.get(m.name).amount);//error....Initial term of field expression must be a concrete sobject
            }
        }

 Now What am I not doing right here?? Or how can I achieve my goal?

 

I know there are a lot of Pros here. It's very clear to them...

 

Thanks everyone. 

 

 

Hi All,

 

I am trying to create a trigger on Feed Item to prevent unauthorized users to post. Unfortunately, I am getting following error on all Feed:

 

caused by: System.FinalException: SObject row does not allow errors

 My code is below:

public class ChatterPrevent{
    public static void CheckUserAccess(List<FeedItem> FeedPrevent){
        Set<id> licensetype = new Set<id>();
        Set<id> isfeedenabled = new set<id>();
        //Map<id,User> nocommentorpost = new Map<id,User>();
        Set<id> nocommentorpost = new Set<id>();
        Set<id> commentonly = new Set<id>();
        //Map<id,String> userstatforchatteranswer = new Map<id,String>();
        List<UserLicense> AllPartnerUsers = [SELECT Id,Name FROM UserLicense where name = 'Partner Community'];
        
        /*for(FeedItem fi: FeedPrevent){
        	isfeedenabled.add(fi.CreatedById);
        }*/
        
        for(UserLicense UL:AllPartnerUsers){
        	licensetype.add(UL.id);
        }
        List<User> unauthorizedusers = [SELECT Id,isActive, user.profile.userlicenseid,name,Community_Chatter_Permissions__c,Community_Chatter_Answers_permissions__c
                                        FROM User where user.profile.userlicenseid in: licensetype and isActive = true];
        for(User U:unauthorizedusers){
            if(U.Community_Chatter_Permissions__c == 'Cannot Post or Comment'){
        		//nocommentorpost.put(U.id,U);
                nocommentorpost.add(U.id);
            }
            else if(U.Community_Chatter_Permissions__c == 'Can Comment Only'){
            	commentonly.add(U.id);
            }
        }
        System.debug('id'+unauthorizedusers);
        
        
        List<FeedItem> getAllFeed = [select id,InsertedbyId from FeedItem where InsertedbyId in:nocommentorpost];
        //System.debug(getAllFeed);
        
        for(User fu:[select id from User where id in:nocommentorpost]){
            for(FeedItem fi:getAllFeed){
                if(fu.id==fi.InsertedById){
                    System.debug(fi.Id);
                	fi.adderror('You are not Authorized to Post or Comment');
                }
            }
        }
    }
    
    
}

 

I am new to Apex any direction will be greatly appreciated....

 

Thank you.

Hello Everyone,

 

I am new to salesforce and apex and still trying to learn the trade. I was wondering if someone could have a look and point me towards the right direction on the error I am getting:

 

I am capturing the Id and fields in a Map from an external webservice in the following format:

list<String> resultlist = new list<string>();
Map<String, list<string>> resultMap = new Map<String, list<String>>{};


resultMap.put(MSId,resultlist);// MSId is the id(key) and mslist are string values



 

Now I have to compare the Id with salesforce record Id and insert the fields into the record. I have taken following approach which is resulting in an error :

List<Me__c> Ms = [select id, name, quantity__c, amount__c, target__c where name in:resultMap.keyset()];//name is the id in this case
        system.debug(Ms);
        for(Me__c m: Ms){
            //for(List<String> mapvalues:msmap.values()){ did not work??
            for(String mapvalues:resultMap.keyset()){
                //System.debug(mapvalues.costscore);
                m.amount__c = Double.valueof(resultMap.get(m.name).amount);//error....Initial term of field expression must be a concrete sobject
            }
        }

 Now What am I not doing right here?? Or how can I achieve my goal?

 

I know there are a lot of Pros here. It's very clear to them...

 

Thanks everyone.