You need to sign in to do that
Don't have an account?

How to display Contact Name In Trigger
Hello All,
I have field in contact object called Manager which is lookup to contact, i have trigger on contact object so basically this trigger creates case when a new contact is created but when iam selecting manager from contact this manager name is not displaying in the case instead it's displaying Id, any help?
Finally I could reproduce it and your solution is
use String.valueOf(ct.Start_Date__c) in your trigger while assigning value to any text field , String.value will conver date into the string that do not show
00 : 00 : 00
All Answers
Use another SOQL in trigger to fetch information from manager.
you will not get related values in trigger.new , you will have to query on contact again for the manager id and fetch the name
Use this in your trigger
code
In the query i have inserted this field but instead of displaying manager name in case it's displaying Id, here is my code
public class ContactTriggerClass
{
public void createCase(Map<Id,Contact> TriggerNewValues)
{
List<Case> c = new List<Case>();
for(Contact ct :[select c.Id,c.Name,c.AccountId,c.Notification_Type__c,c.Manager_Name__r.Manager_Name__c,c.EmployeeType__c,c.Location__c,c.Start_Date__c,c.CostCenter__c,c.HRDepartment__c,c.Employee_List__c,c.JobTitle__c,c.Unix_Account__c, c.Termination_Date__c, c.Termination_Time__c from Contact c where c.Id IN:TriggerNewValues.keyset()])
{
if((ct.Notification_Type__c == 'New Employee') || (ct.Notification_Type__c =='New Contractor'))
{
c.add(new Case(ContactId = ct.Id,AccountId = ct.AccountId,Type = 'PC SETUP_(New/Reused;Desktops,Laptops)',Status='Assigned',Priority = 'Standard',OwnerId = '00G400000015Yoo',Origin ='Email',Subject = 'New PC Setup :'+ct.Name+'- Start Date :'+ct.Start_Date__c,Description = 'Name :'+ ct.Name+'\r\n\r\nManager :'+ct.Manager_Name__r.Manager_Name__c+'\r\n\r\nEmployee Type :'+ct.EmployeeType__c+'\r\n\r\nLocation:'+ct.Location__c+'\r\n\r\nStart Date :'+ct.Start_Date__c));
}
}
insert c;
}
}
Try with this
change
c.Manager_Name__r.Manager_Name__c
to
c.Manager_Name__r.Name
at both the places i think you are getting manager id of manager in your code.
ohh that is awesome, it displayed me the name , a small question in the same contact object i have date field called start_date__c, so when the case gets created the date is showing perfect but along with the date it is showing the time format like this 2011-06-24 00:00:00 , i want to avoid this , iam not sure why it is displaying time even though the field is just date type
Your field is datetime field , use date field if you don't want time.
It is just date field
and what is the return type of formula field , please check it is not datetime either.
Return type of formula field? i have just created date field Start_Date__c and iam using this in class, i thought it should just display date but it's not
I also tried a formula field of type Date and saw it did not show me 00:00:00 , you can tru one more thing in your foumula select treat blank as blank.
Please let me know how are you filling your formula field , what is the formula.
Actually iam not creating formula field iam just creating a Date field and iam using this date field in Apex class
Is Start_Date__c is your Date field and you are copying it in the TextField
Yes Start_Date__c is Date field in Contact Object and if a new contact is created then the case gets created and this Date field from contact would be displaying in the description (Text) field in Case
Finally I could reproduce it and your solution is
use String.valueOf(ct.Start_Date__c) in your trigger while assigning value to any text field , String.value will conver date into the string that do not show
00 : 00 : 00
You are awesome thank you somuch for your help
Your welcome mate :)
Thx for being so kind to me and helping me in my lil project, while it is coming to end i have small question where i have no idea to do it, i could do it by WFR but i need to setup atleast like 10 rules, but is it possible to add the manager name to the caseteam when a case is created, ok i knw it's lil confusion but i will explain you, usually when a contact is created , i have a Manager_Name__c field in contact so they will select this manager respective to that contact so when they save the contact a case gets created so is it possible to add this Manager to the case team for respective case, if possible i can post my code but it is similar to the code which i have posted before.
TIA!
Yes, It is possible, please post your code, I will try to help you if I Could.
Gr8 thanks so much , here is my code
Trigger:
Class: public class ContactTriggerClass
{
public void createCase(Map<Id,Contact> TriggerNewValues)
{
List<Case> c = new List<Case>();
for(Contact ct :[select c.Id,c.Name,c.AccountId,c.Notification_Type__c,c.Manager_Name__r.Name,c.EmployeeType__c,c.Location__c,c.Start_Date__c,c.CostCenter__c,c.HRDepartment__c,c.Employee_List__c,c.JobTitle__c,c.Special_Instructions_Hire__c,c.Special_Instructions_Term__c,c.Unix_Account__c,c.Termination_Date__c, c.Termination_Time__c from Contact c where c.Id IN:TriggerNewValues.keyset()])
{
if((ct.Notification_Type__c == 'New Employee') || (ct.Notification_Type__c =='New Contractor'))
{
/* ------------For New PC SETUP------------- */
c.add(new Case(ContactId = ct.Id,AccountId = ct.AccountId,Type = 'PC SETUP_(New/Reused;Desktops,Laptops)',Status='Assigned',OwnerId = '00G400000015Yoo',Origin ='Email',
Subject = 'New PC Setup :'+ct.Name+'- Start Date :'+string.valueof(ct.Start_Date__c),
Description = 'Name :'+ ct.Name+'\r\n\r\nManager :'+ct.Manager_Name__r.Name+'\r\n\r\nEmployee Type :'+ct.EmployeeType__c));
}
}
insert c;
}
}
So if this manager is added to case team then all the updates like case comments , case close, case creation can be sent to manager for his contact through WFR, but main point is adding manager to the case, i have case team member role called Managers and manager has to be added to this role.
TIA!
First fetch this c.Manager_Name__r.Id from contact then
new Case( Case_MangerField__C = c.Manager_Name__r.Id ,
I hope will work for you
I guess this one adds the manager name to case, but it doesn't adds to the case team ryte