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
Prakhyat sapraPrakhyat sapra 

Create a field on Account called “is_gold”, checkbox, default off Assignment: When an Opportunity is greater than $20k, mark is_gold to TRUE

Create a field on Account called “is_gold”, checkbox, default off Assignment: When an Opportunity is greater than $20k, mark is_gold to TRUE
Best Answer chosen by Prakhyat sapra
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you check the below trigger logic on the Opoortunity object.
 
trigger Opportunity_Amount on Opportunity (after insert, after update) {
  Map<Id, List<Opportunity>> acctIdOpptyListMap = new Map<Id, List<Opportunity>>();
    Set<Id> acctIds = new Set<Id>();
    Set<Id> acctidss= new Set<id>();
    List<Opportunity> opptyList = new List<Opportunity>();
    if(trigger.isUpdate || trigger.isInsert){
        for(Opportunity oppty : trigger.New){
            if(oppty.AccountId != null && oppty.amount>20000){
                acctIds.add(oppty.AccountId);
            }
             if(oppty.AccountId != null && oppty.amount<=20000){
                acctidss.add(oppty.AccountId);
            }
        }    
    }
   
    if(acctIds.size() > 0){
                List<Account> acctList = new List<Account>();
        acctList = [SELECT Is_Gold__c  FROM Account WHERE Id IN: acctIds];
        for(Account acct : acctList){
            //List<Opportunity> tempOpptyList = new List<Opportunity>();
           // tempOpptyList = acctIdOpptyListMap.get(acct.Id);
           // Double totalOpptyAmount = 0;
           
            acct.Is_Gold__c  = true;
        }
        update acctList;
    }
    if(acctidss.size() > 0){
                List<Account> acctLists = new List<Account>();
        acctLists = [SELECT Is_Gold__c  FROM Account WHERE Id IN: acctidss];
        for(Account accts : acctLists){
           // List<Opportunity> tempOpptyList = new List<Opportunity>();
           // tempOpptyList = acctIdOpptyListMap.get(acct.Id);
           // Double totalOpptyAmount = 0;
           
            accts.Is_Gold__c  = false;
        }
        update acctLists;
    }
}

If this solution helps, please mark it as best answer.

Thanks,

 

All Answers

satish palsatish pal
Hi @prakhat sapra you can achieve this via flow, create the flow on the opportunity and check the Opportunity amount, if it is greater then 20k, then get the account record from the opportunity and update the is_gold to true
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you check the below trigger logic on the Opoortunity object.
 
trigger Opportunity_Amount on Opportunity (after insert, after update) {
  Map<Id, List<Opportunity>> acctIdOpptyListMap = new Map<Id, List<Opportunity>>();
    Set<Id> acctIds = new Set<Id>();
    Set<Id> acctidss= new Set<id>();
    List<Opportunity> opptyList = new List<Opportunity>();
    if(trigger.isUpdate || trigger.isInsert){
        for(Opportunity oppty : trigger.New){
            if(oppty.AccountId != null && oppty.amount>20000){
                acctIds.add(oppty.AccountId);
            }
             if(oppty.AccountId != null && oppty.amount<=20000){
                acctidss.add(oppty.AccountId);
            }
        }    
    }
   
    if(acctIds.size() > 0){
                List<Account> acctList = new List<Account>();
        acctList = [SELECT Is_Gold__c  FROM Account WHERE Id IN: acctIds];
        for(Account acct : acctList){
            //List<Opportunity> tempOpptyList = new List<Opportunity>();
           // tempOpptyList = acctIdOpptyListMap.get(acct.Id);
           // Double totalOpptyAmount = 0;
           
            acct.Is_Gold__c  = true;
        }
        update acctList;
    }
    if(acctidss.size() > 0){
                List<Account> acctLists = new List<Account>();
        acctLists = [SELECT Is_Gold__c  FROM Account WHERE Id IN: acctidss];
        for(Account accts : acctLists){
           // List<Opportunity> tempOpptyList = new List<Opportunity>();
           // tempOpptyList = acctIdOpptyListMap.get(acct.Id);
           // Double totalOpptyAmount = 0;
           
            accts.Is_Gold__c  = false;
        }
        update acctLists;
    }
}

If this solution helps, please mark it as best answer.

Thanks,

 
This was selected as the best answer