+ Start a Discussion
sreejasreeja 

did any body completed the trialhead challange i had stucked here to complete it

public class BusScheduleCache {

    private Cache.OrgPartition part;
    
      
      
       public BusScheduleCache (){
       
        
        Cache.OrgPartition part = cache.org.getpartition('local.BusSchedule');
        
     
       
       }
       
       
       
       
        public void  putSchedule(String busLine, Time[] schedule){
     
      
      
       Part.put(busLine, '12'); 
       
     //  Part.put(schedule, {5,6,7});   
        
        
        }
        
        
        
       public getSchedule(String busLine){
        
        
        
if (cachedvalue!= null) {
    
    return null;
    
} else {
    
      return null;
}
        }
}

and display in the visualforce page; 

<apex:outputfiled>
 
Best Answer chosen by sreeja
Raj VakatiRaj Vakati
Use this code .. 
 
<apex:page controller="BusScheduleCache" tabStyle="Account">
    
</apex:page>


 
public with sharing class BusScheduleCache {
    private Cache.OrgPartition part;

    public BusScheduleCache(){
        this.part = new Cache.OrgPartition('local.BusSchedule');
    }

    public void putSchedule(String busLine, Time[] schedul){
        part.put(busLine, schedul);
    }

    public Time[] getSchedule(String busLine){
        Time[] cacheSchedule = (Time[])part.get(busLine);
        if(null==cacheSchedule){
            cacheSchedule = new Time[2];
            cacheSchedule[0] = Time.newInstance(8,0,0,0);
            cacheSchedule[1] = Time.newInstance(17,0,0,0);
            return cacheSchedule;
        }else{
            return cacheSchedule;
        }
    }
}

 

All Answers

Deepali KulshresthaDeepali Kulshrestha
Hi sree,

Please try this code: 

public class BusScheduleCache {   
    // Get partition
    private Cache.OrgPartition part;
    String partitionName = 'local.BusSchedule';
    
    public BusScheduleCache () {
        if(partitionName !=null){
            Cache.OrgPartition orgPart = new Cache.OrgPartition(partitionName);
            if(orgPart != null){
                part = orgPart;
            }
        }
    }
    
    public void putSchedule(String busLine, Time[] schedule) {
        if (part != null){
            part.put(busline, schedule);
        }
    }
        
    public Time[] getSchedule(String busLine) {
        Time[] schedule = new List<Time>();
        
        // Get a cached value
        Object obj = part.get(busLine);
        // Cast return value to a specific data type
        Time t2;
        if (obj != null) {
            t2 = (Time)obj;
        }
        if (t2 != null) {
            schedule.add(t2);
        }
        else {
            Time t3 = Time.newInstance(8,0,0,0);
            if (t3 != null){
                schedule.add(t3);
            }
            Time t4 = Time.newInstance(17,0,0,0);
            if (t4 != null){
                schedule.add(t4);
            }
        }     
        return schedule;
    } 
      
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
 
sreejasreeja
hi deepali.. thanks for your reply, how can i call it in the visualforce page??? as it have the input parameters
 
Raj VakatiRaj Vakati
Use this code .. 
 
<apex:page controller="BusScheduleCache" tabStyle="Account">
    
</apex:page>


 
public with sharing class BusScheduleCache {
    private Cache.OrgPartition part;

    public BusScheduleCache(){
        this.part = new Cache.OrgPartition('local.BusSchedule');
    }

    public void putSchedule(String busLine, Time[] schedul){
        part.put(busLine, schedul);
    }

    public Time[] getSchedule(String busLine){
        Time[] cacheSchedule = (Time[])part.get(busLine);
        if(null==cacheSchedule){
            cacheSchedule = new Time[2];
            cacheSchedule[0] = Time.newInstance(8,0,0,0);
            cacheSchedule[1] = Time.newInstance(17,0,0,0);
            return cacheSchedule;
        }else{
            return cacheSchedule;
        }
    }
}

 
This was selected as the best answer
sreejasreeja
Thanks raj;