New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Showing posts with label visualforce. Show all posts
Showing posts with label visualforce. Show all posts

Monday, 15 April 2013

Change Case Owner VF Page


<apex:page tabStyle="Case" standardController="Case" extensions="ChangeOwner">
<apex:form >
<apex:sectionHeader title="Change Case Owner"/>
<p>This screen allows you to transfer cases from one user or queue to another. When you transfer ownership, the new owner will own:</p>
<ul><li>all open activities (tasks and events) for this case that are assigned to the current owner</li></ul>
<p>Note that completed activities will not be transferred. Open activities will not be transferred when assigning this case to a queue.</p>
<apex:pageBlock mode="Edit">
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>
<br/><apex:pageBlockSection title="Select New Owner" collapsible="false" columns="3">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Owner"></apex:outputLabel>
<apex:inputField value="{!Case.ownerId}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>


public class ChangeOwner {
   
    public ChangeOwner(ApexPages.StandardController controller) {

    }

}

Monday, 1 October 2012

Changing hyperlink from one color to another color



<script type="text/javascript"> 
  function turnRed(id) { 
  alert("hi"); 
  var myPara = document.getElementById(id); 
  alert(myPara); 
  myPara.style.color = "green"; 
  } 
  </script> 
  <apex:commandLink action="{!gogoogle}" target="_blank" value="Go Google" id="check" style="color:red" onclick="turnRed('{!$Component.check}')"/>

Sunday, 30 September 2012

custom login page

Refer:
http://boards.developerforce.com/t5/Visualforce-Development/custom-login-page/m-p/501739

Saturday, 29 September 2012

Div and Span html tags difference

Div: We can define a section and apply CSS Styles.
Span: We can define an element or area of a section and we can apply CSS Styles.
Refer:
http://www.slideshare.net/biswadip/span-and-div-tags-in-html
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_span

Friday, 28 September 2012

CSS for changing the color of a hyper link


<apex:page sidebar="false" standardController="Sample__c">
    <head>
    <style type="text/css">
    a:link {
    COLOR: #FF0000;
    }
    a:visited {
    COLOR: #008000;
    }
    a:hover {
    COLOR: #FF0000;
    }
    a:active {
    COLOR: #00FF00;
    }
</style> 
    </head>
    <apex:form >
        <!-- Designing Sidebar -->
        <table>
         <tr>
          <th width="200" valign="top">
        <apex:outputPanel >
            <apex:pageblock title="Sidebar">
                <apex:pageblockSection columns="1">
                    <apex:commandlink value="One"/>
                    <apex:commandlink value="Two"/>
                </apex:pageblockSection>
            </apex:pageblock>
        </apex:outputPanel>
        <!-- All pages comes here -->
         </th>
         <th>
        <apex:outputPanel >
            <apex:pageblock title="One">    
                <apex:pageblockSection >
                    <apex:inputField value="{!Sample__c.name}"/>
                    <apex:inputField value="{!Sample__c.City__c}"/> 
                </apex:pageblockSection>
            </apex:pageblock>
            <apex:pageblock title="Two"> 
                <apex:pageblockSection >
                    <apex:inputField value="{!Sample__c.Mobile__c}"/>
                    <apex:inputField value="{!Sample__c.Salary__c}"/> 
                </apex:pageblockSection>
            </apex:pageblock>
        </apex:outputPanel>
          </th>
         </tr>
        </table> 
    </apex:form>
</apex:page>

<apex:page sidebar="false" standardController="Sample__c" Extensions="sample">
<body text="#507070" link="#900000" alink="#D06000" vlink="#C08000" bgcolor="#FFD078">
    <apex:form >
        <!-- Designing Sidebar -->
        <table>
         <tr>
          <th width="200" valign="top">
        <apex:outputPanel >
            <apex:pageblock id="Sidebar">
                <apex:pageblockSection columns="1" title="Sidebar" collapsible="false">
                    <apex:commandlink value="One" action="{!pageOne}" style="color: #CC0000"/>
                    <apex:commandlink value="Two" action="{!pageTwo}"/>
                </apex:pageblockSection>
            </apex:pageblock>
        </apex:outputPanel>
        <!-- All pages comes here -->
         </th>
         <th>
        <apex:outputPanel >
            <apex:pageblock title="One" rendered="{!page1}">    
                <apex:pageblockSection >
                    <apex:inputField value="{!Sample__c.name}"/>
                    <apex:inputField value="{!Sample__c.City__c}"/> 
                </apex:pageblockSection>
            </apex:pageblock>
            <apex:pageblock title="Two" rendered="{!page2}"> 
                <apex:pageblockSection >
                    <apex:inputField value="{!Sample__c.Mobile__c}"/>
                    <apex:inputField value="{!Sample__c.Salary__c}"/> 
                </apex:pageblockSection>
            </apex:pageblock>
        </apex:outputPanel>
          </th>
         </tr>
        </table> 
    </apex:form>
    </body>
</apex:page>

Refer:
http://www.goldcoastwebdesigns.com/change-hyperlink-color.shtml

Friday, 24 August 2012

Review Points

* We can only use runAs {System.runas()} in a test method. It is not possible to use it in Apex Classes.
* Developer Console by default works in User Mode. 
* For before mode in case of update for an event (if the update is for the same object on which we are writing the trigger) no need to use 'UPDATE' DML Statement.
* Data Loader time zone and sandbox or production time zone should be same while working with date fields. 
 * If we convert the lead record then that lead record won't exists in lead object but when running the reports it will display the converted leads.







Please see the below Comments

Friday, 17 August 2012

apex:component

How to disply custom client-side error messages on VF pge

Custom Error Messages on VF page

How to dipaly client side error messages like above?
Solution:
 By using jquery you can diplay error messages as you mentioned in the above image
1. First download the jquery file here.
2. If it is not downloading copy the code and paste it in notepad and save it with jquery.js like that.
3. Then upload that file into static resources.
4. In your vf page use the following code
<apex:page standardcontroller="Account" showHeader="false" standardStylesheets="false">
    
    <apex:includeScript value="{!$Resource.jquery}"/>
    <apex:includeScript value="http://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.min.js"/>
    
    <script type="text/javascript"> 
        $(document).ready(function() {
             
            $('[id$=commentForm]').validate();             
             
            $('[id$=name]').rules("add",{
                required: true,
                minlength: 5
            });     
            
            $('[id$=email]').rules("add",{
                required: true,
                email: true
            });      
            
            $('[id$=url]').rules("add",{
                url: true
            });
            
            $('[id$=comment]').rules("add",{
                required: true
            });
            
            $('[id$=pwd]').rules("add",{
                required: true,
                minlength: 5
            });
            
            $('[id$=cpwd]').rules("add",{
                required: true,
                minlength: 5,
                equalTo: '[id$=pwd]'
            });      
            
            /* Customised the messages */
            jQuery.validator.messages.required = "You better have entered a value.. or else!"; 
            jQuery.validator.messages.equalTo = "No silly, you're supposed to type the same set of characters AGAIN.";                                                
        });
        
    </script>   
    
    <!-- Ignore my template -->
    <apex:composition template="Template">
        <apex:define name="title">
            <a href="http://thesilverlining-developer-edition.na7.force.com/jqueryvalidatedemo/">jQuery Forms Validation Demo</a>
        </apex:define>
        
        <apex:define name="blurb">
            <p>
                Fiddle with the form entering combinations of correct and incorrect values to see the validation rules in action. Hitting the sumbit button will also trigger form checking.
            </p>
        </apex:define>


        <apex:define name="content">    
            <apex:outputPanel layout="block" style="text-align:center; font-size:12px;padding: 4px">
                <apex:form id="commentForm" > 

                        <apex:outputlabel for="name">Name <span class="star">*</span></apex:outputlabel> 
                        <apex:inputtext id="name" value="{!account.name}"/>
                        <br/>
                        <apex:outputlabel for="email">E-Mail <span class="star">*</span></apex:outputlabel> 
                        <apex:inputtext id="email"  value="{!account.name}"/> 
                        <br/>
                        <apex:outputlabel for="url">URL (optional)</apex:outputlabel> 
                        <apex:inputtext id="url"  value="{!account.name}" /> 
                        <br/>
                        <apex:outputlabel for="comment">Your comment <span class="star">*</span></apex:outputlabel> 
                        <apex:inputtextarea id="comment" value="{!account.name}" style="width: 30%"/>
                        <br/>
                        <apex:outputLabel for="pwd">Password <span class="star">*</span></apex:outputLabel>
                        <apex:inputSecret id="pwd" value="{!account.name}"/>
                        <br/>
                        <apex:outputLabel for="cpwd">Confirm Password <span class="star">*</span></apex:outputLabel>
                        <apex:inputSecret id="cpwd" value="{!account.name}"/>                        
                        <br/>
                        <input type="submit" />
            
                </apex:form>
            
            </apex:outputPanel>
            
        </apex:define>
        
    </apex:composition>
     
</apex:page>
5. make changes according to your vfpage.
6. Then you will get the desired output
Refer Here:
 http://th3silverlining.com/2010/03/02/visualforce-form-validation-enhanced/#more-543

Thursday, 16 August 2012

VisulaForceError-System.QueryException: List has no rows for assignment to SObject

This error usually occurs when you are not passing an id in the URL

Question:
System.QueryException: List has no rows for assignment to SObject Class.practiseOneController.getAccount: line 5, column 1
VF Page:
<apex:page controller="practiseOneController" tabStyle="Account">
<apex:pageBlock title="Hello {!$User.FirstName}!!!">
You belong to {!account.name} Account.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:dataTable value="{!account.contacts}" var="contacts" cellpadding="4" border="1">
<apex:column value="{!contacts.FirstName}" headerValue="FirstName"/>
<apex:column value="{!contacts.LastName}" headerValue="LastName"/>
</apex:dataTable>
</apex:pageBlock> 
</apex:page>
Apex Class:
public class practiseOneController
 {
    public Account getAccount()
    {
        return [select id,Name,(select id,firstname,lastname from Contacts limit 5) from Account where id=
                 :System.currentPageReference().getParameters().get

('id')]; } } 
 Solution:
Use following code for Apex Class

public class practiseOneController
 {
    public Account getAccount()
    {
        Account[] acc = [select id,Name,(select id,firstname,lastname from Contacts limit 5) from Account where id=:System.currentPageReference().getParameters().

get('id')]; if(acc.size() > 0) { return acc[0]; } else { return null } } } 
Refer:
System.QueryException

Sunday, 12 August 2012

To disable other checkboxes in a section if one is selected.

To disable other checkboxes in a section if one is selected.
<apex:page>
<apex:form>
<script>
function confirmDisbaled(ifchecked, id1 ,id2,id3) {


document.getElementById(id1).disabled = ifchecked;
document.getElementById(id2).disabled = ifchecked;
document.getElementById(id3).disabled = ifchecked;


}
</script>
<apex:pageBlock>
<apex:actionRegion >
<apex:outputPanel id="panel1">
<apex:pageBlockSection title="PST" id="PST">
<apex:inputCheckbox label="Global" id="gbl" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.cntry}');"/>

<apex:inputCheckbox label="Local" id="lcl" onchange="return confirmDisbaled(this.checked, '{!$Component.gbl}','{!$Component.cntry}');"/>

<apex:inputCheckbox label="Country" id="cntry" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.gbl}');"/>

</apex:pageBlockSection>
</apex:outputPanel>
</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>

Saturday, 11 August 2012

How to show visual force error?

<apex:page standardController="Account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Student Info">
<apex:inputField value="{!Account.Name}"/>
<apex:inputField value="{!Account.AccountNumber}" required="True"/>
<apex:inputField value="{!Account.AnnualRevenue}" required="True"/>
<apex:inputField value="{!Account.Description}" required="True"/>
<apex:inputField value="{!Account.Site}" required="True"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>

Javascript with Visualforce pages

Displaying pop-up summaries on hover in visualforce

VF:
<apex:page controller="PopupTest19">  
    <apex:form >  
        <apex:repeat value="{!accounts}" var="acc">                              
                
      <a href="{!acc.Id}" id="{!acc.Id}" onblur="LookupHoverDetail.getHover('{!acc.Id}').hide();" onfocus="LookupHoverDetail.getHover('{!acc.Id}', '/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1').show();" onmouseout="LookupHoverDetail.getHover('{!acc.Id}').hide();" onmouseover="LookupHoverDetail.getHover('{!acc.Id}', '/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1').show();">{!acc.Name}</a><br/> 
        </apex:repeat>  
    </apex:form>  
    </apex:page>
APEX:
public with sharing class PopupTest19 { 
List<Schema.account> accounttList = new List<Schema.account>();     
    public List<Schema.account> getAccounts()      {  
        
        accounttList = [Select Id, Name from Account LIMIT 10];  
        return accounttList ;  
    }  
  
}
//List<Schema.account> if apex class has same name as standard object to avoid that confusion we have to use Schema before standard Object name otherwise an error will occur 'Illegal assignment from LIST<Account> to LIST<Account>'
Refer:
Displaying pop-up summaries on hover in visualforce

Illegal assignment from LIST to LIST

* If there is any apex class with the same name of the standard or global sObjects while creating List, map,set the above error will reflect.
*We can solve this problem in two ways:
1. We have to rename our Apex Class to some other name.
2. Use 'Schema' before sObject while creating List, Set, Map (Don't use 'schema' before sObject in SOQL Query)
- List<Schema.Account> aclist = new List<Schema.Account>();
- return type should be also like List<Schema.Account>
-Click here to see the example here!

Refer:
 Illegal assignment from LIST<Account> to LIST<Account>

Friday, 10 August 2012

How to pull values of records modified 7 days ago?

Question:
I want to create a list of sObjects that were modified 7 days ago.

I am using code similar to this, but when I get to the SOQL query it appears that something is not quite working.
Date myDate = date.today()-7;
List<Recruitment_Cycle__c> RCs = [Select ID, Name, LastModifiedDate from Recruitment_Cycle__c where LastModifiedDate =: myDate ]; 
 In this case I am getting 0 rows, however there are a number of records that I would expect to meet the criteria when looking at the data. I suspect something is wrong with my comparison etc...

When I check the debug for myDate it is assigning what looks like the proper date.

Solution: 
One thing is that you should use date.today().addDays(-7)

And also you are using exact match "=" sign. And LastModifiedDate field also contains time, whereas you are just using today function which will return you Date part. So i do not think there will be a match. Please verify if you need Date or Date and Time. I would think you want that day. So you may have to use something like this:

Date myDateStart = date.today().addDays(-7);
Date myDateEnd = date.today().addDays(-6);
List<Recruitment_Cycle__c>
 RCs = [Select ID, Name, LastModifiedDate from Recruitment_Cycle__c 
where LastModifiedDate >=: myDateStart AND LastModifiedDate <=: 
myDateEnd];

Field sets

*Field set is nothing but set of fields like(First Name, Last Name, Username).
*If we use field sets on VF page without modifying VF code Admin can rearrange, delete, add fields to the field set.
*We can use field set on VF page using $ObjectType global variable.

<apex:page standardController="Contact">

<apex:repeat value="{!$ObjectType.Contact.Fieldsets.propernames}" var="f">

<apex:outputText value="{!Contact[f]}"/>

</apex:repeat>

</apex:page>

Thursday, 9 August 2012

Dynamic Visualforce Naming

Question:
I've been doing some work creating content in Visualforce that is rendered/opened in different formats (PDF, csv, excel etc). The few ways I have found to force rendering or download of the Visualforce page onload is to renderAs="PDF" or setting contenttype="text/csv" etc. The issue is during the load of the page, the page itself is saved using the naming convention of the Visualforce page, meaning you cannot specify the necessary extension. 

I was wondering if anyone had a workaround or any ideas to force the save of the page to a dynamic name and specify a file extension (for instance force a Visualforce page named Report with contenttype="application/csv" save as {dynamicname}.csv). 

My temporary work-around is having the file emailed as an attachment, as you can specify name of attachment and file extension dynamically in Visualforce templates. I would prefer the option to directly download rather then use this work-around. Anyone have any ideas?

Solution:
contentType="text/csv#{!dynamicname).csv"

Wednesday, 8 August 2012

How to disable inputfield at particular day?

VF and APEX Code:
<apex:page controller="disable">
    <apex:form >
    <apex:pageblock title="Input Form">
        <apex:pageBlockSection columns="3">
            <apex:pageBlockSection title="Hyderabd">
                <apex:inputtext disabled="{!lock}"/>                
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Banglore"></apex:pageBlockSection>
            <apex:pageBlockSection title="Chennai"></apex:pageBlockSection>
        </apex:pageBlockSection>
    </apex:pageblock>
    </apex:form>
 
</apex:page>
public class disable {

    public boolean getLock() {
        if(date.today() == date.valueOf('2012-08-08')) {
            return True;
         }
        else {
            return False;
        }
    }
}
Date Method to get day of the week
 In Developer Console:
Datetime dt = DateTime.newInstance(Date.today(), Time.newInstance(0, 0, 0, 0));
String dayOfWeek=dt.format('EEEE');
System.debug('Day : ' + dayOfWeek);
Output:
09:39:41.034|USER_DEBUG|[3]|DEBUG|Day : Tuesday


Based on picklist selection, how to display corresponding pageblock on VF page

VF and APEX Code:
<apex:page controller="display">
    <apex:form >
      <!--<apex:actionFunction action="{!selectcountry}" name="fun"/>
      <apex:selectList size="1" value="{!country}" onchange="fun();">-->
      <apex:selectList size="1" value="{!country}">
      <apex:actionSupport event="onchange" action="{!selectcountry}"/>          <apex:selectOptions value="{!picklistvalues}">
          </apex:selectOptions>
      </apex:selectList>
      <apex:pageBlock >
       <!--renderd to display or hide the pageblocksection on any other element of VF page-->
       <apex:pageBlockSection title="India" rendered="{!Ind}">
           <b>India is a developing country</b>
       </apex:pageBlockSection>
       <apex:pageBlockSection title="Australia" rendered="{!Aus}">
           <b>Australia is a continent</b>
       </apex:pageBlockSection>
       <apex:pageBlockSection title="USA" rendered="{!Usa}">
           <b>USA is a developed country</b>
       </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>      
</apex:page>
public class display { 
    
    //To store the picklist value which we have selected on VF page i.e (Ind, Aus, USA)
    public String country { get; set; }    
    
    //To display list of picklist values on VF page
    public List<selectOption> getPicklistvalues() {
        List<selectOption> options = new List<selectOption>();       
        options.add(new selectOption('India','India'));
        options.add(new selectOption('Australia','Australia'));
        options.add(new selectOption('USA','USA'));
        return options;
    }   

    //To make three pageblocksections invisible by default
    public Boolean indtf = false;
    public Boolean austf = false;
    public Boolean usatf = false;
       
    //To dynamically pass Boolean values to rendered attribute on pageblocksection
    public void setInd(Boolean b) {
        this.indtf = b;
    }
    public Boolean getInd() {
        return this.indtf;
    }    
    
    
    public void setAus(Boolean b) {
        this.austf = b;
    }
    public Boolean getAus() {
        return this.austf;
    }

    
    public void setUsa(Boolean b) {
        this.usatf = b;
    }
    public Boolean getUsa() {
        return this.usatf;
    }
 
    //Constructor, After loading the page to display india pageblocksection by default
    public display() {
        setInd(True);
        setAus(False);
        setUsa(False);
    }
    
    //After changing picklist value based on the selection to display either usa or aus pageblocksection
    //Through actionfunction or actionsupport this method will be called to VF page
    public PageReference selectcountry() {
        if(country == 'Australia') {
            setInd(False);
            setAus(True);
            setUsa(False);
        }
        else {
            setInd(False);
            setAus(False);
            setUsa(True);
        }
        return null;
    }
} 

Tuesday, 7 August 2012

How to give the Pagereference for the Save & New ?

Question:
When I am clicking Save & New the record is inserting and giving the same page but the problem is it is giving the same values which has been entered on the before page.

Solution:

PageReference pr=Page.MyPage;
pr.setRedirect(true);

return pr;
   

Labels