I have two objects phase and task. Task is hvng a lookup to phase object. When I will create a task under phase, task name should autopopulate by phase name before saving task record. Please let me know how to proceed. Regards
-
Currently I hv handled it using formula field. But field will get populated after insert.Client needs tht field should get populated before saving.Need some approach....– sfdc_to_learnCommented Jun 25, 2015 at 10:57
-
Do you mean you want to get the phase name to appear on the Task when the user clicks the New Task button?– BarCotterCommented Jun 25, 2015 at 11:24
-
Yes.. You are correct– sfdc_to_learnCommented Jun 25, 2015 at 11:40
2 Answers
The Task Name
field (API Name WhoId) is actually a Lookup to either Contact or Lead so it will not be possible to give it the value of your Phase object.
The Related To
field (API Name WhatId) is a Lookup to many objects including your Phase object so the Phase Name will show up there.
If you absolutely need to have a field labeled Name
display the Phase Name you could create a Custom field and Label it Name
, but this may become confusing in other places and if you go that route you may want to consider changing the label on field with API Name WhoId that has label of Name
.
You can use something like this :
trigger conAccountName on Contact (before insert) {
string ids;
for(contact con : trigger.new){
ids = con.accountid;
}
list<account> accountlist = new list<Account>([select id, name from account where id =:ids]);
string accName;
for(Account a : l){
accName = a.name;
}
for(contact c : trigger.new){
c.lastName = accName;
}
}
Here I am autopopulating the contact name with its account's name before insert. You can develop a similar trigger for yout objects. Let me know if this helps.
-
Hi. Unless you save the record the name will not populate. I need before saving the record the name should appear. For ex - when we click on new contact, you can see phone no gets auto-populate. I want similar to that. Commented Jun 25, 2015 at 11:13
-
-
you can take a look here : forcetree.com/2012/04/… .You can create a custom button with the URL value and in it. Commented Jun 25, 2015 at 11:32