function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sahiti@sfdcsahiti@sfdc 

Can anyone breakdown the code and explain

opps.add(new Opportunity(Name=acct.Name + ' Opportunity ' + k, StageName='Prospecting', CloseDate=System.today().addMonths(1), AccountId=acct.Id));
Best Answer chosen by sahiti@sfdc
Andrew GAndrew G
Hi Sahiti

It looks like adding a new opportunity to a list of opportunities.  With the line by itself its hard to be 100% but I would say:

opps is a list declared list of opportunities
.add is adding to the list
new Opportunity is the new record of object type Opportunity
Name is the Name field on the opportunity
=acct.Name + ' Opportunity ' + k  is setting the value of the name field by using the account Name plus the string Opportunity plus some value k (asuming that acct is an account record somewhere set before the line of code and that k is also set elsewhere)
StageName='Prospecting',  field on opportunity set to string value
CloseDate=System.today().addMonths(1) date field on opportunity set to today's date plus one month
AccountId=acct.Id)  the AccountId on opportunity set to the account record so that the oppty has a relation to the account.



HTH

Andrew