
답변 2개
Hi ECorona,Below is the sample code which I have tested in my org and it is working fine. BookMaster__c is Lookup field in Test__c Object.
I hope it helps you.Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.trigger UpdateOnLookupChange on Test__c (before insert, before update) {
List<ID> OppIds = New List<ID>();
Map<Id,Book__c> promap = new Map<Id,Book__c>();
for(Test__c o : Trigger.new){
OppIds.add(o.BookMaster__c);
}
promap = new Map<Id, Book__c>([SELECT id, Name FROM Book__c WHERE ID IN :OppIds]);
for(Test__c c : Trigger.new) {
if(c.BookMaster__c != null) {
Book__c b = promap.get(c.BookMaster__c);
b.Name='Khan';
}
}
update promap.values();
}
Thanks and Regards,
Khan Anas