+ Start a Discussion
newbie2010newbie2010 

Custom Log a Call VF Page, passing account info

I have created the following VF Page and controller extension to create, what is basically, a pop up of the comments field for logging a call.  This is assigned to a button as a URL on the Account page.  The idea is that everything is assigned within the controller while displaying just the comment box to enter info from the call.  Right now as it is currently written I can fill in everything I need except the account that the "log a call" is related to.  I am passing the account id through the URL in the button.  Any suggestions on how to grad the account id from the URL and make that the account it is related to would be great.

 

VF Page

<apex:page standardController="Task" extensions="LogACallControllerExtension" showHeader="false" sidebar="false">
    <apex:sectionHeader title="Log A Call" />
    <apex:form id="pageForm">
        <apex:pageBlock title="Call Edit" mode="edit">
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!save}" />
                <apex:commandButton value="Cancel" action="{!cancel}" />
            </apex:pageBlockButtons>
            <br />
            <apex:pageBlockSection title="Call Information" columns="1" collapsible="false">
                <apex:inputField value="{!Task.Description}" style="width:400px;height:100px;" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 Controller Extension

public with sharing class LogACallControllerExtension {

    public Task task;
    ApexPages.Standardcontroller controller;
    
                public Account getAccount() {
                    return [SELECT Id, Name from Account where Id=:ApexPages.currentPage().getParameters().get('what_id')];
                }

    public LogACallControllerExtension(ApexPages.StandardController controller) {
            this.task = (Task)controller.getRecord();
            this.task.subject = 'Service Call';
            this.task.type = 'Call';
            this.task.status = 'Completed';
            this.task.activitydate = system.today();
            this.controller = controller;
    }
    public PageReference save() {
          return controller.save();
    }

}

 Button URL

/apex/Log_a_Call_in_Chatter?title=Call&what_id={!Account.Id}&followup=1&tsk5=Service Call&retURL=%2F{!Account.Id}&tsk3={!Account.Name}&tsk10=Call

 I have tried pulling the name from the URL that is assigned to 'tsk3', but it is giving me an error trying to assign a 'name' to a 'string'.

 

I am also wondering if it would be possible to take what is entered in the comment field and post that as a feed in the related account.

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

Just quickly, I think you just want the controller to look like:

 

public with sharing class LogACallControllerExtension {

    public Task task {get; set;}

    public LogACallControllerExtension(ApexPages.StandardController controller) {
            this.task = (Task)controller.getRecord();
            this.task.whatId = ApexPages.currentPage().getParameters().get('what_id');    
            this.task.subject = 'Service Call';    // or      this.task.subject = ApexPages.currentPage().getParameters().get('tsk5');
            this.task.type = 'Call';
            this.task.status = 'Completed';
            this.task.activitydate = Date.today();
    }
}

 

You don't need to override the default controllers Save method with your own since you inherit it from the standard controller.   It's "Date.today()", not "system".   For assigning the WhatId you just need to give it the Id, not the sobject, so you don't need to query for the Account object.  So, assuming that you're passing the Account Id as "what_Id", you should be able to just use it as is.

 

Best, Steve.

 

All Answers

SteveBowerSteveBower

Just quickly, I think you just want the controller to look like:

 

public with sharing class LogACallControllerExtension {

    public Task task {get; set;}

    public LogACallControllerExtension(ApexPages.StandardController controller) {
            this.task = (Task)controller.getRecord();
            this.task.whatId = ApexPages.currentPage().getParameters().get('what_id');    
            this.task.subject = 'Service Call';    // or      this.task.subject = ApexPages.currentPage().getParameters().get('tsk5');
            this.task.type = 'Call';
            this.task.status = 'Completed';
            this.task.activitydate = Date.today();
    }
}

 

You don't need to override the default controllers Save method with your own since you inherit it from the standard controller.   It's "Date.today()", not "system".   For assigning the WhatId you just need to give it the Id, not the sobject, so you don't need to query for the Account object.  So, assuming that you're passing the Account Id as "what_Id", you should be able to just use it as is.

 

Best, Steve.

 

This was selected as the best answer
newbie2010newbie2010

Thanks, Steve!!  That worked great!

 

Now if I could figure out how to take what is entered in the comment box and post that as a chatter feed in the related account then I will be set.

 

Thanks Again!!!

Max_gMax_g

Using your example for the Log a call page, I'm not getting the What_Id to display on my page.  Page is showing related to Account, but the account name is not pulling into the input field.

 

I am using the ownerid as the assigned to name, but that field is not prepopulated as I would have expected it to be.  What field from the standard account lookup page would have that value? 

 

I'm just eliminating the additional followup section of the log a call screen since there is no place that I can find where we can change the followup flag automatically.

 

Any help will be greately appreciated.