Monday, 23 June 2014

Based on Picklist Visible Lookup Field


Here "Risk Assessment" is a Picklist and "Peer Reviewer" is a Lookup field.

<apex:pageBlockSectionItem >
 <apex:outputLabel value="Risk Assessment"></apex:outputLabel>
  <apex:actionRegion>
   <apex:inputField value="{!thisCon.theCase.Risk_Assessment__c}" rendered="{!thisCon.caseRTN       ame == 'OD Change'}"> 
    <apex:actionSupport event="onchange" rerender="pr,prr" />      
  </apex:inputField>
 </apex:actionRegion>
</apex:pageBlockSectionItem>
  
<apex:pageBlockSectionItem >
 <apex:outputLabel value="Peer Reviewer"></apex:outputLabel>
  <apex:outputPanel id="pr"> 
   <apex:outputPanel rendered="{!if(thisCon.theCase.Risk_Assessment__c != null,true,false)}"> 
   <apex:inputField value="{!thisCon.theCase.Peer_Reviewer__c}" rendered="{!thisCon.caseRTNam        e == 'OD Change'}" required="true"/>
  </apex:outputPanel>
 </apex:outputPanel> 
</apex:pageBlockSectionItem>


This is another way:-


 <apex:actionRegion >
  <apex:inputField value="{!thisCon.theCase.Risk_Assessment__c}" required="true" rendered="{!     thisCon.caseRTName == 'OD Change'}">  
   <apex:actionSupport event="onchange" rerender="pr,rp" />      
  </apex:inputField>   
 </apex:actionRegion>
   
 <apex:pageBlockSectionItem >
  <apex:outputPanel id="rp" >
   <apex:outputText value="Risk Assessment" rendered="{!if(thisCon.theCase.Risk_Assessment__c       != null,true,false)}"/>
  </apex:outputPanel> 

 <apex:outputPanel id="pr">
  <apex:outputPanel rendered="{!if(thisCon.theCase.Risk_Assessment__c != null,true,false)}">
   <apex:inputField value="{!thisCon.theCase.Peer_Reviewer__c}" rendered="{!thisCon.caseRTNam         e == 'OD Change'}" />
  </apex:outputPanel>
 </apex:outputPanel>  
</apex:pageBlockSectionItem>


Friday, 13 June 2014

Using Schedulable interface Testclass

@isTest 
public class ContractAmendmentLinkageTestClass{
@isTest static void Amendment(){
ContractAmendmentLinkage Contractobj = new ContractAmendmentLinkage ();
String sch = '20 30 8 10 2 ?';
String jobID = system.schedule('ContractAmendmentLinkage JOB', sch, Contractobj);

Datetime sysTime = System.now().addSeconds( 300 );     
String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
System.Schedule('SelfSchedule ' + sysTime, chronExpression, new ContractAmendmentLinkage() );
  }
}



sch: Is the corn expression ,the corn expression is nothing but the next scheduled time.
ContractAmendmentLinkage JOB: is the name of the job.

Contractobj:: is the object of the scheduled class which we need to run.
corn expression for to run schedule(ContractAmendmentLinkage) every 5min. below

// This is Self-Schedule To Execution purpose.

(Datetime sysTime = System.now().addSeconds( 300 );   
String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
System. Schedule( 'SelfSchedule ' + sysTime, chronExpression, new ContractAmendmentLinkage() );)

Thursday, 12 June 2014

Refreshing the formula field based on text field using Trigger.

Refreshing the fields based on text field(FX Rate to usd) parent to child will refresh(Calculations using formula field) parent.

Parent to child to parent updation using trigger.

Trigger:-

trigger Fieldupdations on Opportunity_Margin_Template__c (after update) {
List<Opportunity_Margin_Template__c> templist = new List<Opportunity_Margin_Template__c>();
List<Opportunity_Template_Task__c> templatetasklist = new List<Opportunity_Template_Task__c>();
set<id> setid = new set<id>();
for(Opportunity_Margin_Template__c margin: Trigger.new)
{
 setid.add(margin.id);
}
List<Opportunity_Margin_Template__c> tasklist = [select Id,Name,Template_Save_as__c,FX_Rate_to_USD__c from Opportunity_Margin_Template__c
                                                 where id in:setid];
templatetasklist =[select id, Cost_Hr__c,Opportunity_Margin_Template__c from   Opportunity_Template_Task__c where  Opportunity_Margin_Template__r.id In : setid];                                        
for(Opportunity_Margin_Template__c temp: tasklist)
{
 if(temp.FX_Rate_to_USD__c!=Trigger.oldmap.get(temp.Id).FX_Rate_to_USD__c)
 {
   templist.add(temp);
 }
}
update templatetasklist ;      
update templist;                                                                                
             

}