• Salesforce Geevan
  • 0 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
  • 0
Vf page 
<apex:page Controller="TEstConteroller" sidebar="false" standardStylesheets="true" showheader="false" >
<apex:form >
    <apex:pageBlock title="CASE" >
  <apex:pageBlockSection >
  <apex:inputtext value="{!Sub}" />
 <apex:inputtext value="{!Des}" />
<center> <apex:commandButton value="find" action="{!search}"  /></center>
 <apex:outputLabel >
   <c:PageBlockTableEnhancerADV targetPbTableIds="tableRecords" paginate="true" defaultPageSize="50" pageSizeOptions="50,100,200"/>
 <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 headerValue="Priority"> {!a.Priority} </apex:column>     
                <apex:column headerValue="Origin"> {!a.Origin} </apex:column> 
                              <apex:column headerValue="Owner"> {!a.owner.Name} </apex:column> 

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')) {
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.
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'>

margin-top:200px; }

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

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?');
   return pgRef;

My code is 
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  + '%'; 

[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}"/>
<table border='1' width='100%'>
  <apex:repeat value="{!cusList}" var="a">

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 TriggerCus on Customer__c (before insert) {
    for(Customer__c a:Trigger.new)
          list<Customer__c> Var=[select Mobile__c,Name__c from Customer__c];
               a.adderror('Duplicate name');