• Saurabh Tripathi 18
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Need to allow an unauthenticated guest user to access an inbound flow to facilitate Lightning Scheduler. When navigating to the community page as a guest, I always encounter an error and the flow component does not show. Required objects are granted read only access via sharing rules, as they are not listed on the community's guest profile. Community is build-your-own theme.
 write a trigger on Account, While inserting a account  name value as ‘someName’ ended with ‘text’ ex: ‘renuText’.
 it should through an error On Account Object if name field has 'text' 
  • January 31, 2018
  • Like
  • 0
trigger EventTrigger on Event (before Insert, before update) {
        public static String communityId=Network.getNetworkId();
        
        if(trigger.isInsert){
            if(communityID!=null){ 
                String CommunityName=ConnectApi.Communities.getCommunity(communityId).name;
                //Update public calendar events for HR4HR community
                if(CommunityName=='HR4HR'){
                   publicCalendar__c pc = [SELECT ID__c FROM publiccalendar__c WHERE Name=: 'HR4HR Community Calendar'];
                   
                   for(Event e:trigger.new){
                       e.OwnerID=pc.ID__c;
                   }
                }
                
                //Update public calendar events for Tech Exchange community
                if(CommunityName=='TechExchange'){
                   publicCalendar__c pc = [SELECT ID__c FROM publiccalendar__c WHERE Name=: 'TechExchange Community Calendar'];
                   for(Event e:trigger.new){
                       e.OwnerID=pc.ID__c;
                   }
                }
            }
        }
        
        if(trigger.isUpdate){
           if(CommunityID!=null){
                for(Event e:trigger.New){
                    if(!(Trigger.OldMap.get(e.id).ownerId==e.ownerId)){
                        e.ownerID.addError('Assigned To field cannot be edited');
                    }    
                }
                
               
            }
            
        }

}

Above is my class and below is my test class.
 
@isTest(seeallData=true)
 public class EventTriggerTest{
  
  
  public static testMethod void testEventTrigger(){
        Network community;
        String communityId;   
        
        Id currentUserId = UserInfo.getUserId();    
        User usr = [select id,Name from User where id =: currentUserId]; 
        
   
     system.runAs(usr){
    community = [SELECT id, Name,OptionsReputationEnabled FROM Network where name =: 'TechExchange'];
        communityId = community.id;
     
    system.debug('Test User Inside Network'+network.getnetworkid());
       
      Event eve = new Event(
            // OwnerId= usr.Id,
             ActivityDate=system.today(),
             StartDateTime=system.now().addhours(35),
             EndDateTime=system.now().addhours(36),
             Subject='Test',
             Description='Testing the event controller'
                               );
      insert eve;
      
      Event e = [Select id, Subject from Event where id=:eve.id];
       
       System.assertEquals('Test', e.subject);
       e.subject='New';
       update e;
       
         
    }

     
  
  }
   
 
  

 }