You need to sign in to do that
Don't have an account?

I have two object like Contact and Account if Create a Contact it will be automatically Create the Account . But i got some error in my code please let me know that is the solution .
trigger updatepho on Contact (after insert){
List<Account> acc = new List<Account>();
for(Contact con:trigger.new){
if(con.AccountId == null){
Account a = [select Id,Phone,(select Id,Phone from Contacts) from Account where Phone =: con.Phone];
a.Name = con.LastName;
a.Phone = con.Phone;
a.Amount__c = 25;
acc.add(a);
}
}
insert acc;
}
This is my error descripation :Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updatepho caused an unexpected exception, contact your administrator: updatepho: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.updatepho: line 5, column 1
List<Account> acc = new List<Account>();
for(Contact con:trigger.new){
if(con.AccountId == null){
Account a = [select Id,Phone,(select Id,Phone from Contacts) from Account where Phone =: con.Phone];
a.Name = con.LastName;
a.Phone = con.Phone;
a.Amount__c = 25;
acc.add(a);
}
}
insert acc;
}
This is my error descripation :Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updatepho caused an unexpected exception, contact your administrator: updatepho: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.updatepho: line 5, column 1
please check below code once :
Thanks
Varaprasad