Wednesday, 27 November 2013

Generate XML using button click and save to the Desktop

Problem :- I had a requirement where If user click on a custom button on Account Page or any other Custom Object Detail page, XML should generate and user should be able to save that XML to their Desktop.

Solution:
1.Create a Custom button and add that page to the page layout.
2.Create a VF Page and controller as below:-

VF Page:
<apex:page standardController="Account" extensions="TestController" contentType="application/octet-stream"><?xml version="1.0" encoding="UTF-8"?>
    <MyAccount:stuff xmlns:MyAccount="http://www.bogussite.com/namespace/myNamespace">
        <apex:repeat value="{!accountName}" var="account">
            <MyAccount:Account Name="{!account.Name}"/>  
<!--            <MyAccount:Account AccountNumber="Act Name" value="{!account.AccountNumber}"/>-->
            <MyAccount:Account Phone="{!account.Phone}"/>
            <MyAccount:Account NoOfContact="{!account.noOfContacts__c}"/>    
        </apex:repeat>
    </MyAccount:stuff>
</apex:page>

Apex Controller :

public with sharing class TestController
{

public Id id{get;set;}
public Account account{get;set;}
public List<Account> accountName;
public TestController(ApexPages.StandardController controller)
{
//id = ApexPages.CurrentPage().getParameters().get('id');

}

public  List<Account> getAccountName()
{
accountName = [select Name,Phone,noOfContacts__c from Account where id = :ApexPages.currentPage().getParameters().get('id')];
System.Debug('Account Name ' +accountName + 'ID = ' +id);
return accountName;
}

}



When user will click on the button it will prompt a window asking user to save the xml.

My next requirement is to add the related List record to the root of the Parent Record, Will update the same on .....

Try it and let me know in case of any issue or any improvement

Saturday, 16 November 2013

Salesforce Dev-401 Materials

Force.com Developer Certification Handbook DEV-401 by Siddhesh Kabe.
Force.com Developer Certification study guide
Salesforce Validation Rule:-

Problem:
There are One check box and two pickList fields  on the Custom Object Page. User want to make sure if checkBox fields is selected then both the Picklist value should not be null.

Solution:-

AND((US_Citizen__c==true),
((ISPICKVAL(City__c ,'')) || (ISPICKVAL(State__c ,''))))

Here in this Solution:
 US_Citizen__c = Custom Check box
and
City__c and State__c = Custom PickList Fields.