You need to sign in to do that
Don't have an account?
sathi
pls give solution
hi, i have an application library management and i have three fields like bookid,book name ,author name.......my problem is when i entered the book id ,the fields book name and author name should be updated with book name and author name regarding with book id.......
Trigger updateRelated Fields on Object__c(before insert,before update){
List<Id> bookIds = new List<Id>();
for(Object__c obj : trigger.new){
bookIds.add(obj.book__c); //assuming the API name for bookid is book__c
}
List<Book__c> bookList = [select book__r.name,book__r.authorname__c from Book__c where id in:bookIds];
}
for(Object__c obj : trigger.new){
obj.bookname__c = bookList[0].book__r.name;
obj.authorname__c = bookList[0].book__r.authorname__c;
}
All Answers
Do you want to update the fields the record is saved,if so you can write an APex Trigger on that object and populate the fields based on book id in insert or update events.
thank you, If you have any example trigger ,can u post me pls
Trigger updateRelated Fields on Object__c(before insert,before update){
List<Id> bookIds = new List<Id>();
for(Object__c obj : trigger.new){
bookIds.add(obj.book__c); //assuming the API name for bookid is book__c
}
List<Book__c> bookList = [select book__r.name,book__r.authorname__c from Book__c where id in:bookIds];
}
for(Object__c obj : trigger.new){
obj.bookname__c = bookList[0].book__r.name;
obj.authorname__c = bookList[0].book__r.authorname__c;
}
thank you i got it ...