Showing posts with label Visualforce Scenarios. Show all posts
Showing posts with label Visualforce Scenarios. Show all posts

Sunday, September 23, 2018

Create a visualforce page to display account information by using standard controller

Visualforce Page:
---------------------
<apex:page standardController="account" recordSetVar="accounts">
    <apex:form>
      <apex:pageBlock>
          <apex:pageBlockTable value="{!accounts}" var="a">
              <apex:column value="{!a.name}" headerValue="Account Name"/>
              <apex:column value="{!a.type}" headerValue="Account Type"/>
              <apex:column value="{!a.accountnumber}" headerValue="Account Number"/>
              <apex:column value="{!a.industry}" headerValue="Account Industry"/>
          </apex:pageBlockTable>
          <apex:commandButton action="{!first}"  value="First"/>
          <apex:commandButton action="{!Next}"  value="Next"/>
          <apex:commandButton action="{!previous}"  value="Previous"/>
          <apex:commandButton action="{!last}"  value="Last"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Saturday, September 22, 2018

i) Visualforce page on view account details and its related contacts, opportunities and open activities in tab by account id? ii) Create a button on account detail page?

i) Visualforce page on view account details and its related contacts, opportunities and open activities in tab by account id?
Visualforce Page:
---------------------
<apex:page standardController="account">
    <apex:tabPanel>
      <apex:tab label="Details" name="accountdetails" id="tabdetails">
          <apex:detail relatedList="false" title="false"/>
      </apex:tab>
        <apex:tab label="Contacts" name="Contacts" id="tabContacts">
          <apex:relatedList subject="{!account}" list="contacts" />
      </apex:tab>
        <apex:tab label="Opportunities" name="Opportunities" id="tabOpportunities">
          <apex:relatedList subject="{!account}" list="Opportunities"/>
      </apex:tab>
        <apex:tab label="Open Activities" name="OpenActivities" id="tabopnact">
          <apex:relatedList subject="{!account}" list="OpenActivities"/>
      </apex:tab>
    </apex:tabPanel>
</apex:page>


ii) Create a button on account detail page?
If we  create button, when user click on this button, can redirect to the visualforce we created above with out giving 'id' on URL.
Create new button:
fill the details:
Add this button on account detail page through page layout and it will show as below.

When we click on that button, it will open the vf page we create along with current account id.

How to override with 'New' button on account object?

Visualforce Page:
----------------------
<apex:page standardController="account">
    <apex:form>
      <apex:pageBlock title="Account Details">
         <apex:pageBlockButtons>
           <apex:commandButton value="Save the account" action="{!save}" />
         </apex:pageBlockButtons>
          <apex:pageBlockSection title="Account Information" columns="2" collapsible="false">
             <apex:inputField value="{!account.name}"/>
              <apex:inputField value="{!account.phone}"/>
              <apex:inputField value="{!account.industry}"/>
              <apex:inputField value="{!account.type}"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
</apex:page>

output:
We have to override the "new" button on account object, for this go to Buttons, Links, and Actions on account object and click edit link near new label.
Then select visualforce page which we created on Salesforce Classic Override section.

Click on Save button, then whenever we click on new button to create new record on account object, this vf page will opened.

Adding multiple account records in single save using visualforce page

Adding multiple  records in single save using visualforce page

Apex Class:
---------------
public class addmultiplerecords{
   account a = new account();
   public list<account> acclist{get; set;}
   public addmultiplerecords(){
     acclist = new list<account>();
     acclist.add(a);
  }
  public void addaccount(){
      account acc = new account();
      acclist.add(acc);
  }
  public pagereference saveaccount(){
          insert acclist;
          return null;
  }
}
Visualforce Page:
----------------------
<apex:page controller="addmultiplerecords">
    <apex:form>
       <apex:pageBlock>
          <apex:pageBlockTable value="{!acclist}" var="a">
              <apex:column headerValue="Account Name">
                  <apex:inputField value="{!a.name}"/>
              </apex:column>
               <apex:column headerValue="Account Number">
                  <apex:inputField value="{!a.accountnumber}"/>
              </apex:column>
               <apex:column headerValue="Account Type">
                  <apex:inputField value="{!a.type}"/>
              </apex:column>
               <apex:column headerValue="Account Industry">
                  <apex:inputField value="{!a.industry}"/>
              </apex:column>
          </apex:pageBlockTable>
          <apex:pageBlockButtons>
              <apex:commandButton value="Add one more account" action="{!addaccount}"/>
              <apex:commandButton value="Save Account" action="{!saveaccount}"/>
          </apex:pageBlockButtons>
       </apex:pageBlock>
    </apex:form>
</apex:page>