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
Sandeep Reddy 288Sandeep Reddy 288 

Write an apex program, to Auto Populate the AnnualRevenue of the Accounts based on the Industry

Write an apex program, to Auto Populate the AnnualRevenue of the Accounts
        based on the Industry Name as below.
            Industry Name            AnnualRevenue
            ---------------------------------------
                Banking                1,45,00,000
                Finance                2,00,00,000
                Manufacturing        1,90,00,000
                Energy                85,00,000
                Education            90,00,000
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sandeep,

try with below code.
Trigger AnnualRevenueUpdate on Account(before insert,before update){


for(Account acc:trigger.new){

if(acc.Industry =='Banking'){
acc.AnnualRevenue=14500000;
}else if(acc.Industry =='Finance'){
acc.AnnualRevenue=20000000;
}else if(acc.Industry =='Manufacturing'){
acc.AnnualRevenue= 19000000;
}else if(acc.Industry =='Energy'){
acc.AnnualRevenue=8500000;
}else if(acc.Industry =='Education'){
acc.AnnualRevenue=9000000;
}
}

}

If this helps, Please mark it as best answer.

Thanks!!
Sandeep Reddy 288Sandeep Reddy 288
Is this apex class or apex trigger??
I want apex class and anonymous window code 
is it possible 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sandeep,

try with below code in  anonymous window code.
List<Account> acclistupdate = new List<Account>();
for(Account acc:[select id,AnnualRevenue,Industry from Account]){

if(acc.Industry =='Banking'){
acc.AnnualRevenue=14500000;
acclistupdate.add(acc.AnnualRevenue);
}else if(acc.Industry =='Finance'){
acc.AnnualRevenue=20000000;
acclistupdate.add(acc.AnnualRevenue);
}else if(acc.Industry =='Manufacturing'){
acc.AnnualRevenue= 19000000;
acclistupdate.add(acc.AnnualRevenue);
}else if(acc.Industry =='Energy'){
acc.AnnualRevenue=8500000;
acclistupdate.add(acc.AnnualRevenue);
}else if(acc.Industry =='Education'){
acc.AnnualRevenue=9000000;
acclistupdate.add(acc.AnnualRevenue);
}
}

update acclistupdate;

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​
Sandeep Reddy 288Sandeep Reddy 288
Its getting error
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sandeep,

What is the error??

Thanks!!
Sandeep Reddy 288Sandeep Reddy 288
Thank you for your response.