Sunday, 26 April 2020

Illegal assignment from LIST<Account> to LIST<Account> at line in Apex Class:

Whenever you have return Query on any object if it is returning more than one record then we will be using the List datatype to store that result .Here is the some interesting issue that I faced when I am assigning my results of type List<Account> to List<Account>

Public class AccountSearch
{
 List<Account> listAcc{get;set;}
 public AccountSearch()
 {
    listAcc = new List<Account>();
 listAcc = [Select id,name FROM Account ];
 }
}

When I am execute this class I am getting an error at line Query Illegal assignment from LIST<Account> to LIST<Account> at line in Salesforce Class.
Here I'm getting list of accounts from query and I am assigning that to List<Account> listAcc only but why still I getting this error.I searched for it so many places finally I got the solution.

WorkAround:
In my organization somewhere I have created a class named "Account". That is why the compiler is not able to understand that it is standard Object Account or the class created in my org.Now I renamed my class to some other name now it's working perfectly.

Sunday, 28 October 2012

How to support paging of data in your Visualforce Pages.

A while back I was working on a project in which I had to a design a search interface for my Custom object. The search result could get pretty big at times and I always needed to over come the limitations and show large number of rows in the screen.

At that point I was like "gee if I could use Paging with the pageBlockTable tag" and then I decided to write it myself. So here is goes:

As we all know we should have two pieces of code, one for the Controller and the other is for the page tags.


The whole idea here is to create two lists on the controller object which one keeps the original records (all records) and the second one temporarily keeps only what should be shown to the user.
With defining a few parameters such as Total Pages, Current Page Number and Page size I managed to simulate paging successfully.

Here is what goes to the page:


<apex:page controller="MyPagingController" tabStyle="Account">
<apex:sectionHeader title="Accounts List with Paging"></apex:sectionHeader>
<apex:form >
<apex:pageBlock title="" id="pageBlock">
<apex:pageBlockButtons location="top">
<apex:commandButton value="View" action="{!ViewData}" id="theButton" rerender="pageBlock"></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageMessages ></apex:pageMessages>
<div align="right" style="display:{!IF(NOT(ISNULL(accounts)),'block','none')}">
<font size="1pt">Page #:&nbsp;<apex:outputLabel value="{!PageNumber}"/>&nbsp;out of&nbsp;<apex:outputLabel value="{!totalPageNumber}"/>&nbsp;&nbsp;&nbsp;&nbsp;</font>
<apex:commandButton value="Previous" action="{!previousBtnClick}" disabled="{!previousButtonEnabled}" reRender="pageBlock"></apex:commandButton>
<apex:commandButton value="Next" action="{!nextBtnClick}" reRender="pageBlock" disabled="{!nextButtonDisabled}" ></apex:commandButton>
</div>
<br/><br/>
<apex:pageBlockTable value="{!accounts}" var="a" rendered="{!NOT(ISNULL(accounts))}" rows="{!PageSize}">
<apex:column >
<apex:facet name="header">Account Name</apex:facet>
<apex:outputLink value="/{!a.Id}" target="_blank">{!a.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!a.Phone}"></apex:column>
<apex:column value="{!a.Fax}"></apex:column>
</apex:pageBlockTable>
<div align="right" style="display:{!IF(NOT(ISNULL(accounts)),'block','none')}">
<br/>
<font size="1pt">Page #:&nbsp;<apex:outputLabel value="{!PageNumber}"/>&nbsp;out of&nbsp;<apex:outputLabel value="{!totalPageNumber}"/>&nbsp;&nbsp;&nbsp;&nbsp;</font>
<apex:commandButton value="Previous" action="{!previousBtnClick}" disabled="{!previousButtonEnabled}" reRender="pageBlock"></apex:commandButton>
<apex:commandButton value="Next" action="{!nextBtnClick}" reRender="pageBlock" disabled="{!nextButtonDisabled}" ></apex:commandButton>
</div>

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




Below is the code for Controller:


public class MyPagingController {
private List accounts;
private List pageAccounts;
private Integer pageNumber;
private Integer pageSize;
private Integer totalPageNumber;
public Integer getPageNumber()
{
return pageNumber;
}
public List getAccounts()
{
return pageAccounts;
}
public Integer getPageSize()
{
return pageSize;
}
public Boolean getPreviousButtonEnabled()
{
return !(pageNumber > 1);
}
public Boolean getNextButtonDisabled()
{
if (accounts == null) return true;
else
return ((pageNumber * pageSize) >= accounts.size());
}
public Integer getTotalPageNumber()
{
if (totalPageNumber == 0 && accounts !=null)
{
totalPageNumber = accounts.size() / pageSize;
Integer mod = accounts.size() - (totalPageNumber * pageSize);
if (mod > 0)
totalPageNumber++;
}
return totalPageNumber;
}
public MyPagingController()
{
pageNumber = 0;
totalPageNumber = 0;
pageSize = 20;
ViewData();
}
public PageReference ViewData()
{
accounts = null;
totalPageNumber = 0;
BindData(1);
return null;
}
private void BindData(Integer newPageIndex)
{
try
{
if (accounts == null)
accounts = [Select id, Name, Phone, Fax from Account limit 1000];
pageAccounts = new List();
Transient Integer counter = 0;
Transient Integer min = 0;
Transient Integer max = 0;
if (newPageIndex > pageNumber)
{
min = pageNumber * pageSize;
max = newPageIndex * pageSize;
}
else
{
max = newPageIndex * pageSize;
min = max - pageSize;
min = (min <>
}
for(Account a : accounts)
{
counter++;
if (counter > min && counter <= max)
pageAccounts.add(a);
}
pageNumber = newPageIndex;
if (pageAccounts == null || pageAccounts.size() <= 0)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Data not available for this view.'));
}
catch(Exception ex)
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,ex.getMessage()));
}
}
public PageReference nextBtnClick() {
BindData(pageNumber + 1);
return null;
}
public PageReference previousBtnClick() {
BindData(pageNumber - 1);
return null;
}
}

Friday, 19 October 2012

How to import attachments using Apex Data Loader?



Steps to import attachments using Apex Data Loader are
  1. Create an AttachmentLst.csv file with the following column headers:
·         ParentId - ID of the record to which the attachment should be associated  
·         Name - Name of the attachment  
·         ContentType - Format of the extension (e.g. .xls, .pdf, etc)  
·         OwnerID - ID for the owner of the attachment 
·         Body - File path to the Attachment on your local machine (C:\Attachments\FileName.jpeg)
  1. Log in to the Data Loader. 
  2. Select the "Insert" command.
  3. In the 'Select Sforce Object' step, select the ‘Attachments’ object. This object is not displayed by default hence check the ‘Show all Sforce Objects' checkbox. 
  4. Choose the AttachmentLst.csv file. 
  5. In the mapping step, map the following fields:
·         Parent ID 
·         Name 
·         Owner ID 
·         Body - Make sure to map the Body column which you created previously with the file extension. This is how you designate the file and location of the attachments to be inserted. 
                  7. Click "OK" to start the upload.

Saturday, 13 October 2012

AUTO REFRESH DASHBOARDS

Auto Refresh Dashboards every time you click the Home Tab.

Tired of seeing the wrong numbers displayed on the Dashboard? Oftentimes, users forget to hit the refresh button on the Home Page Dashboard. This can result in Salesforce users seeing inaccurate data which can be confusing and frustrating. This TIP will help keep your Dashboards refreshing with the most up to date information.

Go to the setup menu:
Click customize, Home, Homepage Components.
Edit Messages and Alert.
Paste this code anywhere in the data entry box:
<script type="text/javascript"> var run; function sa_refresh() { var dashboardButton = document.getElementById("db_ref_btn"); dashboardButton.click() } setTimeout(sa_refresh, 5000); //Runs the Refresh function every 5 minutes using Milliseconds (1minute = 60000) run = setInterval(sa_refresh,300000); </script>

SAVE.
The code will refresh the dashboard every time you click the home tab or every 5 minutes.

Sunday, 7 October 2012

How to use 'Schema- Builder' in Salesforce

Hi All,  while working with salesforce we have to deal with many S-Object and Custom-Objects.we need to set up relation ship (Master/Lookup) among these all.But to keep this relation-ship in mind is very typical.
 To get a rid of this problem Salesforce has provided it's new tool "Schema-Builder".

Specification:-
--------------
In Schema Builder We may observe relation ship among many objects.Different different color lining are used to make it clear and out of any sort of technical-dilemma.
to configure
1.)go to Set up ->App setup->where you will easily 'Schema builder' link.

2.) click on this link you will be redirected t new Page with schema home page where you will get a list of objects.
3.) Select object to view pre-defined relationship among them.

How to Use ANT in salesforce

Hi friends here We will learn How to deal with deployment process using ANT. If you have ANT then fine
other wise download apache-ant-1.8.2 or higher version and go through these steps for installing ANT.
Step 1 Download apache-ant-1.8.2-bin from Web.
step 2 install jdk1.6.0_25 or higher version.
Step 3 go to run command use command sysdm.cpl press "advanced" tab then press "environment variable" tab then press on
tab "New"

create two variable ANT_HOME and JAVA_HOME
ANT_HOME D:\apache-ant-1.8.2-bin\apache-ant-1.8.2 (if your ant folder is in D- drive)                    
JAVA_HOME  C:\Program Files\Java\jdk1.6.0_25 (give path of jdk)

PATH %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\ProgramFiles\Java\jdk1.6.0_25\jre\bin;D:\apache-ant-1.8.2-bin\apache-ant-1.8.2\bin;
(if path variable is alreadyavailable then append this also other wise create new Path variable)

for more detail go to
http://ant.apache.org/manual/index.html

Now we move to "How to Use ANT for deployment in Apex"

for this Process
1) First of all create package.xml(depends requirement )
2) And Use build.xml and
3) build.property (change credential according to your requirement)

Tuesday, 2 October 2012

How to be Sucessful with Salesforce

Name: How to be Sucessful with Salesforce.

Release: Spring 12

Pages: 3611

                                        Download link