You need to sign in to do that
Don't have an account?
Devendra 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..
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..
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.
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
ac.Product_Name__c= sub.Product__r.Name;
Please copy the new code if it is still not working.