I am trying to populate the Task with related data even before creating a task. For example in this Task creation, I have RelatedTo(Loan) autofilled, similarly I want LoanNumber and ClientName to be auto filled which are fields from Loan object.

I have created a Trigger but that is working only after creating a Task but not before,

trigger updateLoan_Task on Task (before insert, before update) {

   Set<Id> LoanIDs = new Set<Id>();
   for (Task t : Trigger.new) {
       if (t.WhatId != null && String.valueOf(t.WhatId).startsWith('a0Q')) {

   Map<Id, Loan_New__c> loan = new Map<Id, Loan_New__c>([Select Id, LoanNumber__c, Client_Name__c from Loan_New__c where Id in :LoanIDs]);

   for (Task t : Trigger.new) {
       if (t.WhatId != null && String.valueOf(t.WhatId).startsWith('a0Q')) {
            Loan_New__c l = loan.get(t.WhatId);
            t.test_loanNumber__c = l.LoanNumber__c;
            t.Client_name__c = l.Client_Name__c; 

Is there any way I can populate this info before creating a task, I checked this from the other Post but my scenario is different. Any suggestions?


  • FYI you should check the object type of the WhatId more programatically i.e. t.WhatId.getSObjectType() == My_Object__c.sObjectType.
    – Adrian Larson
    Commented Jan 11, 2019 at 19:06

2 Answers 2


Triggers are supposed to work that way. They do not pre-populate data on the screens but only update it during the transaction.

Out of the box, you will not be able to pre-populate data. If you can create some lightning component, then you can utilize force:createRecord event here which lets you to open the standard screen for record creation with an option of pre-populating the desired fields by using the defaultFieldValues of this event.

Prepopulating Field Values

The defaultFieldValues attribute lets you prepopulate the create record form with default or calculated field values. Prepopulated values can accelerate data entry, improve data consistency, and otherwise make the process of creating a record easier. Specify default field values as name-value pairs in a JavaScript object.

Example below from the documentation. You can read more about this event and how to utilize it on its documentation.

var createAcountContactEvent = $A.get("e.force:createRecord");
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'AccountId' : '001xxxxxxxxxxxxxxx'

As it is clear from your screenshot, You are using either an object-specific quick action or Global action, You can use setting predefined value for the fields you want on the action.

When you create actions, use predefined field values to set a value for a field. Predefined values can help ensure consistency and make it faster and easier for users to create records.

Note:- When You will use force:createRecord, In AssignedTo field, you will get the only User Option, not the groups.

Follow these steps:-

  1. Click the name of an action in the Buttons, Links, and Actions list or the Global Actions list.
  2. On the action detail page, click New in the Predefined Field Values list. Select the field you want to predefine a value for.
  3. Specify the value for the field.
  4. For single-select picklists, you can specify both a specific value and a formula value.
  5. If you set both, the formula value takes precedence over the specific value. Click Save.

Go through this for more information about this:- Set Predefined Field Values for Quick Action Fields

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .