ads

Thursday, 28 July 2016

Parameter Passing Between Two Visualforce Page Using URL





Controller Code of First VF Page: -



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
public class gettingURLid
{
public Account Accinsert{get;set;}
public pagereference save()
    {
        insert accinsert;
       
        Pagereference page=new Pagereference('/apex/refpage?id='+accinsert.id);
        Page.setredirect(true);
        return page;
    }

public gettingURLid()
{
Accinsert=new account();
}
}

Code For First VF Page :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<apex:page controller="gettingURLid">
<apex:form >
<apex:pageBlock >

<apex:pageBlockButtons >
  <apex:commandButton action="{!save}" value="Save"/>
 </apex:pageBlockButtons>
 
<apex:pageblockSection >


<apex:inputField value="{!accinsert.name}"/>
<apex:inputField value="{!accinsert.type}"/>
<apex:inputField value="{!accinsert.phone}"/>



</apex:pageblockSection>
</apex:pageBlock>

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

OutPut Screen  For First VF Page:-




Controller Code of Second VF Page: -



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
public class refpage
{

//public string posId;
public account acc_var{get;set;}

public refpage()
    {
     string postId;
        postId=apexpages.currentpage().getparameters().get('id');
       
      
        acc_var= [select name, type from account where id= :postID];
        
        
    }


}


Code For Second VF Page :-



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<apex:page controller="refpage">
<apex:form >
<apex:pageBlock >

<apex:pageblockSection >

Hello customer <br></br>Your Account name is:-  <h1>{!acc_var.name} </h1>
<br></br>
Type :- <h1>{!acc_var.type}</h1>


</apex:pageblockSection>
</apex:pageBlock>

</apex:form>

</apex:page>


OutPut Screen  For Second VF Page:-


Redirect From One Visulforce Page to Another



Controller Code For First VF Page  :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class insertRecords{

public account accinsert{get; set;}

public insertRecords()
    {

    accinsert=new account();

    }

    public pagereference save()
    {
        insert accinsert;
        accinsert =new account();
        Pagereference page=new Pagereference('/apex/savemsg');
        Page.setredirect(true);
        return page;
    }
    

}

Visualforce Page Code For First VF Page :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<apex:page controller="insertRecords">
<apex:form >
  <apex:pageBlock >
  <apex:pageBlockButtons >
  <apex:commandButton action="{!save}" value="Save"/>
  </apex:pageBlockButtons>
   <apex:pageBlockSection >
  <apex:inputField value="{!accinsert.name}"/>
   <apex:inputField value="{!accinsert.phone}"/>
    <apex:inputField value="{!accinsert.type}"/>
   </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

OutPut Screen For First VF Page :-






Visualforce Page Code For Second VF Page :-



1
2
3
4
5
<apex:page >
<apex:pageBlock >
 Your record is saved...
 </apex:pageBlock>
</apex:page>



OutPut Screen For Second VF Page :-


Insert Record And Redirect To Detail Page



Controller Code :-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public class TransferIDtoNextPage
{
public Account Accinsert{get;set;}

 public pagereference save()
    {
        insert accinsert;
        
        Pagereference page=new Pagereference('/'+accinsert.id);
        Page.setredirect(true);
        return page;
    }

public TransferIDtoNextPage()
    {
    Accinsert=new account();
    
    
    }

}

Visualforce Page Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<apex:page controller="TransferIDtoNextPage">
<apex:form >
<apex:pageBlock >

<apex:pageBlockButtons >
  <apex:commandButton action="{!save}" value="Save"/>
 </apex:pageBlockButtons>
 
<apex:pageblockSection >


<apex:inputField value="{!accinsert.name}"/>
<apex:inputField value="{!accinsert.type}"/>
<apex:inputField value="{!accinsert.phone}"/>



</apex:pageblockSection>


</apex:pageBlock>

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

Output Screen :-

    1st Screen :- VF Page To Fill Value


    2nd Screen :- Detail Page Of Recently Inserted Record.




How To Show Total No Of Reords in PageBlockTable





Controller Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
public class TotalContacts
{
 public String obj;
    public List<Contact> ContactList{get;set;}
    
    public TotalContacts() 
    {    
        ContactList= [SELECT ID, Name,lastname,email FROM Contact order by createddate limit 10];
    }   

}

Visualforce Page Code:-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<apex:page controller="TotalContacts">

<apex:pageblock Title="List of Contacts">
      
         <apex:pageBlock >
        <apex:pageblockTable value="{!ContactList}" var="u">
            <apex:column headerValue="Contact Name">
                <apex:outputLink value="/{!u.id}">{!u.Name}</apex:outputLink>
            </apex:column>
            
            <apex:column headerValue="Contact Email">
                <apex:outputLink value="/{!u.id}">{!u.Email}</apex:outputLink>
            </apex:column>
        </apex:pageblockTable>
    </apex:pageblock>  

    </apex:pageBlock> 

</apex:page>

OutPut Screen :-



Wednesday, 27 July 2016

Insert Record and Clear Fields value After Save




Controller Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
public class outputPanelPage {
public contact con_insert{get;set;}

public string msg{get;set;}
public outputPanelPage()
{
 msg= 'Plz Enter the value...';
con_insert=new contact();


}

public void save()
{
  
   insert con_insert;
   con_insert=new contact();
   msg= 'Your Record is saved...';
}
}

VF Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<apex:page controller="outputPanelPage">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="SAVE" action="{!save}"/>

</apex:pageBlockButtons>

<apex:pageBlockSection columns="1">

<apex:inputField value="{!con_insert.lastname}"/>
<apex:inputField value="{!con_insert.AssistantName}"/>
<apex:inputField value="{!con_insert.Birthdate}"/>

</apex:pageBlockSection>


{!msg}


</apex:pageBlock>

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

Output Screen :-

             Screen 1 :- Before Save

           
         

              Screen 2 :- After Save











Use of ActionRegion,rerender,Param and Id






Controller Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class ActionReson3{


public List<opportunity> opplist{get;set;}
public opportunity opp_var{get;set;}
Public id Recid{get;set;}

public boolean ShowHide {get;set;}
    
    public ActionReson3() 
    {    
    ShowHide=False;
        opplist = [SELECT ID, Name,closedate FROM opportunity limit 5] ;
    }   
     
     public void getRecordID()
     {
     showHide= True;
       opp_var= [select name, accountid,closedate,ForecastCategoryName,Amount,leadsource from opportunity where id=:Recid ];
    
       
     }

    
}


Visualforce Page :-



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<apex:page controller="ActionReson3">
<apex:form >
<apex:pageblock Title="List of Opportunity">

<apex:pageblockTable value="{!opplist}" var="opp">
  <apex:column headerValue="Opportunity Name">
            
         <apex:actionregion >
        <apex:commandLink action="{!getRecordID}" value="{!opp.name}" rerender="pb" >
             <apex:param assignTo="{!Recid}" name="testuser" value="{!opp.id}"/>
             
         </apex:commandLink>
          </apex:actionregion>
          </apex:column>
         
           
            <apex:column headerValue="Close Date">
                <apex:outputLink value="/{!opp.id}" >{!opp.closedate}</apex:outputLink>
            </apex:column>
       
       
       
        </apex:pageblockTable>
        

    </apex:pageblock>
    
    
    <apex:pageBlock rendered="true" id="pb"  >
        <apex:pageBlockSection >
        <apex:outputField value="{!opp_var.name}"  />
        <apex:outputField value="{!opp_var.accountid}"/>
        <apex:outputField value="{!opp_var.closedate}"/>
        <apex:outputField value="{!opp_var.ForecastCategoryName}"/>
        <apex:outputField value="{!opp_var.Amount}"/>
        <apex:outputField value="{!opp_var.leadsource}"/>
        
</apex:pageBlockSection>
    
</apex:pageBlock>  


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



OutPut Screen :-

Use Of ActionRegion






Controller Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public class ActionRegionEXp
{
public String DepartmentStr{get;set;}
 public Contact conobj{get;set;}

 public ActionRegionEXp()
 {
  Conobj = new Contact();
 }
 public void FetchInfo()
 {
 
 
  if(DepartmentStr!=null && DepartmentStr!='')
  {
  
  
    List<Contact> ConLst = new List<Contact>();
    conLst = [select id,Department,title,email from Contact where Department=:DepartmentStr];
  
  
 
   if(conLst !=null && conLst.size()>0)
   {
     conobj= conLst[0];
     
     
    }
    else
    {
    Apexpages.Message message= new Apexpages.Message(ApexPages.Severity.Info,'No Record Found with this Department:' +DepartmentStr);
    ApexPages.addMessage (message);
    Conobj=Null;
    }
 
 }

}
}


Visualforce Page Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<apex:page controller="ActionRegionEXp">

<apex:pageMessages id="messgs"> </apex:pageMessages>
<apex:form >
<apex:pageBlock id="pageblock">

<table>
<apex:actionRegion >
<tr>
<td> <apex:outputLabel value="Enter Deparment">  </apex:outputLabel></td>

<td> <apex:inputText value="{!DepartmentStr}"/></td>
<td> <apex:commandbutton value="Get Info" action="{!Fetchinfo}" rerender="pageblock,messgs" /> </td>
</tr>

</apex:actionRegion>
<tr>
<td> <apex:outputLabel value="Contact Title"></apex:outputLabel> </td>
<td> <apex:inputField value="{!conobj.Title}"/> </td>
</tr>
 <tr>
     <td> <apex:outputLabel value="Contact Email"> </apex:outputLabel> </td>
      <td>  <apex:inputField value="{!conobj.Email}"/> </td>
     </tr>
</table>
</apex:pageBlock>

</apex:form>

</apex:page>


Output Screen :-



Update Existing Records Using List In Salesforce



Developer Console Code :-



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
      List<Account>  Acclist = [select id,website,name from Account];
      List<Account> Accupdate = new list<Account>();
        
        for(Account acc:Acclist){
            
            acc.website ='www.sfdcfor.com';
            acc.name = 'SFDC ForYou';
              
           Accupdate.add(acc);
         }
        
        update accupdate;


Result :-


Insert a New Record Using Developer Console




Account Record Insert :-



1
2
3
4
5
   Account acc = new Account();
           acc.name = 'india';
           acc.website = 'www.sfdcforyou.com';

    Insert acc;



Contact Record Insert :-



1
2
3
4
5
 Contact con = new contact();
         con.Lastname='Sfdcforyou';
         con.Department='Sfdcforyou';
        
 Insert con;


Schedule a Batch Class






Batch  Class :-



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
global class batchContactupdate implements Database.Batchable<sObject> {

global Database.QueryLocator start(Database.BatchableContext BC)
     {
    string Query='Select Name, Type from Contact';
     return Database.getQueryLocator(Query);
     }
       global void execute(Database.BatchableContext BC, List<Contact> scope)
       {
        for (Contact a : Scope)
        {
            a.Description='----This Description is updated by Batch Class------';
        }
       update Scope;
       
       }
     
      global void finish(Database.BatchableContext BC) 
    {
    }
 }

Scheduled Class :-



1
2
3
4
5
6
7
8
9
global class scheduledBatchable implements Schedulable {


   global void execute(SchedulableContext sc)
    {
      batchContactupdate b = new batchContactupdate(); 
      database.executebatch(b);
    }
}



Cron Expression :-


1
2
3
scheduledBatchable sc = new scheduledBatchable();
String sch = '0 5 * * * ?';
String jobID = system.schedule('Update Contact Job', sch, sc);


Scheduled Jobs :-




Apex Jobs :-







Batch Class In Salesforce






Batch Class Code :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
global class batchContactupdate implements Database.Batchable<sObject> {

global Database.QueryLocator start(Database.BatchableContext BC)
     {
    string Query='Select Name, Type from Contact';
     return Database.getQueryLocator(Query);
     }
       global void execute(Database.BatchableContext BC, List<contact> scope)
       {
        for (Contact a : Scope)
        {
            a.Description='----This Description is updated by Batch Class------';
        }
       update Scope;
       
       }
     
      global void finish(Database.BatchableContext BC) 
    {
    }
 }


Developer Console Code :-

1
2
batchContactupdate xyz = new batchContactupdate();
database.executebatch(xyz);



Apex Job :-




Tuesday, 26 July 2016

Method called from JS using Action function

In below example we are going to show you how you can call method from JS using ActionFunction

Flow Chart:-

1:- On click Radio button line 14 VF page ==> "javascript1()"

2:-Script call at line no 4 VF page ==> function javascript1()

3:- Function call at line no 5 VF page ==> ActionFunctionName();

4:- Now it goes to line no 10 ==>
      <apex:actionfunction name="ActionFunctionName" 
       action="{!ActionFunctionMeth}" rerender="ReftxtId"/>

5:-It will call action/Method  at line no 10 .{!ActionFunctionMeth}

6:- Now Method in Controller at line no 6 will update value in MyString variable .

7:- Updated value of MyString will shown to user using below code at line no 18 in VF page.

      <apex:outputText value="{!MyString}" id="ReftxtId"></apex:outputText>


 Controller Code:-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Public class ExmplActionFunction {
Public string MyString{get;set;}

  public ExmplActionFunction (){}

  public string ActionFunctionMeth(){
     MyString = 'Method called from js using Action function After clicking on Radio Button';
     return null;
    }
}


Visualforce page :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<Apex:page controller="ExmplActionFunction">

<script> 
function javascript1(){
ActionFunctionName();
}
</script>
<apex:form >

<apex:actionfunction name="ActionFunctionName" action="{!ActionFunctionMeth}" rerender="ReftxtId"/>

<apex:pageblock >
<apex:outputLabel value="Click on Radio Button Below to call Contoller method from js using ActionFunction"></apex:outputLabel>
<apex:selectRadio onclick="javascript1()" ></apex:selectRadio><p/>
</apex:pageblock>

<apex:pageblock >
<apex:outputText value="{!MyString}" id="ReftxtId"></apex:outputText>
</apex:pageblock>

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


 User Interface :-




Thursday, 14 July 2016

Salesforce Certified Force.com ADM 201 - Spring '16 Release Exam

Que 1 :- What is true regarding the new Data Loader?

A. It has a new column flagging duplicate files.
B. It supports Web Server OAuth Authentication for Windows or Mac.
C. It has downloadable add-ons published through the AppExchange.
D. It works with all legacy security protocol.

Que 2 :-What key user access data is included in login forensics?


A. Who logged in from a new browser more than once in a day.
B. Who logged in more than the number set in the profile.
C. Who logged in during business hours.
D. Who logged in more than the average number of times.


Que 3 :- What does the Customize Application permission setting allow?


A. To create article types.
B. To edit contract settings.
C. To modify custom picklist values.
D. To create a new user.

Que 4 :- What object types is Work Orders object associated with?
Choose 2 answers

A. Products
B. Service Contracts
C. Milestones
D. Cases
E. Leads

Que 5. Which areas are calculated for the Health Check score?
Choose 2 answers

A. Number of users
B. Session Settings 
C. Profiles and Permissions assigned
D. Password Policy
E. Login attempts