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
Sanjay ShroffSanjay Shroff 

The following code goes over all opportunities updated in a transaction and updates their Type field to "Renewal" if the owner's role contains the string "Customer"

Sanjay ShroffSanjay Shroff

list<Opportunity> oppsToUpdate=new list<Opportunity>();
for (Opportunity opp :opps){
if (opp.Owner.UserRole.Name!=null&&opp.Owner.UserRole.Name.contains('Customer')){
opp.Type='Renewal';
oppsToUpdate.add(opp);
}
}
if (!oppsToUpdate.isEmpty())
update oppsToUpdate;

Based on the code above as a reference point, write a piece of code that goes over all
opportunities in a transaction, checks whether the Type field is "New Deal" and updates the
Amount field to 30,000, but only if it's current value is below 30,000 (i.e. if the amount is 42,000,
the system will not update the amount, but if the amount is 10,000 it will be updated to 30,000).
In addition, if the amount is not a multiple of 100, the system will update the amount to the
nearest 100 (i.e. 40,210 will be updated to 40,200).

Thanks,

SS


 
Andrew GAndrew G
Reads like a homework question.
 
Foram Rana RForam Rana R
Hi Sanjay,

Hope you are doing well..!!

Can you please update

if (opp.Owner.UserRole.Name!=null&&opp.Owner.UserRole.Name.contains('Customer')){

to

if (opp.Owner.Name!=null&&opp.Owner.Name.contains('Customer')){

Let me know If it works.

Thanks,
Foram Rana
Sanjay ShroffSanjay Shroff
Hello Rana,

The following code goes over all opportunities updated in a transaction and updates their Type field to "Renewal" if the owner's role contains the string "Customer".
list<Opportunity> oppsToUpdate=new list<Opportunity>();
for (Opportunity opp :opps){
if (opp.Owner.UserRole.Name!=null&&opp.Owner.UserRole.Name.contains('Customer')){
opp.Type='Renewal';
oppsToUpdate.add(opp);
}
}
if (!oppsToUpdate.isEmpty())
update oppsToUpdate;

Based on the code above as a reference point, write a piece of code that goes over all
opportunities in a transaction, checks whether the Type field is "New Deal" and updates the
Amount field to 30,000, but only if it's current value is below 30,000 (i.e. if the amount is 42,000,
the system will not update the amount, but if the amount is 10,000 it will be updated to 30,000).
In addition, if the amount is not a multiple of 100, the system will update the amount to the
nearest 100 (i.e. 40,210 will be updated to 40,200).

Thanks,

SS