You need to sign in to do that
Don't have an account?
Visithra
Wen an opportunity created, update the highest opportunity on account record.
Here is my code,
//1/to get parent unique id
Set<Id> accountIDs=new Set<Id>();
for(Opportunity oppRecord:Trigger.new)
{
if(oppRecord.AccountId!=null)
accountIDs.add(oppRecord.AccountId);
}
//2. parent to child relationship
List<Account> accountList=[Select ID, Rating, Highest_opp_record__c,
(Select ID, StageName, Amount,AccountID FROM Opportunities Where Amount>=50000)
FROM Account Where ID in:accountIDs
];
//3. update the amount in account record
List<Account> accList=new List<Account>();
for(Account accRecord:accountList)
{
accRecord.Highest_opp_record__c=(accRecord.Opportunities).Amount;
accList.add(accRecord);
}
if(accList.size()>0)
update acclist;
}
While creating a record in opportunity am facing the below error:
System.QueryException: List has more than 1 row for assignment to SObject Trigger.OpportunityTriggerAmount: line 27, column 1
//1/to get parent unique id
Set<Id> accountIDs=new Set<Id>();
for(Opportunity oppRecord:Trigger.new)
{
if(oppRecord.AccountId!=null)
accountIDs.add(oppRecord.AccountId);
}
//2. parent to child relationship
List<Account> accountList=[Select ID, Rating, Highest_opp_record__c,
(Select ID, StageName, Amount,AccountID FROM Opportunities Where Amount>=50000)
FROM Account Where ID in:accountIDs
];
//3. update the amount in account record
List<Account> accList=new List<Account>();
for(Account accRecord:accountList)
{
accRecord.Highest_opp_record__c=(accRecord.Opportunities).Amount;
accList.add(accRecord);
}
if(accList.size()>0)
update acclist;
}
While creating a record in opportunity am facing the below error:
System.QueryException: List has more than 1 row for assignment to SObject Trigger.OpportunityTriggerAmount: line 27, column 1
Can you modify your code to handle multiple Opportunity records for each Account and determine the highest amount among them as :
If this information helps, please mark the answer as best. Thank you
You Can Try Below Code Please Mark it As Best Answer If It Helps You
Thank You!