0
trigger onOpportunity_AddPointofContact on Opportunity (after update)
{
 List<Point_of_Contact__c> getPrimaryLst=[select id,Primary__c from Point_of_Contact__c where Primary__c =:true];
    List<Point_of_Contact__c> insertPointConList=new List<Point_of_Contact__c>();
    for(Opportunity opp:Trigger.new)
    {
        Opportunity oldRec =Trigger.oldMap.get(opp.Id);
        if(oldRec.StageName != opp.StageName && opp.StageName == 'Approved')
        {
           Point_of_Contact__c con=new Point_of_Contact__c();
           ngsCon.Point_of_Contact__c=opp.Program_Officer__c;
           ngsCon.Contact__c=opp.npsp__Primary_Contact__c;
           ngsCon.Type__c='grant';
           ngsCon.Start_Date__c=opp.FGM_Base__Award_Date__c;
            if(getPrimaryLst.size() == 0){
             ngsCon.Primary__c =true;   
            }
           insertPointConList.add(ngsCon);
        }

    }
    if(insertPointConList.size()>0)
    {
        try {
            insert insertPointConList;
            system.debug('====>insertPointConList'+insertPointConList);
           }
        catch (Exception Ex){
            system.debug(Ex);
        }
    }

}

here i wrote the code but inserting duplicate records in Point_of_Contact__c object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.