You need to sign in to do that
Don't have an account?
Aryan Jha
Missing return statement required return type: Account Method does not exist or incorrect signature: void add(Contact) from the type Account
public class AccountContacts {
public static Account Accountwithnocontacts()
{
Account a=new Account();
a.Name='aryanjha';
a.Phone='901727392';
return a;
}
public static Account Accountwithcontacts()
{
Account acc=[SELECT Id,name FROM Account WHERE Name='Voltas'];
for(Account a:acc)
{
Contact con=new Contact();
con.firstname='Lucky';
acc.add(con);
return acc;
}
}
}
public static Account Accountwithnocontacts()
{
Account a=new Account();
a.Name='aryanjha';
a.Phone='901727392';
return a;
}
public static Account Accountwithcontacts()
{
Account acc=[SELECT Id,name FROM Account WHERE Name='Voltas'];
for(Account a:acc)
{
Contact con=new Contact();
con.firstname='Lucky';
acc.add(con);
return acc;
}
}
}
1. The error "Missing return statement required return type: Account", is occuring as you have written the 'return acc' inside the loop which should have been written after the For loop, before the method get closed.
2. The error "Method does not exist or incorrect signature: void add(Contact) from the type Account" is occuring because in line no. 15 :- acc.add(con); , you are adding contact data to the account variable and hence the mismatch.
3. Try below code and check if it full fill your requirement :-
Please mark as Best Answer so that it can help others in the future.
Regards,
Priya Ranjan