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

apex code to check if there is open opportunity on the account
Hi all,
Is there any way where I can check if there is any open opportunity with the close date is in past and if it is there tehn I want to close it before i create a new opportunity on the same account.
Here I am creating the new opportunity using the batch job and my job will run on first day of every month.
Thanks in advance........
Is there any way where I can check if there is any open opportunity with the close date is in past and if it is there tehn I want to close it before i create a new opportunity on the same account.
Here I am creating the new opportunity using the batch job and my job will run on first day of every month.
Thanks in advance........
List<Account> accs =new List<Account>([SELECT Id,Name,
(SELECT Id,CloseDate,Name,IsClosed FROM Opportunities WHERE IsClosed = False AND CloseDate < Today) FROM Account]);
public static List<Opportunity> opps (Opportunity openOpp) {
//Close the open Opportunity
openOpp.StageName = 'Closed Lost';
openOpp.Close_Reason__c = 'Mass_Closure_Lacking_Follow_Up';
Database.update(openOpp);
return opps;
}
I have written something like this. But, it is hitting the limit. Cn you help me in modifying it so that it will not hit the limits anymore
The trigger below will check for a new Opportunity if there are any opportunities on the same Account which are not closed but having closedate before today and updates all the related opportunity records StageName and Close_Reason__c.
Please try below code: Hope this helps! Please mark as best if it does
Thanks