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
ghtjgnhtfgghtjgnhtfg 

Account.Type should be changed upon an Opportunity stage

Hey All,

 

When Opportunity Stage== Received Specimen,

then Account.Type should be changed to "Customer".

 

Is apex trigger used to accomplish the task???Please suggest me. Any code provided, is appreciated.

 

Thanks-- Deepthi

ReidCReidC

It can -- use a trigger to make the change.

 

Docs are here.  YOu can find links to more examples.

ghtjgnhtfgghtjgnhtfg

Thank you!!!

Yes, it can be done with the help of a trigger.

Can you please provide me with the code.

Austin_SteveAustin_Steve

trigger AccountTypeUpdate on Opportunity (after update) {
list<Account> accounts = new List<Account>();
Set<String> accSet = new Set<String>();

for(Opportunity opp : Trigger.new) {
if (opp.StageName == 'A - Closed Won') {
accSet.add(opp.AccountId);
}
}
accounts = [Select ID, type from Account where ID in :accSet];
for(Opportunity opp : Trigger.new){
for(Account acc:accounts){

if(opp.AccountId == acc.Id && opp.StageName == 'A - Closed Won' && opp.Deal_Category__c=='OD'){
acc.type = 'Customer - OD';
}
if (opp.Accountid == acc.id && opp.StageName == 'A - Closed Won' && opp.Deal_Category__c=='Perpetual'){
acc.type = 'Customer';
}
}
}
if(accounts.size() > 0){
update accounts;
}
}

 

ghtjgnhtfgghtjgnhtfg

Thanks a lot Steve!!!

It worked...Thanks