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
shweta raghav 13shweta raghav 13 

how to update sso field when opportunity update,my trigger is work only at the time of creation of opportunity

trigger PracticeFrmOpp on SSO__c (before insert,before update) {
    Set<Id> accIds = new Set<Id>();
    
    for(SSO__c sso :trigger.new) {
        accIds.add(sso.Opportunity_Name__c);
    }   
    Map<Id,opportunity> mappractice = new Map<Id,opportunity>([select id, Practiceu__c from opportunity
                                                                where id in :accIds]);
    for(SSO__c sso:trigger.new) {
        if(mappractice != null && mappractice .containsKey(sso.Opportunity_Name__c)) {
            opportunity OppRecord = mappractice .get(sso.Opportunity_Name__c);
            sso.Practice_test__c= OppRecord .Practiceu__c ;
        }
    }
}
Best Answer chosen by shweta raghav 13
Srinivasa Chary TaduriSrinivasa Chary Taduri
Trigger should be on Opportunity object (after update event).

Trigger TriggerOnOppty on Opportunity(after update)
{
    List<SSO__c> vLstSSO = [Select Id, Opportunity_Name__c, Practice_test__c from SSO__c where Opportunity_Name__c In: Trigger.new];
    
    for(Opportunity vOppty: Trigger.new)
    {
        Opportunity vOpptyOld = Trigger.OldMap.get(vOppty.Id);
        if(vOppty.Practiceu__c != vOpptyOld.Practiceu__c)
        {
            for(SSO__c vSSO:  vLstSSO)
            {
                if(vOppty.Id == vSSO.Opportunity_Name__c)
                {
                    vSSO.Practice_test__c = vOppty.Practiceu__c;
                }
            }
        }
    }
    
    if(!vLstSSO.isEmpty())
    {
        update vLstSSO;
    }
    
}


Please mark it as best answer.