• Sain
  • NEWBIE
  • 65 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 36
    Questions
  • 20
    Replies
Hi,

I have requirement to display total amount spend by individual per partucular month like shown below, i have Name,Entry Date, Amount__c fields in custom object.  

Name              Current Month Total Amount
Name1                      10000
Name2                        5000
Name3                       40000

Here Current month total Amount is sum of amount__c spend by particular user in whole month.

for example: i have user vinod, he has created 5 records(record1 Amount is 10,record2 Amount is 100,record3 Amount is 10,record4 Amount is 250,record5 Amount is 50) in a particular month.  now i have to display as below

Name                 Current Month Total Amount
vinod                  420(this value is sum of amount spend by particular user for whole month )
ganesh               1000

if any one can provide me a sample code how to achive this it would be great thankfull.

Thanks In Advance
Sain
  • September 02, 2015
  • Like
  • 0
Hi,

I have requirement to display total amount spend by individual per partucular month like shown below, i have Name, Amount__c fields in custom object.  


Name              Current Month Total Amount
Name1                      10000
Name2                        5000
Name3                       40000

if any one can provide me a sample code how to achive this it would be great thankfull.

Thanks In Advance
Sain
  • September 01, 2015
  • Like
  • 0
Hi,

I am developing a VF page, where i have implemented custom date input field but it is not working.

Please help to know where i am going wrong.

VF page:
<apex:page controller="CustomCalendarClass">
<apex:includeScript value="{!URLFOR($Resource.JSCalander,'calendar/calendar.js')}"/>
<apex:stylesheet value="{!URLFOR($Resource.JSCalander,'calendar/calendar_blue.css')}" />
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
Start Date<apex:inputText value="{!startdate}" size="10" id="startdate" onmouseover="initialiseCalendar(this, '{!$Component.startdate}')" />

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

 <script>
function fnSetDateFormat(oDateFormat)
{
 oDateFormat['FullYear'];  //Example = 2007
 oDateFormat['Year'];   //Example = 07
 oDateFormat['FullMonthName']; //Example = January
 oDateFormat['MonthName'];  //Example = Jan
 oDateFormat['Month'];   //Example = 01
 oDateFormat['Date'];   //Example = 01
 oDateFormat['FullDay'];   //Example = Sunday
 oDateFormat['Day'];    //Example = Sun
 oDateFormat['Hours'];   //Example = 01
 oDateFormat['Minutes'];   //Example = 01
 oDateFormat['Seconds'];   //Example = 01
  
 var sDateString;
  
 // Use dd/mm/yyyy format
 sDateString = oDateFormat['Date'] +"/"+ oDateFormat['Month'] +"/"+ oDateFormat['FullYear'];
 return sDateString;
}
   
     
function initialiseCalendar(obj, eleId)
{
 var element=document.getElementById(eleId);
 var params='close=true';
 if (null!=element)
 {
  if (element.value.length>0)
  {
   // date is formatted dd/mm/yyyy - pull out the month and year
   var month=element.value.substr(3,2);
   var year=element.value.substr(6,4);
   params+=',month='+month;
   params+=',year='+year;
  }
 }
 fnInitCalendar(obj, eleId, params);
}
</script>
<script>
$(function() {
$( "#expdate" ).datepicker();
$( "#anim" ).change(function() {
$( "#expdate" ).datepicker( "option", "showAnim", $( this ).val() );
});
});
</script>
</apex:page>

Class:
public with sharing class CustomCalendarClass {
public string startdate {get;set;}
}

Regards,
Sain
  • August 26, 2015
  • Like
  • 0
Hi,

I have scenario where i have to search data with start date and end date, for this iam using custom input picker but its not getting any calender to pick date.

with refere: http://bobbuzzard.blogspot.in/2012/03/custom-date-picker.html 

User-added image
VF Page:
<apex:page controller="ExpensesClass" >
<apex:includeScript value="{!URLFOR($Resource.Calendar,'calendar/calendar.js')}"/>
<apex:stylesheet value="{!URLFOR($Resource.Calendar,'calendar/calendar_blue.css')}" />

<apex:form >
<apex:pageBlock >
<apex:pagemessages />
<apex:pageBlockSection title="Search Criteria"  collapsible="false">
<apex:pageBlockSectionItem >
Start Date<apex:inputText value="{!startdate}" size="10" id="startdate" onmouseover="initialiseCalendar(this, '{!$Component.startdate}')" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >

End Date<apex:inputText value="{!enddate}" id="enddate" size="10" onmouseover="initialiseCalendar(this, '{!$Component.enddate}')"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Owner Name:"/>
<apex:inputText value="{!nameQuery}"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:CommandButton action="{!executeSearch}" value="Search"  />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

<script>
function fnSetDateFormat(oDateFormat)
{
 oDateFormat['FullYear'];  //Example = 2007
 oDateFormat['Year'];   //Example = 07
 oDateFormat['FullMonthName']; //Example = January
 oDateFormat['MonthName'];  //Example = Jan
 oDateFormat['Month'];   //Example = 01
 oDateFormat['Date'];   //Example = 01
 oDateFormat['FullDay'];   //Example = Sunday
 oDateFormat['Day'];    //Example = Sun
 oDateFormat['Hours'];   //Example = 01
 oDateFormat['Minutes'];   //Example = 01
 oDateFormat['Seconds'];   //Example = 01
  
 var sDateString;
  
 // Use dd/mm/yyyy format
 sDateString = oDateFormat['Date'] +"/"+ oDateFormat['Month'] +"/"+ oDateFormat['FullYear'];
 return sDateString;
}
   
     
function initialiseCalendar(obj, eleId)
{
 var element=document.getElementById(eleId);
 var params='close=true';
 if (null!=element)
 {
  if (element.value.length>0)
  {
   // date is formatted dd/mm/yyyy - pull out the month and year
   var month=element.value.substr(3,2);
   var year=element.value.substr(6,4);
   params+=',month='+month;
   params+=',year='+year;
  }
 }
 fnInitCalendar(obj, eleId, params);
}
</script>
</apex:page>

Class:

public class ExpensesClass {
public string nameQuery{get;set;}
public List<Expense__c> expensesList{get;set;}
public Boolean isTableExit {get;set;}
public Date enddate{get; set;}
public Date startdate{get; set;}

public ExpensesClass(){
//expList =[Select id, Item__c, owner.name,sum(Amount__c) From Expense__c];
}
public PageReference executeSearch(){
string str='%'+nameQuery+'%';
if(nameQuery==null || nameQuery==''){
    //errormessage ='Name cannot be null or empty. Please Try Again.';
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter Owner Name'));
}else{
expensesList=[Select id, Item__c, owner.name,Amount__c, Date__c From Expense__c where owner.name LIKE:str Limit:limitsize Offset:offsetsize];
}

isTableExit =true;
return null;
}
}


Thabks in advance,
Shaik
  • August 26, 2015
  • Like
  • 0
Hi,

I want to display Grand Total Amount of amount field in expensive object. 

Please help me to achieve this.
User-added image

**VF Page:**

<apex:page controller="ExpensesClass" >

<apex:form >
<!-- Need this variables for totals generation -->
<apex:variable value="{!0}" var="total1"/>

<apex:pageBlock >

<apex:pageBlockTable value="{!expensesList}" var="e" rendered="{!isTableExit}" >

<apex:column value="{!e.Date__c}"/>
<!--<apex:column value="{!e.Item__c}"/>-->
<apex:column >
<apex:outputLink target="_blank" value="/{!e.id}">{!e.Item__c}</apex:outputLink>
</apex:column>

<apex:column headerValue="Amount">
<apex:outputField value="{!e.Amount__c}" />
<apex:variable var="total1" value="{!e.Amount__c+total1}" />
<apex:facet name="footer">
               Total: <span class="t1"></span>   
</apex:facet>
</apex:column>
        
</apex:pageBlockTable>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Grand Total Amount:"/>
<apex:outputText value="{!totalsum1}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<script>
    // Here we will set the generated subtotals to the footer cells
    
    document.getElementsByClassName('t1')[0].innerHTML = '{!total1}'; 
</script>
</apex:form>
</apex:page>

**Class:**
public class ExpensesClass {
public string nameQuery{get;set;}
public List<Expense__c> expensesList{get;set;}
public Boolean isTableExit {get;set;}
public Date fromdate {get; set;}
public Date todate {get; set;}
public list<AggregateResult> totalsum {get;set;}
public integer totalsum1{get;set;}

//public List<Expense__c> expensesList {get; set;}
public ExpensesClass(){
totalsize=[Select count() From Expense__c];
totalsum=new list<AggregateResult>();
//totalsum=[Select sum(Amount__c) From Expense__c];
}

public PageReference executeSearch(){
string str='%'+nameQuery+'%';
if(nameQuery==null || nameQuery==''){
    //errormessage ='Name cannot be null or empty. Please Try Again.';
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter Owner Name'));
}else{
expensesList=[Select id, Item__c, owner.name,Amount__c, Date__c From Expense__c where owner.name LIKE:str Limit:limitsize Offset:offsetsize];
}

return null;
}

public Void gettotalsum1(){
AggregateResult[] groupedresult=[Select sum(Amount__c) From Expense__c];
object totalsum1=groupedresult[0].get('total');
//return totalsum;
}
}

Thanks in advance 
Sain
 
  • August 25, 2015
  • Like
  • 0
Hi,

I have written test class for below VF page, but iam getting only 59% of code coverage, Please help me to make it to 100% .

<apex:page controller="SearchClass" >
<apex:form >
<apex:pageBlock >
<apex:pagemessages />
{!errormessage }
<apex:pageBlockSection title="Search Criteria"  collapsible="false">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Name:"/>
<apex:inputText value="{!nameQuery}"/>

</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:CommandButton action="{!executeSearch}" value="Search"  />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockTable value="{!tableList}" var="p" rendered="{!isTableExit}" >
<apex:column >
<apex:outputLink target="_blank" value="/{!p.id}">{!p.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!p.Parent_Name__c}"/>
<apex:column value="{!p.Gender__c}"/>
<apex:column value="{!p.Marital_Status__c}"/>
<apex:column value="{!p.Phone__c}"/>
<apex:column value="{!p.Email__c}"/>
</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
</apex:page>

Class:
public with sharing class SearchClass {

public string nameQuery{get;set;}
public List<object__c> tableList{get;set;}
public Boolean isTableExit {get;set;}
public string errormessage {get;set;}

public List<object__c> plist=new List<object__c>([Select id, name From object__c]);

public PageReference executeSearch(){
string queryStr='%'+nameQuery+'%';
if(nameQuery==null || nameQuery==''){
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter Name'));
}else{
tableList=[Select id,name,Phone__c,Email__c,parent_Name__c,Gender__c,Marital_Status__c From object__c where name=:nameQuery];

}
isTableExit =true;
return null;
}

public SearchClass(){
string urlQuery=ApexPages.currentPage().getParameters().get('query');
if ( (null!=urlQuery) && (0!=urlQuery.length()) )
  {
   nameQuery=urlQuery;
   executeSearch();
  }
 
 isTableExit=false;
}
}

Test Class:

@isTest
public class SampleSearch{

static TestMethod void testSampleSearch(){
PageReference pageRef = Page.SampleSearch;
Test.setCurrentPageReference(pageRef);
SearchClass myclass=new SearchClass();
object__c pobj=new object__c ();
pobj.name='test';

myclass.executeSearch();

pobj.name='test1';
myclass.executeSearch();
}
}


Thanks in advance
Sain
  • August 24, 2015
  • Like
  • 0
Hi,

What is the diff b/w utility and helper class? please help me with example..

Thanks in Advance 
  • August 20, 2015
  • Like
  • 0
Hi,

Iam trying to get populate field values into popup page while cliking on formula field on custom detail page.  

getting error: Id value is not valid for the Visitor__c standard controller

and also values not populating popup fields.

VF Page:

<apex:page standardController="Visitor__c" sidebar="false" extensions="CustomVisitorDetailExt" >
<script>
 var newWin=null;
 
 function openLookupPopup(mid)
 {
  var url="/apex/PopUpforVisitor?id=" +mid;
  <!--var url="/apex/PopUpforVisitor";-->
  newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
  if (window.focus) 
  {
   newWin.focus();
  }
    
     return false;
    }
       
 function closeLookupPopup()
 {
    if (null!=newWin)
    {
       newWin.close();
    }  
 }
</script>
<apex:form >
<apex:actionFunction name="VisitorAddress" action="{!VisitorAddress}" rerender="accinfo, msgs" >
<apex:param name="recordId" value="" assignTo="{!recordId}"/>
</apex:actionfunction>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection Title="Visitor Details:" collapsible="false" id="accinfo">
<apex:outputField value="{!Visitor__c.name}"/>
<apex:outputField value="{!Visitor__c.Gender__c}"/>
<apex:outputField value="{!Visitor__c.Email__c}"/>
<apex:outputField value="{!Visitor__c.Phone__c}"/>
<apex:outputField value="{!Visitor__c.Patient__c}"/>
<apex:outputField value="{!Visitor__c.Relashionship__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection Title="Address Information:" collapsible="false">

<apex:inputField value="{!Visitor__c.Current_Address__c}" onclick="openLookupPopup('{!$Component.targetName}', '{!$Component.targetId}');"/>
<!--<apex:inputField value="{!Visitor__c.Current_Address__c}" onclick="openLookupPopup('{!myd}');return false;"/>-->
 
  <!--<apex:outputText value="{!Visitor__c.Current_Address__c}"  />
  <apex:outputlink onclick="window.showModalDialog('\apex\PopUpforVisitor')" target="_blank"  value="/{Visitor__c.id}" > {!Visitor__c.Current_Address__c}
   <apex:actionSupport event="onClick" action="{!VisitorAddress}" reRender="result,mypage" status="status"/>
  </apex:outputlink>-->
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Popup VF Page:

<apex:page standardController="Visitor__c" sidebar="false" showHeader="false" extensions="CustomVisitorDetailExt">
<apex:form >
<apex:pageBlock >

<apex:pageBlockSection Title="Address Information:" collapsible="false" columns="1">
  <!--<apex:repeat value="{!$ObjectType.Visitor__c.fieldsets.Address}" var="fValue">
                 <apex:outputfield value="{!Visitor__c[fValue]}"/>
             </apex:repeat>-->
<apex:inputField value="{!Vist.Address_Line1__c}"/>  
<apex:inputField value="{!vist.Address_Line2__c}"/>  
<apex:inputField value="{!vist.City__c}"/>  
<apex:inputField value="{!vist.State__c}"/>  
<apex:outputField value="{!vist.PinCode__c}"/>  
<apex:inputField value="{!vist.Land_Mark__c }"/>  
 
          
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Class:

public with sharing class CustomVisitorDetailExt {
public visitor__c vist {get;set;}
public id recordId {get;set;}
public id myd {get;set;}

public ApexPages.StandardController standardCon;
    public CustomVisitorDetailExt(ApexPages.StandardController con) {
    standardCon=con;
    vist =new visitor__c();
  myd=apexpages.currentpage().getparameters().get('recordId');
System.debug('>>>>urlid' +myd);
    }
public PageReference VisitorAddress(){
PageReference page=new PageReference('/apex/PopUpforVisitor?id=' +myd);

 //visitor__c vis= (visitor__c) standardCon.getRecord();
    vist= [select Address_Line1__c,Address_Line2__c,City__c,PinCode__c,State__c,Land_Mark__c from visitor__c where id =: myd ];
    //vist.Address_Line1__c=vis.Address_Line1__c;
    //vist.Address_Line2__c=vis.Address_Line2__c;
    //vist.Address_Line1__c=apexpages.currentpage().getparameters().get('vis.Address_Line1__c');
    //vist.Address_Line2__c=apexpages.currentpage().getparameters().get('vis.Address_Line2__c');
return page;
}
}

Please help me to solve this issue.

Regards,
Sain
  • August 12, 2015
  • Like
  • 0
Hi,

Iam trying to get populate field values into popup page while cliking on formula field on custom detail page.  

getting error: Id value is not valid for the Visitor__c standard controller

and also values not populating popup fields
.

VF Page:

<apex:page standardController="Visitor__c" sidebar="false" extensions="CustomVisitorDetailExt" >
<script>
 var newWin=null;
 
 function openLookupPopup(mid)
 {
  var url="/apex/PopUpforVisitor?id=" +mid;
  <!--var url="/apex/PopUpforVisitor";-->
  newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
  if (window.focus) 
  {
   newWin.focus();
  }
    
     return false;
    }
       
 function closeLookupPopup()
 {
    if (null!=newWin)
    {
       newWin.close();
    }  
 }
</script>
<apex:form >
<apex:actionFunction name="VisitorAddress" action="{!VisitorAddress}" rerender="accinfo, msgs" >
<apex:param name="recordId" value="" assignTo="{!recordId}"/>
</apex:actionfunction>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection Title="Visitor Details:" collapsible="false" id="accinfo">
<apex:outputField value="{!Visitor__c.name}"/>
<apex:outputField value="{!Visitor__c.Gender__c}"/>
<apex:outputField value="{!Visitor__c.Email__c}"/>
<apex:outputField value="{!Visitor__c.Phone__c}"/>
<apex:outputField value="{!Visitor__c.Patient__c}"/>
<apex:outputField value="{!Visitor__c.Relashionship__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection Title="Address Information:" collapsible="false">

<apex:inputField value="{!Visitor__c.Current_Address__c}" onclick="openLookupPopup('{!$Component.targetName}', '{!$Component.targetId}');"/>
<!--<apex:inputField value="{!Visitor__c.Current_Address__c}" onclick="openLookupPopup('{!myd}');return false;"/>-->
 
  <!--<apex:outputText value="{!Visitor__c.Current_Address__c}"  />
  <apex:outputlink onclick="window.showModalDialog('\apex\PopUpforVisitor')" target="_blank"  value="/{Visitor__c.id}" > {!Visitor__c.Current_Address__c}
   <apex:actionSupport event="onClick" action="{!VisitorAddress}" reRender="result,mypage" status="status"/>
  </apex:outputlink>-->
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Popup VF Page:

<apex:page standardController="Visitor__c" sidebar="false" showHeader="false" extensions="CustomVisitorDetailExt">
<apex:form >
<apex:pageBlock >

<apex:pageBlockSection Title="Address Information:" collapsible="false" columns="1">
  <!--<apex:repeat value="{!$ObjectType.Visitor__c.fieldsets.Address}" var="fValue">
                 <apex:outputfield value="{!Visitor__c[fValue]}"/>
             </apex:repeat>-->
<apex:inputField value="{!Vist.Address_Line1__c}"/>  
<apex:inputField value="{!vist.Address_Line2__c}"/>  
<apex:inputField value="{!vist.City__c}"/>  
<apex:inputField value="{!vist.State__c}"/>  
<apex:outputField value="{!vist.PinCode__c}"/>  
<apex:inputField value="{!vist.Land_Mark__c }"/>  
 
          
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Class:

public with sharing class CustomVisitorDetailExt {
public visitor__c vist {get;set;}
public id recordId {get;set;}
public id myd {get;set;}

public ApexPages.StandardController standardCon;
    public CustomVisitorDetailExt(ApexPages.StandardController con) {
    standardCon=con;
    vist =new visitor__c();
  myd=apexpages.currentpage().getparameters().get('recordId');
System.debug('>>>>urlid' +myd);
    }
public PageReference VisitorAddress(){
PageReference page=new PageReference('/apex/PopUpforVisitor?id=' +myd);

 //visitor__c vis= (visitor__c) standardCon.getRecord();
    vist= [select Address_Line1__c,Address_Line2__c,City__c,PinCode__c,State__c,Land_Mark__c from visitor__c where id =: myd ];
    //vist.Address_Line1__c=vis.Address_Line1__c;
    //vist.Address_Line2__c=vis.Address_Line2__c;
    //vist.Address_Line1__c=apexpages.currentpage().getparameters().get('vis.Address_Line1__c');
    //vist.Address_Line2__c=apexpages.currentpage().getparameters().get('vis.Address_Line2__c');
return page;
}
}

Please help me to solve this issue.

Regards,
Sain
  • August 12, 2015
  • Like
  • 0
Hi,

I have custom object called patient and fields name, email__c, gender__c(piclist), Doctor__c(lookup field).
I developed a dynamic search page to fetch the related data and display in a table based on values given in input fields called name, email__c, Doctor__c. 
I am able to get data based on name, email__c, but iam facing problem with fetching data based on search given in picklist field(Gender__c), Doctor__c(lookup field)..

please help me modify code to solve this issue.

Visualforce Page:
<apex:page id="myPage" controller="DynamicSearchPatientClass" sidebar="false">
<script type="text/javascript">
 function doSearch() {
   searchServer(
          document.getElementById("myPage:myFrm:pbMain:pbsMain:Name").value,
          document.getElementById("myPage:myFrm:pbMain:pbsMain:Gender").value,
          document.getElementById("myPage:myFrm:pbMain:pbsMain:Email").value,
          document.getElementById("myPage:myFrm:pbMain:pbsMain:Doctor").value);
  }

</script>   
 <apex:form id="myFrm">
 <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="result">
 <apex:param name="Name" value="" />
<apex:param name="Gender" value="" />
 <apex:param name="Email" value="" />
<apex:param name="Doctor" value="" />
</apex:actionFunction>      

<apex:pageBlock id="pbMain">
<apex:pageBlockSection id="pbsMain" title="Patient Search" collapsible="false"columns="2" >
Patient Name<apex:inputText value="{!objPatients.Name}" id="Name"onkeyup="doSearch();"/>
 Gender<apex:inputText value="{!objPatients.Gender__c}" id="Gender"onchange="doSearch();"/>
Email<apex:inputText value="{!objPatients.Email__c}" id="Email"onkeyup="doSearch();"/>
Doctor Name<apex:inputText value="{!objPatients.Doctor__c }" id="Doctor"onchange="doSearch();"/>

</apex:pageBlockSection>           

<apex:pageBlockSection title="Patient Details" id="result" >
<apex:pageBlockTable value="{!patients}" var="p" id="result2">
 <apex:column value="{!p.Name}"/>
 <apex:column value="{!p.Gender__c}"/>
<apex:column value="{!p.Email__c}"/>
 <apex:column value="{!p.Doctor__c }"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

Apex Class:

 public with sharing class DynamicSearchPatientClass {
 Private string soql {get;set;}
public Patient__c objPatients {get;set;}
public List<Patient__c> patients {get;set;}
public String sortDir{
get { if (sortDir == null) { sortDir = 'asc'; }
return sortDir;}
set;
 }   

public String sortField {
get {if  ( sortField == null) {
sortField = 'Name'; } return sortField; }
set;
}   

public void runQuery() {
try {
patients= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20 ');
system.debug('>>>>>>4' +patients);
 }
catch (Exception e) {
 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' OOOps! ') );
 }
}   

public DynamicSearchPatientClass(){

soql='select name,Email__c,Gender__c,Doctor__c from patient__c where patient__c.Name != null';
system.debug('>>>>>>' +soql);

runQuery();   
}   

public PageReference runSearch(){

String Name = Apexpages.currentPage().getParameters().get('Name');
String Gender = Apexpages.currentPage().getParameters().get('Gender');
String Email = Apexpages.currentPage().getParameters().get('Email');
String Doctor= Apexpages.currentPage().getParameters().get('Doctor');       

soql='select name,Email__c,Gender__c,Doctor__c from patient__c where Name != null';  
system.debug('>>>>>>3' +soql);
if (!Name.equals(''))

soql += ' and Name LIKE \''+String.escapeSingleQuotes(Name)+'%\'';
system.debug('>>>>>>1' +soql);

if (!Email.equals(''))
soql += ' and Email__c LIKE \''+String.escapeSingleQuotes(Email)+'%\'';

if (!Gender.equals(''))
system.debug('>>>>>>2' +soql);
soql += ' and Gender__c LIKE \''+String.escapeSingleQuotes(Gender)+'%\'';

if (!Doctor.equals(''))
soql += ' and Doctor__c LIKE \''+String.escapeSingleQuotes(Doctor)+'%\'';       

runQuery();       
return null;   
 }
}

Regards,
Sain
  • August 11, 2015
  • Like
  • 0
Hi,

Please any one can explain me about apex:repeat component in salesforce? where we can use?

regards,
Sain
  • August 11, 2015
  • Like
  • 0
Hi,
I have custom object called patient and fields name, email__c, gender__c, Doctor__c(lookup field).
I have to develop a dynamic search page to fetch the related data and display in a table based on values given in input fields called name, email__c, Doctor__c.  but iam facing problem with fetching data based on search.

please help me to solve this issue.

<apex:page controller="DynamicSearchPatientClass" sidebar="false">
<script type="text/javascript">

      function doSearch() {

        searchServer(
          document.getElementById("Name").value,
          document.getElementById("Gender").value,
          document.getElementById("Email").value,
          document.getElementById("Doctor").value);
      }
      </script>

<apex:form >

<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,result2,errors">
          <apex:param name="Name" value="" />
          <apex:param name="Gender" value="" />
          <apex:param name="Email" value="" />
          <apex:param name="Doctor" value="" />
</apex:actionFunction>

<apex:pageBlock >
<apex:pageBlockSection title="Patient Search" collapsible="false" columns="2" >
Patient Name<apex:inputText value="{!patients.Name}" id="Name" onkeyup="doSearch();"/>
Gender<apex:inputText value="{!patients.Gender__c}" id="Gender" onchange="doSearch();"/>
Email<apex:inputText value="{!patients.Email__c}" id="Email" onkeyup="doSearch();"/>
Doctor Name<apex:inputText value="{!patients.Doctor__c }" id="Doctor" onchange="doSearch();"/>
</apex:pageBlockSection>

<apex:pageBlockSection title="Patient Details" id="result" >
<apex:pageBlockTable value="{!patients}" var="p" id="result2">
<apex:column value="{!p.Name}"/>
<apex:column value="{!p.Gender__c}"/>
<apex:column value="{!p.Email__c}"/>
<apex:column value="{!p.Doctor__c }"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Class:
public with sharing class DynamicSearchPatientClass {

Private string soql {get;set;}
public Patient__c patients {get;set;}

public String sortDir{
      get { if (sortDir == null) { sortDir = 'asc'; }
                   return sortDir;}
      set;}

public String sortField {
          get {if  ( sortField == null) {
                  sortField = 'Name'; } return sortField; }
          set;}

public void runQuery() {
              try {
                   patients= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20 ');
                   system.debug('>>>>>>4' +patients);
                    }
                    catch (Exception e) {
                     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' OOOps! ') );
                     }
     }    

public DynamicSearchPatientClass(){
 soql='select name,Email__c,Gender__c,Doctor__c from patient__c where patient__c.Name != null';
 system.debug('>>>>>>' +soql);
runQuery();

}

public PageReference runSearch(){
    String Name = Apexpages.currentPage().getParameters().get('Name');
    String Gender = Apexpages.currentPage().getParameters().get('Gender');
    String Email = Apexpages.currentPage().getParameters().get('Email');
    String Doctor= Apexpages.currentPage().getParameters().get('Doctor');

    soql='select name,Email__c,Gender__c,Doctor__c from patient__c where patient__c.Name != null';   
system.debug('>>>>>>3' +soql);
    if (!Name.equals(''))
      soql += ' and Name LIKE \' '+String.escapeSingleQuotes(Name)+'%\'';
   system.debug('>>>>>>1' +soql);
    if (!Email.equals(''))
      soql += ' and Email__c LIKE \''+String.escapeSingleQuotes(Email)+'%\'';
     if (!Gender.equals(''))
     system.debug('>>>>>>2' +soql);
      soql += ' and Gender__c LIKE \''+String.escapeSingleQuotes(Gender)+'%\'';
    if (!Doctor.equals(''))
      soql += ' and Doctor__c LIKE \''+String.escapeSingleQuotes(Doctor)+'%\'';

    runQuery();

return null;

}
}


Regards,
Sain
 
  • August 10, 2015
  • Like
  • 0
Hi,
I have custom object called patient and fields name, email__c, gender__c, Doctor__c(lookup field).
I have to develop a dynamic search page to fetch the related data and display in a table based on values given in input fields called name, email__c, Doctor__c.  but iam facing problem with fetching data based on search.

please help me to solve this issue.

<apex:page controller="DynamicSearchPatientClass" sidebar="false">
<script type="text/javascript">

      function doSearch() {

        searchServer(
          document.getElementById("Name").value,
          document.getElementById("Gender").value,
          document.getElementById("Email").value,
          document.getElementById("Doctor").value);
      }
      </script>

<apex:form >

<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,result2,errors">
          <apex:param name="Name" value="" />
          <apex:param name="Gender" value="" />
          <apex:param name="Email" value="" />
          <apex:param name="Doctor" value="" />
</apex:actionFunction>

<apex:pageBlock >
<apex:pageBlockSection title="Patient Search" collapsible="false" columns="2" >
Patient Name<apex:inputText value="{!patients.Name}" id="Name" onkeyup="doSearch();"/>
Gender<apex:inputText value="{!patients.Gender__c}" id="Gender" onchange="doSearch();"/>
Email<apex:inputText value="{!patients.Email__c}" id="Email" onkeyup="doSearch();"/>
Doctor Name<apex:inputText value="{!patients.Doctor__c }" id="Doctor" onchange="doSearch();"/>
</apex:pageBlockSection>

<apex:pageBlockSection title="Patient Details" id="result" >
<apex:pageBlockTable value="{!patients}" var="p" id="result2">
<apex:column value="{!p.Name}"/>
<apex:column value="{!p.Gender__c}"/>
<apex:column value="{!p.Email__c}"/>
<apex:column value="{!p.Doctor__c }"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Class:
public with sharing class DynamicSearchPatientClass {

Private string soql {get;set;}
public Patient__c patients {get;set;}

public String sortDir{
      get { if (sortDir == null) { sortDir = 'asc'; }
                   return sortDir;}
      set;}

public String sortField {
          get {if  ( sortField == null) {
                  sortField = 'Name'; } return sortField; }
          set;}

public void runQuery() {
              try {
                   patients= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20 ');
                   system.debug('>>>>>>4' +patients);
                    }
                    catch (Exception e) {
                     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' OOOps! ') );
                     }
     }    

public DynamicSearchPatientClass(){
 soql='select name,Email__c,Gender__c,Doctor__c from patient__c where patient__c.Name != null';
 system.debug('>>>>>>' +soql);
runQuery();

}

public PageReference runSearch(){
    String Name = Apexpages.currentPage().getParameters().get('Name');
    String Gender = Apexpages.currentPage().getParameters().get('Gender');
    String Email = Apexpages.currentPage().getParameters().get('Email');
    String Doctor= Apexpages.currentPage().getParameters().get('Doctor');

    soql='select name,Email__c,Gender__c,Doctor__c from patient__c where patient__c.Name != null';   
system.debug('>>>>>>3' +soql);
    if (!Name.equals(''))
      soql += ' and Name LIKE \' '+String.escapeSingleQuotes(Name)+'%\'';
   system.debug('>>>>>>1' +soql);
    if (!Email.equals(''))
      soql += ' and Email__c LIKE \''+String.escapeSingleQuotes(Email)+'%\'';
     if (!Gender.equals(''))
     system.debug('>>>>>>2' +soql);
      soql += ' and Gender__c LIKE \''+String.escapeSingleQuotes(Gender)+'%\'';
    if (!Doctor.equals(''))
      soql += ' and Doctor__c LIKE \''+String.escapeSingleQuotes(Doctor)+'%\'';

    runQuery();

return null;

}
}


Regards,
Sain
 
  • August 10, 2015
  • Like
  • 0
Hi,
I have requirment to auto populate parent object(Opporutnity) fields vales into child (Project__c) fields on the basis of selecting lookup field.
Please share the sample code.

VF Page:

<apex:page controller="autopopulateclass">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
<apex:inputField value="{!pro.Name}"/>
</apex:pageBlockSection>
<apex:actionRegion >
 <apex:pageBlockSection id="projectInfo" title="Information of Project">
 <apex:inputField value="{!pro.Opportunity__c}">
 <apex:actionSupport event="onchange" action="{!populateRelAccFields}" rerender="accountInfo"/>
 </apex:inputField>
 <!--<apex:outputField value="{!opp.Account.Phone}"/>
 <apex:outputField value="{!opp.Account.Type}"/>-->
 <apex:inputField value="{!pro.Mobile_No__c}"/>
  <apex:inputField value="{!pro.Email__c}"/>
 </apex:pageBlockSection>
 </apex:actionRegion>
 <apex:commandButton value="Cancel" action="{!cancel}"/>
 <apex:commandButton value="Save" action="{!save}"/>
</apex:pageblock>
</apex:form>
</apex:page>

Controller:

public with sharing class autopopulateclass {
public project__c pro{get; set;}
public opportunity opp{get;set;}

public autopopulateclass(){
pro=new project__c();
opp=new opportunity();
}

public pagereference populateRelAccFields(){
if(null!=pro.opportunity__c){
project__c pro1=new project__c();
pro1.mobile_No__c=opp.mobile_No__c;
pro1.email__c=opp.email__c;

}
return null;
}
public void save(){}
public void cancel(){}
}

Thanks in advance
Sain
  • July 28, 2015
  • Like
  • 0
Hi,
I have requirment to auto populate parent object(Opporutnity) fields vales into child (Project__c) fields on the basis of selecting lookup field.
Please share the sample code.

Thanks in advance
Sain
  • July 28, 2015
  • Like
  • 0
Hi,
I have requirment to auto populate parent object(Opporutnity) fields vales into child (Project__c) fields on the basis of selecting lookup field.
Please share the sample code.

VF Page:

<apex:page controller="autopopulateclass">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
<apex:inputField value="{!pro.Name}"/>
</apex:pageBlockSection>
<apex:actionRegion >
 <apex:pageBlockSection id="accountInfo" title="Information of Account">
 <apex:inputField value="{!pro.Opportunity__c}">
 <apex:actionSupport event="onchange" action="{!populateRelAccFields}" rerender="accountInfo"/>
 </apex:inputField>
 <!--<apex:outputField value="{!opp.Account.Phone}"/>
 <apex:outputField value="{!opp.Account.Type}"/>-->
 <apex:inputField value="{!pro.Mobile_No__c}"/>
  <apex:inputField value="{!pro.Email__c}"/>
 </apex:pageBlockSection>
 </apex:actionRegion>
 <apex:commandButton value="Cancel" action="{!cancel}"/>
 <apex:commandButton value="Save" action="{!save}"/>
</apex:pageblock>
</apex:form>
</apex:page>

Controller:

public with sharing class autopopulateclass {
public project__c pro{get; set;}
public opportunity opp{get;set;}

public autopopulateclass(){
pro=new project__c();
opp=new opportunity();
}

public pagereference populateRelAccFields(){
if(null!=pro.opportunity__c){
project__c pro1=new project__c();
pro1.mobile_No__c=opp.mobile_No__c;
pro1.email__c=opp.email__c;

}
return null;
}
public void save(){}
public void cancel(){}
}

Thanks in advance
Sain
  • July 28, 2015
  • Like
  • 0
Hi,

I have two objects called object1, object2(Master) and having lookup relationship among them, In object1 having a field called test1 and in Object2 having fields test2(piclist values are A,B), test3(picklist values x,y).
Now i am creating a validation rule on object1 to make test1 field mandatory while test2 is 'A' and test3 is 'x'

AND(ISPICKVAL(object1__r.test2__c='A'),ISPICKVAL(object2__r.test3__c='x') )

Getting below error:

 Field test2__c is a picklist field. Picklist fields are only supported in certain functions.

and also changed my expression with TEXT but still i am not able to sove it.
AND(TEXT(ISPICKVAL(object1__r.test2__c='A'))


Any suggestions from community.

Thanks in advance.



  • May 07, 2015
  • Like
  • 0
Hi,

I have two objects called object1, object2(Master) and having lookup relationship among them, In object1 having a field called test1 and in Object2 having fields test2(piclist values are A,B), test3(picklist values x,y).
Now i am creating a validation rule on object1 to make test1 field mandatory while test2 is 'A' and test3 is 'x'

AND(ISPICKVAL(object1__r.test2__c='A'),ISPICKVAL(object2__r.test3__c='x') )

Getting below error:

 Field test2__c is a picklist field. Picklist fields are only supported in certain functions.

and also changed my expression with TEXT but still i am not able to sove it.
AND(TEXT(ISPICKVAL(object1__r.test2__c='A'))


Any suggestions from community.

Thanks in advance.



 
  • May 07, 2015
  • Like
  • 0
Hi,
I have two objects doctor, appointment and there is a lookup relationship between them.  have a fields called appointment_date__c(date/time type) and doctor__c lookup field in Appointment.
Now i have to delete the Appointment records those are Schedule is 'Confirm'(Doctor object field) and current time is 30m before from appointment_date__c field time.

for suppose 5 records appointment time is 6:30PM and current time is 6:00PM, this 5 records have to fetch and delete.

My Batch Class:

Global class AppointmentDelete implements database.Batchable<sObject>{
    global database.QueryLocator start(database.BatchableContext BC){
    string c='Confirm';
    String query='Select id,Name, doctor__r.name from Appointment__C where doctor__r.Schedule__c =\'' + c + '\'';
    system.debug('>>>>>>>query: '+query);
    return database.getQueryLocator(query);
    }
    
    global Void execute(database.BatchableContext BC, List<Appointment__C> scope ){
            
        delete scope;
       
    }
    
    global void finish(database.BatchableContext BC){
        
    }
}

 
  • April 19, 2015
  • Like
  • 0
Hi,

I have two objects doctor, appointment and there is a lookup relationship between them.  have a fields called appointment_date__c(date/time type) and doctor__c lookup field in Appointment.
Now i have to delete the Appointment records those are Schedule is 'Confirm'(Doctor object field) and current time is 30m before from appointment_date__c field time.

for suppose 5 records appointment time is 6:30PM and current time is 6:00PM, this 5 records have to fetch and delete.

My Batch Class:

Global class AppointmentDelete implements database.Batchable<sObject>{
    global database.QueryLocator start(database.BatchableContext BC){
    string c='Confirm';
    String query='Select id,Name, doctor__r.name from Appointment__C where doctor__r.Schedule__c =\'' + c + '\'';
    system.debug('>>>>>>>query: '+query);
    return database.getQueryLocator(query);
    }
    
    global Void execute(database.BatchableContext BC, List<Appointment__C> scope ){
            
        delete scope;
       
    }
    
    global void finish(database.BatchableContext BC){
        
    }
}

 
  • April 18, 2015
  • Like
  • 0
Hi,

I have requirement to display total amount spend by individual per partucular month like shown below, i have Name,Entry Date, Amount__c fields in custom object.  

Name              Current Month Total Amount
Name1                      10000
Name2                        5000
Name3                       40000

Here Current month total Amount is sum of amount__c spend by particular user in whole month.

for example: i have user vinod, he has created 5 records(record1 Amount is 10,record2 Amount is 100,record3 Amount is 10,record4 Amount is 250,record5 Amount is 50) in a particular month.  now i have to display as below

Name                 Current Month Total Amount
vinod                  420(this value is sum of amount spend by particular user for whole month )
ganesh               1000

if any one can provide me a sample code how to achive this it would be great thankfull.

Thanks In Advance
Sain
  • September 02, 2015
  • Like
  • 0
Hi,

I have requirement to display total amount spend by individual per partucular month like shown below, i have Name, Amount__c fields in custom object.  


Name              Current Month Total Amount
Name1                      10000
Name2                        5000
Name3                       40000

if any one can provide me a sample code how to achive this it would be great thankfull.

Thanks In Advance
Sain
  • September 01, 2015
  • Like
  • 0
Hi,

I want to display Grand Total Amount of amount field in expensive object. 

Please help me to achieve this.
User-added image

**VF Page:**

<apex:page controller="ExpensesClass" >

<apex:form >
<!-- Need this variables for totals generation -->
<apex:variable value="{!0}" var="total1"/>

<apex:pageBlock >

<apex:pageBlockTable value="{!expensesList}" var="e" rendered="{!isTableExit}" >

<apex:column value="{!e.Date__c}"/>
<!--<apex:column value="{!e.Item__c}"/>-->
<apex:column >
<apex:outputLink target="_blank" value="/{!e.id}">{!e.Item__c}</apex:outputLink>
</apex:column>

<apex:column headerValue="Amount">
<apex:outputField value="{!e.Amount__c}" />
<apex:variable var="total1" value="{!e.Amount__c+total1}" />
<apex:facet name="footer">
               Total: <span class="t1"></span>   
</apex:facet>
</apex:column>
        
</apex:pageBlockTable>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Grand Total Amount:"/>
<apex:outputText value="{!totalsum1}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<script>
    // Here we will set the generated subtotals to the footer cells
    
    document.getElementsByClassName('t1')[0].innerHTML = '{!total1}'; 
</script>
</apex:form>
</apex:page>

**Class:**
public class ExpensesClass {
public string nameQuery{get;set;}
public List<Expense__c> expensesList{get;set;}
public Boolean isTableExit {get;set;}
public Date fromdate {get; set;}
public Date todate {get; set;}
public list<AggregateResult> totalsum {get;set;}
public integer totalsum1{get;set;}

//public List<Expense__c> expensesList {get; set;}
public ExpensesClass(){
totalsize=[Select count() From Expense__c];
totalsum=new list<AggregateResult>();
//totalsum=[Select sum(Amount__c) From Expense__c];
}

public PageReference executeSearch(){
string str='%'+nameQuery+'%';
if(nameQuery==null || nameQuery==''){
    //errormessage ='Name cannot be null or empty. Please Try Again.';
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter Owner Name'));
}else{
expensesList=[Select id, Item__c, owner.name,Amount__c, Date__c From Expense__c where owner.name LIKE:str Limit:limitsize Offset:offsetsize];
}

return null;
}

public Void gettotalsum1(){
AggregateResult[] groupedresult=[Select sum(Amount__c) From Expense__c];
object totalsum1=groupedresult[0].get('total');
//return totalsum;
}
}

Thanks in advance 
Sain
 
  • August 25, 2015
  • Like
  • 0
Hi Guys,

When i click button in list view page it will call batch class from there batch class call to Apex class. Actually i want to run a Apex class as a Asynchronously. I tried to put @future in Apex Class but it doesn't take return values. So could you please help me out this problem.

Thanks,
Mahesh.

 
Hi, 

I don't know what is wrong with my code.
If I change the selectedrtype, the page should run the onchange event to get the stagelist, but the stagelist remains blank.

Thanks,
Sascha

 
Public class depen002_class {

Public String SelectedRType {get; set;}

Public depen002_class() {

}

Public List <SelectOption> getRTypeList() {
    List <RecordType > RTypes = [SELECT Id, Name FROM RecordType WHERE sObjectType = 'Opportunity'];
    List <SelectOption> RTypeOptionList = new List <SelectOption>();
    FOR (RecordType R : RTypes) {
        RTypeOptionList.add (new SelectOption(R.Id, R.Name));
    }
    RETURN RTypeOptionList; 
}

Public List <SelectOption> getStageList() {
    
    List <SelectOption> StageOptionList = new List <SelectOption>();     
        
        IF (SelectedRType == '') {
            StageOptionList.add (new SelectOption('- None -', 'Stages empty'));
        } ELSE {
            StageOptionList.add (new SelectOption('- None -', 'You found a Stage'));
        } 
         
    RETURN NULL;               
    }
     
}
 
<apex:page controller="depen002_class">

<apex:form >

<table width="100%">
    <tr>
        <td align="center">
            <apex:selectList value="{!SelectedRType}" size="1" multiselect="false" style="width:150px">
             <apex:actionSupport event="onchange" action="{!getStageList}" />
                <apex:selectOptions value="{!RTypeList}" />             
            </apex:selectList>
        </td>        
    </tr>
</table>


<table width="100%">
    <tr>
        <td align="center">
            <apex:selectList size="1" multiselect="false" style="width:150px">
                <apex:selectOptions value="{!StageList}" />             
            </apex:selectList>
        </td>        
    </tr>
</table>

{!SelectedRType}

</apex:form>

</apex:page>

 
Hi,

I have written test class for below VF page, but iam getting only 59% of code coverage, Please help me to make it to 100% .

<apex:page controller="SearchClass" >
<apex:form >
<apex:pageBlock >
<apex:pagemessages />
{!errormessage }
<apex:pageBlockSection title="Search Criteria"  collapsible="false">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Name:"/>
<apex:inputText value="{!nameQuery}"/>

</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:CommandButton action="{!executeSearch}" value="Search"  />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockTable value="{!tableList}" var="p" rendered="{!isTableExit}" >
<apex:column >
<apex:outputLink target="_blank" value="/{!p.id}">{!p.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!p.Parent_Name__c}"/>
<apex:column value="{!p.Gender__c}"/>
<apex:column value="{!p.Marital_Status__c}"/>
<apex:column value="{!p.Phone__c}"/>
<apex:column value="{!p.Email__c}"/>
</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
</apex:page>

Class:
public with sharing class SearchClass {

public string nameQuery{get;set;}
public List<object__c> tableList{get;set;}
public Boolean isTableExit {get;set;}
public string errormessage {get;set;}

public List<object__c> plist=new List<object__c>([Select id, name From object__c]);

public PageReference executeSearch(){
string queryStr='%'+nameQuery+'%';
if(nameQuery==null || nameQuery==''){
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter Name'));
}else{
tableList=[Select id,name,Phone__c,Email__c,parent_Name__c,Gender__c,Marital_Status__c From object__c where name=:nameQuery];

}
isTableExit =true;
return null;
}

public SearchClass(){
string urlQuery=ApexPages.currentPage().getParameters().get('query');
if ( (null!=urlQuery) && (0!=urlQuery.length()) )
  {
   nameQuery=urlQuery;
   executeSearch();
  }
 
 isTableExit=false;
}
}

Test Class:

@isTest
public class SampleSearch{

static TestMethod void testSampleSearch(){
PageReference pageRef = Page.SampleSearch;
Test.setCurrentPageReference(pageRef);
SearchClass myclass=new SearchClass();
object__c pobj=new object__c ();
pobj.name='test';

myclass.executeSearch();

pobj.name='test1';
myclass.executeSearch();
}
}


Thanks in advance
Sain
  • August 24, 2015
  • Like
  • 0
Hi,

Iam trying to get populate field values into popup page while cliking on formula field on custom detail page.  

getting error: Id value is not valid for the Visitor__c standard controller

and also values not populating popup fields.

VF Page:

<apex:page standardController="Visitor__c" sidebar="false" extensions="CustomVisitorDetailExt" >
<script>
 var newWin=null;
 
 function openLookupPopup(mid)
 {
  var url="/apex/PopUpforVisitor?id=" +mid;
  <!--var url="/apex/PopUpforVisitor";-->
  newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
  if (window.focus) 
  {
   newWin.focus();
  }
    
     return false;
    }
       
 function closeLookupPopup()
 {
    if (null!=newWin)
    {
       newWin.close();
    }  
 }
</script>
<apex:form >
<apex:actionFunction name="VisitorAddress" action="{!VisitorAddress}" rerender="accinfo, msgs" >
<apex:param name="recordId" value="" assignTo="{!recordId}"/>
</apex:actionfunction>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection Title="Visitor Details:" collapsible="false" id="accinfo">
<apex:outputField value="{!Visitor__c.name}"/>
<apex:outputField value="{!Visitor__c.Gender__c}"/>
<apex:outputField value="{!Visitor__c.Email__c}"/>
<apex:outputField value="{!Visitor__c.Phone__c}"/>
<apex:outputField value="{!Visitor__c.Patient__c}"/>
<apex:outputField value="{!Visitor__c.Relashionship__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection Title="Address Information:" collapsible="false">

<apex:inputField value="{!Visitor__c.Current_Address__c}" onclick="openLookupPopup('{!$Component.targetName}', '{!$Component.targetId}');"/>
<!--<apex:inputField value="{!Visitor__c.Current_Address__c}" onclick="openLookupPopup('{!myd}');return false;"/>-->
 
  <!--<apex:outputText value="{!Visitor__c.Current_Address__c}"  />
  <apex:outputlink onclick="window.showModalDialog('\apex\PopUpforVisitor')" target="_blank"  value="/{Visitor__c.id}" > {!Visitor__c.Current_Address__c}
   <apex:actionSupport event="onClick" action="{!VisitorAddress}" reRender="result,mypage" status="status"/>
  </apex:outputlink>-->
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Popup VF Page:

<apex:page standardController="Visitor__c" sidebar="false" showHeader="false" extensions="CustomVisitorDetailExt">
<apex:form >
<apex:pageBlock >

<apex:pageBlockSection Title="Address Information:" collapsible="false" columns="1">
  <!--<apex:repeat value="{!$ObjectType.Visitor__c.fieldsets.Address}" var="fValue">
                 <apex:outputfield value="{!Visitor__c[fValue]}"/>
             </apex:repeat>-->
<apex:inputField value="{!Vist.Address_Line1__c}"/>  
<apex:inputField value="{!vist.Address_Line2__c}"/>  
<apex:inputField value="{!vist.City__c}"/>  
<apex:inputField value="{!vist.State__c}"/>  
<apex:outputField value="{!vist.PinCode__c}"/>  
<apex:inputField value="{!vist.Land_Mark__c }"/>  
 
          
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Class:

public with sharing class CustomVisitorDetailExt {
public visitor__c vist {get;set;}
public id recordId {get;set;}
public id myd {get;set;}

public ApexPages.StandardController standardCon;
    public CustomVisitorDetailExt(ApexPages.StandardController con) {
    standardCon=con;
    vist =new visitor__c();
  myd=apexpages.currentpage().getparameters().get('recordId');
System.debug('>>>>urlid' +myd);
    }
public PageReference VisitorAddress(){
PageReference page=new PageReference('/apex/PopUpforVisitor?id=' +myd);

 //visitor__c vis= (visitor__c) standardCon.getRecord();
    vist= [select Address_Line1__c,Address_Line2__c,City__c,PinCode__c,State__c,Land_Mark__c from visitor__c where id =: myd ];
    //vist.Address_Line1__c=vis.Address_Line1__c;
    //vist.Address_Line2__c=vis.Address_Line2__c;
    //vist.Address_Line1__c=apexpages.currentpage().getparameters().get('vis.Address_Line1__c');
    //vist.Address_Line2__c=apexpages.currentpage().getparameters().get('vis.Address_Line2__c');
return page;
}
}

Please help me to solve this issue.

Regards,
Sain
  • August 12, 2015
  • Like
  • 0
Hi,

Please any one can explain me about apex:repeat component in salesforce? where we can use?

regards,
Sain
  • August 11, 2015
  • Like
  • 0
Hi,
I have custom object called patient and fields name, email__c, gender__c, Doctor__c(lookup field).
I have to develop a dynamic search page to fetch the related data and display in a table based on values given in input fields called name, email__c, Doctor__c.  but iam facing problem with fetching data based on search.

please help me to solve this issue.

<apex:page controller="DynamicSearchPatientClass" sidebar="false">
<script type="text/javascript">

      function doSearch() {

        searchServer(
          document.getElementById("Name").value,
          document.getElementById("Gender").value,
          document.getElementById("Email").value,
          document.getElementById("Doctor").value);
      }
      </script>

<apex:form >

<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,result2,errors">
          <apex:param name="Name" value="" />
          <apex:param name="Gender" value="" />
          <apex:param name="Email" value="" />
          <apex:param name="Doctor" value="" />
</apex:actionFunction>

<apex:pageBlock >
<apex:pageBlockSection title="Patient Search" collapsible="false" columns="2" >
Patient Name<apex:inputText value="{!patients.Name}" id="Name" onkeyup="doSearch();"/>
Gender<apex:inputText value="{!patients.Gender__c}" id="Gender" onchange="doSearch();"/>
Email<apex:inputText value="{!patients.Email__c}" id="Email" onkeyup="doSearch();"/>
Doctor Name<apex:inputText value="{!patients.Doctor__c }" id="Doctor" onchange="doSearch();"/>
</apex:pageBlockSection>

<apex:pageBlockSection title="Patient Details" id="result" >
<apex:pageBlockTable value="{!patients}" var="p" id="result2">
<apex:column value="{!p.Name}"/>
<apex:column value="{!p.Gender__c}"/>
<apex:column value="{!p.Email__c}"/>
<apex:column value="{!p.Doctor__c }"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Class:
public with sharing class DynamicSearchPatientClass {

Private string soql {get;set;}
public Patient__c patients {get;set;}

public String sortDir{
      get { if (sortDir == null) { sortDir = 'asc'; }
                   return sortDir;}
      set;}

public String sortField {
          get {if  ( sortField == null) {
                  sortField = 'Name'; } return sortField; }
          set;}

public void runQuery() {
              try {
                   patients= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20 ');
                   system.debug('>>>>>>4' +patients);
                    }
                    catch (Exception e) {
                     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' OOOps! ') );
                     }
     }    

public DynamicSearchPatientClass(){
 soql='select name,Email__c,Gender__c,Doctor__c from patient__c where patient__c.Name != null';
 system.debug('>>>>>>' +soql);
runQuery();

}

public PageReference runSearch(){
    String Name = Apexpages.currentPage().getParameters().get('Name');
    String Gender = Apexpages.currentPage().getParameters().get('Gender');
    String Email = Apexpages.currentPage().getParameters().get('Email');
    String Doctor= Apexpages.currentPage().getParameters().get('Doctor');

    soql='select name,Email__c,Gender__c,Doctor__c from patient__c where patient__c.Name != null';   
system.debug('>>>>>>3' +soql);
    if (!Name.equals(''))
      soql += ' and Name LIKE \' '+String.escapeSingleQuotes(Name)+'%\'';
   system.debug('>>>>>>1' +soql);
    if (!Email.equals(''))
      soql += ' and Email__c LIKE \''+String.escapeSingleQuotes(Email)+'%\'';
     if (!Gender.equals(''))
     system.debug('>>>>>>2' +soql);
      soql += ' and Gender__c LIKE \''+String.escapeSingleQuotes(Gender)+'%\'';
    if (!Doctor.equals(''))
      soql += ' and Doctor__c LIKE \''+String.escapeSingleQuotes(Doctor)+'%\'';

    runQuery();

return null;

}
}


Regards,
Sain
 
  • August 10, 2015
  • Like
  • 0
Hi,

I have two objects called object1, object2(Master) and having lookup relationship among them, In object1 having a field called test1 and in Object2 having fields test2(piclist values are A,B), test3(picklist values x,y).
Now i am creating a validation rule on object1 to make test1 field mandatory while test2 is 'A' and test3 is 'x'

AND(ISPICKVAL(object1__r.test2__c='A'),ISPICKVAL(object2__r.test3__c='x') )

Getting below error:

 Field test2__c is a picklist field. Picklist fields are only supported in certain functions.

and also changed my expression with TEXT but still i am not able to sove it.
AND(TEXT(ISPICKVAL(object1__r.test2__c='A'))


Any suggestions from community.

Thanks in advance.



  • May 07, 2015
  • Like
  • 0
Hi,
I have two objects doctor, appointment and there is a lookup relationship between them.  have a fields called appointment_date__c(date/time type) and doctor__c lookup field in Appointment.
Now i have to delete the Appointment records those are Schedule is 'Confirm'(Doctor object field) and current time is 30m before from appointment_date__c field time.

for suppose 5 records appointment time is 6:30PM and current time is 6:00PM, this 5 records have to fetch and delete.

My Batch Class:

Global class AppointmentDelete implements database.Batchable<sObject>{
    global database.QueryLocator start(database.BatchableContext BC){
    string c='Confirm';
    String query='Select id,Name, doctor__r.name from Appointment__C where doctor__r.Schedule__c =\'' + c + '\'';
    system.debug('>>>>>>>query: '+query);
    return database.getQueryLocator(query);
    }
    
    global Void execute(database.BatchableContext BC, List<Appointment__C> scope ){
            
        delete scope;
       
    }
    
    global void finish(database.BatchableContext BC){
        
    }
}

 
  • April 19, 2015
  • Like
  • 0
Hi,

Iam getting error like: Illegal assignment from String to Boolean

isActive is CheckBox type custome field, while creating record it self we check isActive field to true, now i want to unCheck(false).


Global class unCheckisActive implements database.Batchable<sObject>{
    global database.QueryLocator start(database.BatchableContext BC){
    String query='Select id,isActive__c,LastModifiedDate From object__c Where LastModifiedDate >Last_N_Years:1';
    return database.getQueryLocator(query);
    }
    
    global Void execute(database.BatchableContext BC, List<object__c> scope ){
        List<object__c> objectToUpdate=new List<object__c>();
        for(object__c obj:scope){
            obj.isActive__c='False'; // Illegal assignment from String to Boolean
            objectToUpdate.add(obj);
        }
        update objectToUpdate;
    }
    
    global void finish(database.BatchableContext BC){
        
    }
}

Kindly suggest me how to rectify this error.

Thanks in advance!!!
  • January 20, 2015
  • Like
  • 0
Hi,

I have a two Picklist A and B, if i select any value in picklist A, it should has to be make Picklist B Mandatory(Required to select  a value in Picklist B).

Please share, Does anyone has some sample code or can point me in the right direction?
Many thanks!!!
  • December 02, 2014
  • Like
  • 0

Hi,

My requirement is if i select any picklist value in custome field it has to popup related value on another Picklist field.

Let me explaine in detail, i have two Picklists A and B, If i Selected any value in Picklist A it should has to be update related picklist value in B.

Please share, Does anyone has some sample code or can point me in the right direction?
Many thanks!!!
  • December 02, 2014
  • Like
  • 0
Hi All,

I have a two objects like doctor(parent) and patient(child), my scenario is i have to count a child records on parent object by using trigger.

(using rollup summary we can achieve this but i have to achieve with trigger)

please any one help me with code for this scenario.

Thanks in advance!!!
  • September 15, 2014
  • Like
  • 0
Hi,

My requirement is if i select any picklist value in custome field it has to popup related value on another customer field.

Let me explaine in detail, i have two fields like medical procedure(picklist) and price field.  If i select any picklist value in medical procedure it has to be popup price field with related value.

Please SHARE, Does anyone has some sample code or can point me in the right direction?
Many thanks!!!
  • August 29, 2014
  • Like
  • 0
Hi,

My requirement is if i select any picklist value in custome field it has to popup related value on another customer field.

Let me explaine in detail, i have two fields like medical procedure(picklist) and price field.  If i select any picklist value in medical procedure it has to be popup price field with related value.

Please share, Does anyone has some sample code or can point me in the right direction?
Many thanks!!!
  • August 29, 2014
  • Like
  • 0