• Salesforce Geevan
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 0
    Replies
Vf page 
<apex:page Controller="TEstConteroller" sidebar="false" standardStylesheets="true" showheader="false" >
<apex:form >
    <apex:pageBlock title="CASE" >
  <apex:pageBlockSection >
  <label>Subject</label>
  <apex:inputtext value="{!Sub}" />
 <label>Description</label>
 <apex:inputtext value="{!Des}" />
<center> <apex:commandButton value="find" action="{!search}"  /></center>
 </apex:pageBlockSection>
 <apex:outputLabel >
   <c:PageBlockTableEnhancerADV targetPbTableIds="tableRecords" paginate="true" defaultPageSize="50" pageSizeOptions="50,100,200"/>
</apex:outputLabel>
 <apex:pageblockTable value="{!CaseList}" var="a" id="tableRecords" styleClass="list" border="1">
               <apex:column headerValue="CaseNumber">
     <apex:outputLink value="/{!a.id}">"{!a.CaseNumber}"</apex:outputLink>
</apex:column>
                  <apex:column headerValue="Priority"> {!a.Priority} </apex:column>     
                <apex:column headerValue="Origin"> {!a.Origin} </apex:column> 
                              <apex:column headerValue="Owner"> {!a.owner.Name} </apex:column> 
                        </apex:pageblockTable>
 </apex:pageBlock>

Controller
public class TEstConteroller
{
    public list<Case> caseList {get;set;}
     public string Des {get;set;}
         public string Sub{get;set;}

    public void search()
    {
        CaseList = new List<Case>();
for(Case act : [select id,CaseNumber , Priority,Origin,Case.owner.Name,Description,Subject,from Case ]) {
    if(act.Description.contains('Des') || act.Subject.contains('Sub')) {
        caseList.add(act);
    }
    
    }
}
}
 
 
i have a vf page which has username and pwd field, i want to login to the employee object  and also the hr object from a single vf page with username and pwd.
Below i created a login page for accessing Hr object,how can i access the Employee object using the same vf page.
Employee__c   
Fields are:  Username(Name),password( mobile__c)
 MY VF page :
<apex:page showHeader="false" sidebar="false" controller="login" standardStylesheets="false">
<apex:form >
<style type ='text/css'>
.h{
 

margin-top:200px; }
</style>

<h>
<label>UserName </label>
<apex:inputText value="{!username}"/>
<br/>
<label>PassWord </label>
<apex:inputText value="{!password}"/><br/>
<br/>
<apex:commandButton value="Submit" action="{!Login}"/></h>
</apex:form>
</apex:page>

Apex class
public with sharing class login{

String username;
String password;
public String getusername() {return username;}
public void setusername(String un){this.username=un;}
public String getpassword() {return password;}
public void setpassword(String pw){this.password=pw;}

public  pagereference Login(){

List<HR__c> a = [select id from HR__c where Name like:username and Mobile__c like:password ];
id idvar;
for(HR__c b : a)
{
idvar = b.id;
 }    
   pagereference pgRef;
   pgRef = new PageReference('https://ap2.salesforce.com/' + idvar +'/e?');
   pgRef.setredirect(true);    
   return pgRef;

}
}
My code is 
Controller:
public class  SearchNoButton{
public String find { get; set; }
public list<Customer__c> cuslist{get;set;}
public String searchtext{get;set;}

public string s ;
public void find()
{
cuslist=new list<Customer__c>();
s  = '%' + searchtext  + '%'; 

cuslist=
[select Name,Name__c,Status__c,age__c from Customer__c where Name__c LIKE : s];


}

}

visualforce page:
<apex:page controller="SearchNoButton" action="{!find}">
<apex:pageblock title="search Customer">
<apex:form Rendered="{!find}">
name  <apex:inputtext value="{!searchtext}" Rendered="{!find}"/>
</apex:form>
  </apex:pageblock>
<table border='1' width='100%'>
  <tr>
      <th>name</th><th>customername</th><th>Status</th><th>AGE</th>
  </tr>
  <apex:repeat value="{!cusList}" var="a">
  <tr>
      <td>{!a.Name}</td>
      <td>{!a.Name__c}</td>
      <td>{!a.Status__c}</td>
      <td>{!a.Age__c}</td>
  </tr>
  
  </apex:repeat>

  </table>
</apex:page>
The below is my code. when i run this code without trigger , its working properly...
I wrote a trigger for checking duplicates (name,mobile), while submitting it throws,
Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Duplicate name: []
Error is in expression '{!Custom_Save}' in component <apex:commandButton> in page customer: Class.Customer.Custom_Save: line 8, column 1
An unexpected error has occurred. Your development organization has been notified.
VF Page:
<apex:page controller="Customer">
<apex:form > <apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!cus.Name__c}"/><br/>
<apex:inputField value="{!cus.Age__c}"/><br/>
<apex:inputField value="{!cus.DOB__c}"/><br/>
<apex:inputField value="{!cus.ITEM__c}"/><br/>
<apex:inputField value="{!cus.Mobile__c}"/><br/>
<apex:inputField value="{!cus.Quantity__c}"/><br/>
<apex:inputField value="{!cus.Status__c}"/><br/>
<apex:inputField value="{!cus.DATE_TIME__c}"/><br/> <apex:inputField value="{!cus.Yes_No__c}"/>
<apex:commandButton value="Save" action="{!Custom_Save}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

Apex Code
Public class Customer{
Public Customer__c cus{get;set;}

public Customer(){
     cus = new Customer__c();
}
public void Custom_Save()
{
     insert cus;
}
}

Trigger
trigger TriggerCus on Customer__c (before insert) {
    for(Customer__c a:Trigger.new)
    {
        if((a.Mobile__c!=null)&&(a.Name__c!=null))
        {
          list<Customer__c> Var=[select Mobile__c,Name__c from Customer__c];
            if(var.size()>0)
            {
               a.adderror('Duplicate name');
            }
                
        }
    }
}