• Rajendra Shukla 22
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
controller===>
public class actionFunctionController{
    public Position__c poc{get;set;}
    public Boolean show{get;set;}
    public Boolean showmessage{get;set;}
    
    public actionFunctionController(ApexPages.StandardController stdController){
        String pid = ((Position__c)stdcontroller.getRecord()).Id;
        poc=[select id,name,Hire_By__c,Hiring_Manager__c,Job_Level__c,Functional_Area__c,Job_Description__c,Location__c,Max_Pay__c,
             Min_Pay__c,Open_Date__c,Responsibilities__c,Travel_Required__c,Type__c,Status__c,Cancellation_Reason__c from Position__c where id=: pid];
             show = false;
    }
    public PageReference Savefun(){
        try{
            if(poc.Status__c =='Cancelled' && poc.Cancellation_Reason__c == null){
                showmessage = true;    
                return null;
                }  
            else{
                update poc;
                showmessage=false;
                PageReference newPage = new PageReference('https://ap2.salesforce.com/'+ApexPages.currentPage().getParameters().get('id'));
                return newPage;
                }
            }
        catch(Exception e){
            ApexPages.addMessages(e);
            return null;
        }
        return null;        
    }
    public PageReference priorityChanged(){
        if(poc.Status__c == 'Cancelled'){
            show = true;
        }
        else{
            show = false;
        }
        return null;
    }
}


test class-->
@istest
public class Test_Action_contrller {
    Static TestMethod void test_Method(){
        Position__c poc = new Position__c();
        poc.name = 'Hari';
        poc.Hire_By__c = Date.newInstance(2017, 12,30);
        poc.Status__c='Cancelled';
        poc.Cancellation_Reason__c='Cancelled';
        insert poc;
        Position__c poc1 = new Position__c();
        poc1.name = 'Hari';
        poc1.Hire_By__c = Date.newInstance(2017, 12,30);
        poc1.Status__c='Cancelled';
        poc1.Cancellation_Reason__c='';
        insert poc1;
        Position__c poc2 = new Position__c(name = 'Hari',Hire_By__c = Date.newInstance(2017, 11,30),Status__c='Canceld',Cancellation_Reason__c='not need');
        insert poc2;
        ApexPages.StandardController sc= new  ApexPages.StandardController(poc);
        ApexPages.StandardController sc1= new  ApexPages.StandardController(poc1);
         ApexPages.StandardController sc2= new  ApexPages.StandardController(poc2);
        actionFunctionController afc=new actionFunctionController(sc);
        actionFunctionController afc1=new actionFunctionController(sc1);
        actionFunctionController afc2=new actionFunctionController(sc2);
           Test.startTest();
        afc.priorityChanged();
        afc.Savefun();
        afc1.Savefun();
        afc2.priorityChanged();
        afc2.Savefun();
        Test.stopTest();
           }    
}
hear is my controller class--------------------->
public class actionFunctionController {
    public Position__c poc{get;set;}
    public Boolean show{get;set;}
    public Boolean showmessage{get;set;}
    
    public actionFunctionController(ApexPages.StandardController stdController){
        poc=[select id,name,Hire_By__c,Hiring_Manager__c,Job_Level__c,Functional_Area__c,Job_Description__c,Location__c,Max_Pay__c,Min_Pay__c,Open_Date__c,Responsibilities__c,Travel_Required__c,Type__c,Status__c,Cancellation_Reason__c from Position__c where id=:ApexPages.currentPage().getParameters().get('id')];
        show = false;
    }
    public PageReference Savefun(){
        try{
            if(poc.Status__c =='Cancelled' && poc.Cancellation_Reason__c == null){
                showmessage = true;    
                return null;
                }  
            else{
                update poc;
                showmessage=false;
                PageReference newPage = new PageReference('https://ap2.salesforce.com/'+ApexPages.currentPage().getParameters().get('id'));
                return newPage;
                }
            }
        catch(Exception e){
            ApexPages.addMessages(e);
            return null;
        }
        return null;
        
    }
    public PageReference priorityChanged(){
        if(poc.Status__c == 'Cancelled'){
            show = true;
        }
        else{
            show = false;
        }
        return null;
    }
}

vf page--------------->
<apex:page standardController="Position__c" extensions="actionFunctionController">
    <style>
     .myCustomMessage .message {color: Red !important;}
    </style>
    <apex:form >
        <apex:pageBlock title="{!$User.FirstName}">
            <apex:pageBlockButtons >
                <apex:commandButton value="sAVE" action="{!Savefun}"/>
                <apex:commandButton value="cANCEL" action="{!cancel}" />
            </apex:pageBlockButtons>
        <apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/>
            <apex:pageBlockSection title="Please Enter The Changes" columns="1" id="out" collapsible="false">
                <apex:inputField value="{!poc.name}"/>
                <apex:inputField value="{!poc.Hire_By__c}"/>
                <apex:inputField value="{!poc.Hiring_Manager__c}"/>
                <apex:inputField value="{!poc.Job_Level__c}"/>
                <apex:inputField value="{!poc.Functional_Area__c}"/>
                <apex:inputField value="{!poc.Job_Description__c}"/>
                <apex:inputField value="{!poc.Location__c}"/>
                <apex:inputField value="{!poc.Max_Pay__c}"/>
                <apex:inputField value="{!poc.Min_Pay__c}"/>
                <apex:inputField value="{!poc.Open_Date__c}"/>
                <apex:inputField value="{!poc.Responsibilities__c}"/>
                <apex:inputField value="{!poc.Travel_Required__c}"/>
                <apex:inputField value="{!poc.Type__c}"/>
                <apex:inputField value="{!poc.Status__c}" onchange="priorityChangedJavaScript()"/>
                <apex:inputField value="{!poc.Cancellation_Reason__c}" rendered="{!show}"/>
                <apex:outputPanel styleClass="myCustomMessage" rendered="{!showmessage}">
                <apex:pageMessage severity="error" strength="1" summary="Please enter the reason" />
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controlleer---------------------->
public class InterviewTwo_Controller {
    public list<Account>listAccount{set;get;}
    public String searchString{set;get;}
    public boolean showmsg{set;get;}
    public InterviewTwo_Controller(){
        listAccount =new list<Account>();
        showmsg= false;
    }
    public PageReference displayAccounts(){
        string AccountQuery='select id,name,BillingState,Phone,Website from Account where name Like '+searchString;
        if(searchString !='' && searchString != null){
          // AccountQuery= AccountQuery+'where name Like \'%'+searchString+'%\'';
           // AccountQuery= AccountQuery+searchString;
            listAccount=database.query('select id,name,BillingState,Phone,Website from Account where name Like '+searchString);
            //listAccount=database.query(searchString);
            if(listAccount.size()>0 && listAccount!=null){
                showmsg=false;
            }else{
                ApexPages.Message errMsg =new ApexPages.Message(Apexpages.Severity.WARNING,'No Account Found');
                ApexPages.addMessage(errMsg);
                showmsg=true;
            }
        }
        return null;
    }
}

VFPage------------------------->
<apex:page controller="InterviewTwo_Controller" sidebar="false" >
    <apex:form >
    <apex:sectionHeader title="InterviewTwo"/>
    <apex:pageBlock mode="Edit">
        <apex:pageBlockSection title="Search">
            <apex:inputText label="Search" value="{!searchString}" />
            <apex:commandButton value="Search" action="{!displayAccounts}" />
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Result" rendered="{!showmsg==true}" >
            <apex:pageMessages rendered="{!showmsg}">
            </apex:pageMessages><br/>
            <apex:pageBlockTable value="{!listAccount}" var="a" headerClass="headerclass">
                <apex:column headerValue="Account_Name" value="{!a.Name}" />
                <apex:column headerValue="Billing" value="{!a.BillingState}"/>
                <apex:column headerValue="Phone" value="{!a.phone}" />
                <apex:column headerValue="Website" value="{!a.Website}"/>                
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Result" rendered="{!showmsg==false}" >
            <apex:outputLabel value="{!searchString}" />
            <apex:pageBlockTable value="{!listAccount}" var="a" headerClass="headerclass">
                <apex:column headerValue="Account Name" value="{!a.Name}" />
                <apex:column headerValue="Billing" value="{!a.BillingState}"/>
                <apex:column headerValue="Phone" value="{!a.phone}" />
                <apex:column headerValue="Website" value="{!a.Website}"/>                
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
   </apex:form>
</apex:page>
controller===>
public class actionFunctionController{
    public Position__c poc{get;set;}
    public Boolean show{get;set;}
    public Boolean showmessage{get;set;}
    
    public actionFunctionController(ApexPages.StandardController stdController){
        String pid = ((Position__c)stdcontroller.getRecord()).Id;
        poc=[select id,name,Hire_By__c,Hiring_Manager__c,Job_Level__c,Functional_Area__c,Job_Description__c,Location__c,Max_Pay__c,
             Min_Pay__c,Open_Date__c,Responsibilities__c,Travel_Required__c,Type__c,Status__c,Cancellation_Reason__c from Position__c where id=: pid];
             show = false;
    }
    public PageReference Savefun(){
        try{
            if(poc.Status__c =='Cancelled' && poc.Cancellation_Reason__c == null){
                showmessage = true;    
                return null;
                }  
            else{
                update poc;
                showmessage=false;
                PageReference newPage = new PageReference('https://ap2.salesforce.com/'+ApexPages.currentPage().getParameters().get('id'));
                return newPage;
                }
            }
        catch(Exception e){
            ApexPages.addMessages(e);
            return null;
        }
        return null;        
    }
    public PageReference priorityChanged(){
        if(poc.Status__c == 'Cancelled'){
            show = true;
        }
        else{
            show = false;
        }
        return null;
    }
}


test class-->
@istest
public class Test_Action_contrller {
    Static TestMethod void test_Method(){
        Position__c poc = new Position__c();
        poc.name = 'Hari';
        poc.Hire_By__c = Date.newInstance(2017, 12,30);
        poc.Status__c='Cancelled';
        poc.Cancellation_Reason__c='Cancelled';
        insert poc;
        Position__c poc1 = new Position__c();
        poc1.name = 'Hari';
        poc1.Hire_By__c = Date.newInstance(2017, 12,30);
        poc1.Status__c='Cancelled';
        poc1.Cancellation_Reason__c='';
        insert poc1;
        Position__c poc2 = new Position__c(name = 'Hari',Hire_By__c = Date.newInstance(2017, 11,30),Status__c='Canceld',Cancellation_Reason__c='not need');
        insert poc2;
        ApexPages.StandardController sc= new  ApexPages.StandardController(poc);
        ApexPages.StandardController sc1= new  ApexPages.StandardController(poc1);
         ApexPages.StandardController sc2= new  ApexPages.StandardController(poc2);
        actionFunctionController afc=new actionFunctionController(sc);
        actionFunctionController afc1=new actionFunctionController(sc1);
        actionFunctionController afc2=new actionFunctionController(sc2);
           Test.startTest();
        afc.priorityChanged();
        afc.Savefun();
        afc1.Savefun();
        afc2.priorityChanged();
        afc2.Savefun();
        Test.stopTest();
           }    
}
hear is my controller class--------------------->
public class actionFunctionController {
    public Position__c poc{get;set;}
    public Boolean show{get;set;}
    public Boolean showmessage{get;set;}
    
    public actionFunctionController(ApexPages.StandardController stdController){
        poc=[select id,name,Hire_By__c,Hiring_Manager__c,Job_Level__c,Functional_Area__c,Job_Description__c,Location__c,Max_Pay__c,Min_Pay__c,Open_Date__c,Responsibilities__c,Travel_Required__c,Type__c,Status__c,Cancellation_Reason__c from Position__c where id=:ApexPages.currentPage().getParameters().get('id')];
        show = false;
    }
    public PageReference Savefun(){
        try{
            if(poc.Status__c =='Cancelled' && poc.Cancellation_Reason__c == null){
                showmessage = true;    
                return null;
                }  
            else{
                update poc;
                showmessage=false;
                PageReference newPage = new PageReference('https://ap2.salesforce.com/'+ApexPages.currentPage().getParameters().get('id'));
                return newPage;
                }
            }
        catch(Exception e){
            ApexPages.addMessages(e);
            return null;
        }
        return null;
        
    }
    public PageReference priorityChanged(){
        if(poc.Status__c == 'Cancelled'){
            show = true;
        }
        else{
            show = false;
        }
        return null;
    }
}

vf page--------------->
<apex:page standardController="Position__c" extensions="actionFunctionController">
    <style>
     .myCustomMessage .message {color: Red !important;}
    </style>
    <apex:form >
        <apex:pageBlock title="{!$User.FirstName}">
            <apex:pageBlockButtons >
                <apex:commandButton value="sAVE" action="{!Savefun}"/>
                <apex:commandButton value="cANCEL" action="{!cancel}" />
            </apex:pageBlockButtons>
        <apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/>
            <apex:pageBlockSection title="Please Enter The Changes" columns="1" id="out" collapsible="false">
                <apex:inputField value="{!poc.name}"/>
                <apex:inputField value="{!poc.Hire_By__c}"/>
                <apex:inputField value="{!poc.Hiring_Manager__c}"/>
                <apex:inputField value="{!poc.Job_Level__c}"/>
                <apex:inputField value="{!poc.Functional_Area__c}"/>
                <apex:inputField value="{!poc.Job_Description__c}"/>
                <apex:inputField value="{!poc.Location__c}"/>
                <apex:inputField value="{!poc.Max_Pay__c}"/>
                <apex:inputField value="{!poc.Min_Pay__c}"/>
                <apex:inputField value="{!poc.Open_Date__c}"/>
                <apex:inputField value="{!poc.Responsibilities__c}"/>
                <apex:inputField value="{!poc.Travel_Required__c}"/>
                <apex:inputField value="{!poc.Type__c}"/>
                <apex:inputField value="{!poc.Status__c}" onchange="priorityChangedJavaScript()"/>
                <apex:inputField value="{!poc.Cancellation_Reason__c}" rendered="{!show}"/>
                <apex:outputPanel styleClass="myCustomMessage" rendered="{!showmessage}">
                <apex:pageMessage severity="error" strength="1" summary="Please enter the reason" />
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controlleer---------------------->
public class InterviewTwo_Controller {
    public list<Account>listAccount{set;get;}
    public String searchString{set;get;}
    public boolean showmsg{set;get;}
    public InterviewTwo_Controller(){
        listAccount =new list<Account>();
        showmsg= false;
    }
    public PageReference displayAccounts(){
        string AccountQuery='select id,name,BillingState,Phone,Website from Account where name Like '+searchString;
        if(searchString !='' && searchString != null){
          // AccountQuery= AccountQuery+'where name Like \'%'+searchString+'%\'';
           // AccountQuery= AccountQuery+searchString;
            listAccount=database.query('select id,name,BillingState,Phone,Website from Account where name Like '+searchString);
            //listAccount=database.query(searchString);
            if(listAccount.size()>0 && listAccount!=null){
                showmsg=false;
            }else{
                ApexPages.Message errMsg =new ApexPages.Message(Apexpages.Severity.WARNING,'No Account Found');
                ApexPages.addMessage(errMsg);
                showmsg=true;
            }
        }
        return null;
    }
}

VFPage------------------------->
<apex:page controller="InterviewTwo_Controller" sidebar="false" >
    <apex:form >
    <apex:sectionHeader title="InterviewTwo"/>
    <apex:pageBlock mode="Edit">
        <apex:pageBlockSection title="Search">
            <apex:inputText label="Search" value="{!searchString}" />
            <apex:commandButton value="Search" action="{!displayAccounts}" />
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Result" rendered="{!showmsg==true}" >
            <apex:pageMessages rendered="{!showmsg}">
            </apex:pageMessages><br/>
            <apex:pageBlockTable value="{!listAccount}" var="a" headerClass="headerclass">
                <apex:column headerValue="Account_Name" value="{!a.Name}" />
                <apex:column headerValue="Billing" value="{!a.BillingState}"/>
                <apex:column headerValue="Phone" value="{!a.phone}" />
                <apex:column headerValue="Website" value="{!a.Website}"/>                
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Result" rendered="{!showmsg==false}" >
            <apex:outputLabel value="{!searchString}" />
            <apex:pageBlockTable value="{!listAccount}" var="a" headerClass="headerclass">
                <apex:column headerValue="Account Name" value="{!a.Name}" />
                <apex:column headerValue="Billing" value="{!a.BillingState}"/>
                <apex:column headerValue="Phone" value="{!a.phone}" />
                <apex:column headerValue="Website" value="{!a.Website}"/>                
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
   </apex:form>
</apex:page>