function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rajasekar@apexcloud.com.devrajasekar@apexcloud.com.dev 

How to fetch Contact/Lead address of a Task?

Hi,

 

Is there any direct way to fetch the Contact/Lead Address of the task by using the query??

 

Thanks,

Pradeep_NavatarPradeep_Navatar

We can access some of the contact or lead information. You will be able to fetch limited fields by using the query. For an example you can access id ,name but will not be able to access the address.

 

Hope this helps.

tantotanto

Can you elaborate on how you are trying to accomplish this and the out come?

RajaMohanRajaMohan

Hi tanto,

 

I am having a visualforce page. In that, I need to display the Today Activity Details and Contact/Lead Address based on the whoId in Activity. I tried in many ways but I cant able to fetch the details.

 

Any idea or codes will be helpful.. Thanks..

jkucerajkucera

In general I find the API guide helpful for these types of problems:

http://www.salesforce.com/us/developer/docs/api/index.htm

 

Something like this should work:

 

Set<Id> leadIds=[select ID FROM Lead WHERE <fill in your criteria>];

List<Task> leadTasks=[SELECT Id, Subject, WHOID FROM Task WHERE WhoId IN : leadIds];

 

I believe you have to do one list of tasks for Lead and a 2nd for Contact so that sharing can be calculated (would be extremely slow performance otherwise).

tantotanto

I have to agree with John. Have you tried SOQL? If so could you post the query?

RajaMohanRajaMohan

Hi

 

I did the following to accomplish this.

 

Controller:

 

 public class dataTableCon {

Set<Id> taskIds=new Set<Id>();
public List<Event> tts =new List<Event>();
public Event tt { get; set;}
Set<Id> contactIds=new Set<Id>();
List<Contact> contacts=new List<Contact>();
List<Contact> conlist=new List<Contact>();
List<Account> accounts=new List<Account>();
List<Event> tasks=new List<Event>();
public ID id1;
List<Contact> c=new List<Contact>();


public String date1;
public Date uDate;

public dataTableCon() {

}


public dataTableCon(ApexPages.StandardController controller) {
this.tt=(Event)controller.getRecord();
this.tt.ActivityDate=System.Today();
date1 = ApexPages.currentPage().getParameters().get('dd');

}


/*Task*/
public List<Event> getTasks(){
uDate=date.valueOf(date1);

Event[] ee=[select whoId from Event where (ActivityDate =: uDate AND ownerId=:UserInfo.getUserId()) ORDER BY StartDateTime ASC limit 10];
// ee.sort();
System.debug('## Tasks: ' + ee);
for(Event e:ee){
if(e.whoId!=null){
Event con=[select StartDateTime,EndDateTime,who.FirstName, Who.LastName, who.Type, Subject, Description, ActivityDate from Event where id =:e.id];
Contact cc=[select Name, Account.Premiumaccount__c,Account.Name, Street__c,City__c,PostalCode__c from Contact where ID =:e.whoId];
con.AccType__c=cc.Account.Premiumaccount__c;
con.ContactLeadAdd1__c=cc.Street__c;
con.ContactLeadAdd2__c=cc.City__c;
con.ContactLeadAdd3__c=cc.PostalCode__c;
con.AccName__c=cc.Account.Name;
tasks.add(con);
}
}
// tasks.sort();
return tasks;
}






Public PageReference Sub(){
PageReference pf=new PageReference('/apex/TaskFinalRes?dd='+tt.ActivityDate);
pf.setRedirect(True);
return pf;
}

Public PageReference Taskfin(){
PageReference pf=new PageReference('/apex/TaskFinal');
pf.setRedirect(True);
return pf;
}

}

 

 

I displayed the informations in VF page. This is working good in sandbox but the Account Name, Account Type and Address are not displaying in production.

 

Can any  one help in this?? This is very urgent..

jkucerajkucera

I highly recommend reading this article:

http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/

 

to add things like Account name:

 

contact.account.name

 

 

RajaMohanRajaMohan

Hi,

 

Thanks. It is working too fine now. But it is displaying the GMT time. How to change the time according to that org?