You need to sign in to do that
Don't have an account?
Akash Shrirame
a.Create a new Custom text field on account named "Top Salary Contacts".
b. Create a custom number type field on Contact with 2 decimal places named "Salary" in Contact.
Find the First 2 Contacts With the Highest Salary and Update the name in a custom field Separated by Comma ( , )
a.Create a new Custom text field on account named "Top Salary Contacts".
b. Create a custom number type field on Contact with 2 decimal places named "Salary" in Contact.
Set<id>idSet = new Set<id>();
for(Contact con : Trigger.new){
if(con.accountid!=null){
idset.add(con.accountid);
}
}
Map<id,contact>mymap = new map<id,contact>();
List<Account>acclist = [Select id,Top_Salary_Contacts__c,(Select id,Name,Salary__c from Contacts where Salary__c != null order by Salary__c desc limit 2)
from account where ID IN:idset];
for(Account acc : acclist){
mymap.put(acc.id,acc.contacts);
}
List<Account>alist = new List<Account>();
for(Account c : acclist){
c.Top_Salary_Contacts__c = mymap.get(c.id).name;
alist.add(c);
}
if(alist.size()>0){
update alist;
}
}
Error : HighestSalary: execution of AfterUpdate caused by: System.QueryException: List has more than 1 row for assignment to SObject External entry point
How to Avoid this and Assign 2 values in 1 field and Separate that values by comma.
try with below code.
If this helps, Please mark it as best answer.
Thanks!!