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
Devendra Hirulkar 3Devendra Hirulkar 3 

how to return name instated of id

Hi friends,
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
the below is my trigger


trigger copypro on Subsc__c (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
  }

  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called Quotes__r (not Quote__r) but check
  //You only need to select the child quotes if you are going to do something for example checking whether the quote in the trigger is the latest
  Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c  FROM Subscs__r) FROM Account WHERE ID IN :listIds]);

  for (Subsc__c sub : Trigger.new)
  {
     Account ac = Acc.get(sub.Company_Name__c);
     ac.Product_Name__c=sub.Product__c;
  }

  update Acc.values();
}
thanks..
Shashikant SharmaShashikant Sharma
User related field instead of direct lookup reference field.

Change your query to use Product__r.Name

Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__r.Name  FROM Subscs__r) FROM Account WHERE ID IN :listIds]);

and use this Product__r.Name in 

ac.Product_Name__c= sub.Product__r.Name;

Let me know if you still see issue.
 
Devendra Hirulkar 3Devendra Hirulkar 3
hello shashikant
i am create same as your querry like used Product__r.name instad of Product__c
but by using this it  not copy the product name
so what i do know
thanks
devendra
Devendra Hirulkar 3Devendra Hirulkar 3
* hello shashikanti am create same as your querry like used Product__r.name instad of Product__cbut by using this it not copy the product nameso what i do knowthanksdevendra*
Shashikant SharmaShashikant Sharma
Did you change the code of assignment to the field 

ac.Product_Name__c= sub.Product__r.Name;

Please copy the new code if it is still not working.