You need to sign in to do that
Don't have an account?
Trigger Error
HI All,
I have written trigger on School_del__c, that will be updated phone number filed in acoount. but Now I am creating a record in School_del__c i am getting errormeassage like
""Apex trigger UpdatephoneNumber caused an unexpected exception, contact your administrator: UpdatephoneNumber: execution of AfterInsert caused by: System.StringException: Invalid id: 467894: Trigger.UpdatephoneNumber: line 6, column 1"
the trigger code is
trigger UpdatephoneNumber on School_del__c (after insert ,after update) {
set<id> ss=new set<id>();
for(School_del__c sc:trigger.new) {
if(sc.PhoneNumber__c == null || sc.PhoneNumber__c != null) {
ss.add(sc.PhoneNumber__c );
}
}
map<id, Account> app=new map<id, Account>();
List<Account> accountsToUpdate = new List<Account>();
for(account a:[select id,phone from account where id in:ss limit 50000])
app.put(a.id, a);
for(School_del__c sc:trigger.new) {
if(sc.PhoneNumber__c == null ||sc.PhoneNumber__c != null) {
Account acc = app.get(sc.PhoneNumber__c );
acc.phone = sc.PhoneNumber__c;
accountsToUpdate.add(acc);
}
}
if(!accountsToUpdate.isEmpty()) {
update accountsToUpdate;
}
}
any one can help to solve this error
Thanks
Nageswara Reddy.
Hi,
You are making query on Account. So inside the where clause you are checking the id field with a list which store the phone number. So you have to make the below changes:
set<string> ss=new set<string>(); and
for(account a:[select id,phone from account where phone in:ss limit 50000])
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
U create a set of ID i.e "set<id> ss=new set<id>();"
Then u put phone number in it
ss.add(sc.PhoneNumber__c );
// i belive PhoneNumber__c fields dose not have ID of account??
& the u pass these phoneset in to Id in select query
for(account a:[select id,phone from account where id in:ss limit 50000])
& if PhoneNumber__c field have the account id
then at line number 19 u write
acc.phone = sc.PhoneNumber__c;
& if u updating or inseritng any record in trigger i perfer u use before trigger
I belive this is what u want
u have a lookup of account in School_del__c
& when user insert the School_del__c rec u want to update the parent record phone number field with the phone number fields at child ???
If yes just let me know i give u a simple code
HI
Yes I Have already relationship with between them , Now i want update phone(Filel)d of with my custom object Phone number .
Thanks Nageswara Reddy
Hi ankit,
I ahve done with u r modification , but still I am getting same error., do u provide any alternate solution for that
Thanks,
Nageswara
I belive this is what u want
u have a lookup of account in School_del__c
& when user insert the School_del__c rec u want to update the parent record phone number field with the phone number fields at child ???
If yes just let me know i give u a simple code