• bharath kuppala
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies
Please help me in test class for these. Its a critical req, please do the need as soon as possible
thanks in advance
trigger OpportunityBeforeUpdate on Opportunity (before update) {


 System.debug('***********************Before Update');
 
 //Update OQMStage Date
 if(TKT_Case_HelperClass.firstRun){
    if(Util.canTrigger('OQM01'))
    {
        Util.MyLog('## OQM01 begin prepare');
        System.debug('**************OQM01Trigger');
        // Create a list of opportunities to update 
        Map<Id,String> OQM01OpportunitiesID=new Map<Id,String>();
 
   System.debug('**************Trigger New Size'+Trigger.New.size());
   
   
   
         // Fetch Opportunity record updated
         for (Integer i = 0; i < Trigger.New.size(); i++) {
            // Keep Opportunity which have StageName field modified
            if (Trigger.old[i].StageName != Trigger.new[i].StageName) {
                // Add modified opportunity to ListOppty
                 System.debug('**************OQM Not Equal Old'+Trigger.old[i].StageName+'new'+Trigger.new[i].StageName);
                OQM01OpportunitiesID.put(Trigger.new[i].Id,Trigger.new[i].StageName);
            }
            System.debug('**************OQM outside if old'+Trigger.old[i].StageName+'new '+Trigger.new[i].StageName); 
        }
        if(OQM01OpportunitiesID.size()>0){   
              System.debug('**************Call class OQM01Trigger');
          //  OQM01Opportunity.SetOQMStageDate(OQM01OpportunitiesID);
            OQM01Opportunity.updateOQMStageDate(Trigger.new);
            
            
        }
        else 
            Util.MyLog('## OQM01 no Opportunities to treat on '+Trigger.new.size()+' opportunities');
        Util.MyLog('## OQM01 end');
    }
 
 //End
 

/**
//NAJLAE CASE[00017172]
list<Opportunity > LstOpA = new list<Opportunity >();
 for(integer i =0; i<trigger.new.size(); i++) 
  {
        if(Trigger.new[i].Sales_Manager__c!=null)
        {System.debug('CASE[00017172]');
        LstOpA.add(Trigger.new[i]);}
            
  }
if(LstOpA.size()>0) { System.debug('LstOpA.size()'+LstOpA.size()); MAJSalesManageOwner.GetSalesManageEmail(LstOpA);}
// END NAJLAE
**/
//NAJLAE CASE[00021314]
list<Opportunity > LstOpA = new list<Opportunity >();
MAJSalesUser.UpdateInsideSalesName(Trigger.new);
// END NAJLAE


    //AP03 (MLG 28/03/2009) New Opportunity's owner is inserted in AccountTeam with Read access
        //if  Trigger.old[i].OwnerId <> Trigger.new[i].OwnerId  AND Opportunity.RecordType = « CORE - Opportunity Record Type »
    if(Util.canTrigger('AP03')){
        System.Debug('## AP03 begin prepare');
        Opportunity [] AP03Opportunities=new Opportunity[]{};   
      
      for(Integer i = (Trigger.new.size()-1); i >=0 ; i--) {
       if( ((String)Trigger.new[i].OwnerId).substring(0,3) == '005' ){
            Trigger.new[i].Owner__c = Trigger.new[i].OwnerId;}
        else{
            // in case of Queue we clear out our copy field
            Trigger.new[i].Owner__c = null;
        }
        if(Trigger.new[i].OwnerId <> Trigger.old[i].OwnerId)
        if(String.ValueOf(Trigger.new[i].RecordTypeId).equals(Util.RtypeId_CoreOppRtype)) 
        {
            AP03Opportunities.add(Trigger.new[i]);
            
        }   
      } 
        System.Debug('## AP03 end prepare');
        if(AP03Opportunities.size()>0){  
            AP03Opportunity.setUserInAccountTeamReadAccess(AP03Opportunities);
        }else System.Debug('## AP03 no Opportunities to treat on '+Trigger.new.size()+' opportunities');
     }//bypass
     
      //Object (s) : Opportunity

//What : When Opportunity status get "Refused" By Salesman  
//then change Opportunity owner to Telesales who first created the opportunity. 
//Telesales user Id has been stored into the text field "FirstOwnerId__c" 
//on Opportunity thanks to Workflow WF067_Opportunity_First_Owner_Id


if(Util.canTrigger('OPP01'))
{
    Util.MyLog('## OPP01 begin prepare');
    Opportunity [] OPP01Opportunities=new Opportunity[]{};   
  
  for(Integer i = (Trigger.new.size()-1); i >=0 ; i--) 
  {
        System.Debug(Trigger.new[i]);
         if(Trigger.old[i].Opportunity_Sales_Status__c != Trigger.new[i].Opportunity_Sales_Status__c)
          if(Trigger.new[i].Opportunity_Sales_Status__c == Config.EMG_STATUS_GET_REJECTED)
            OPP01Opportunities.add(Trigger.new[i]);
  } 
    Util.MyLog('## OPP01 end prepare');
    if(OPP01Opportunities.size()>0){   
        OPP01Opportunity.modifyOpportunityOwnerOnOpportunity(OPP01Opportunities);
    }else Util.MyLog('## OPP01 no Opportunities to treat on '+Trigger.new.size()+' opportunities');
 }//bypass
   
    
    System.Debug('## AP02 begin prepare');
    Set<Id> SetAccountIds = new Set<Id>();
    Set<Id> SetBPIds = new Set<Id>();
    Map<Id,Account> mapAccount = new Map<Id,Account>();
    Map<Id,Account> mapBP = new Map<Id,Account>();
    for(Opportunity opp: Trigger.new)
    {
         SetAccountIds.add(opp.AccountId);
         if(opp.BusinessPartner__c!=null)SetBPIds.Add(opp.BusinessPartner__c);
    }
    mapAccount = Util.getAccountMapFromOpportunities(SetAccountIds);
    mapBP = Util.getBPMapFromOpportunities(SetBPIds);
    //1:récupérer Opportunity.AccountId
    for(Opportunity opp: Trigger.new)
    {
        if(opp.AccountId!=trigger.oldMap.get(opp.id).accountId)
        {
        
        if(mapAccount.get(opp.AccountId).City__c!=null)opp.AccountCitynew__c=mapAccount.get(opp.AccountId).City__c;else opp.AccountCitynew__c=null;
        if(mapAccount.get(opp.AccountId).State_Province__c!=null)opp.Account_State_Province__c=mapAccount.get(opp.AccountId).State_Province__c;else opp.Account_State_Province__c=null;
        if(mapAccount.get(opp.AccountId).Industry!=null)opp.Account_Vertical__c=mapAccount.get(opp.AccountId).Industry;else opp.Account_Vertical__c=null;
        if(mapAccount.get(opp.AccountId).ZipCode__c!=null)opp.Account_Zip_Code__c=mapAccount.get(opp.AccountId).ZipCode__c;else opp.Account_Zip_Code__c=null;
        
        }
        if(opp.BusinessPartner__c != null && opp.BusinessPartner__c!=trigger.oldMap.get(opp.id).BusinessPartner__c)
        {
        
        if(mapBP.get(opp.BusinessPartner__c).MasterDistributor__c!=null)
        {
            opp.BP_Master_Distributor_text__c=mapBP.get(opp.BusinessPartner__c).MasterDistributor__r.name;
            opp.Nombredejours__c=mapBP.get(opp.BusinessPartner__c).MasterDistributor__r.Nombredejours__c;
            
        }
        else {opp.BP_Master_Distributor_text__c=null; opp.Nombredejours__c=0;}
        if(mapBP.get(opp.BusinessPartner__c).ownerId!=null)opp.BPOwnernew__c=mapBP.get(opp.BusinessPartner__c).owner.firstname+' ' +mapBP.get(opp.BusinessPartner__c).owner.lastname;
        if(mapBP.get(opp.BusinessPartner__c).Parent.Name!=null)opp.Primary_Partner_PARENT_new__c=mapBP.get(opp.BusinessPartner__c).Parent.Name;else opp.Primary_Partner_PARENT_new__c=null;
        if(mapBP.get(opp.BusinessPartner__c).PartnerType__c!=null)opp.BusinessPartnerReportingCategory__c=mapBP.get(opp.BusinessPartner__c).PartnerType__c;else opp.BusinessPartnerReportingCategory__c=null;
       
        }
    }
    
    // Modif MB
    List<Id> opportunitiesIdsWithAttachment = new List<Id>(); 
    for(Id opptyId : Trigger.newMap.keyset()){ 
      if(trigger.newMap.get(opptyId).Configuration_Attached__c == true && trigger.oldMap.get(opptyId).Configuration_Attached__c == false){
        opportunitiesIdsWithAttachment.add(opptyId);
      }
    }
    if(opportunitiesIdsWithAttachment.size()>0){
      OPP01Opportunity.blockOpportunityUpdateWithNoAttachment(opportunitiesIdsWithAttachment, Trigger.newMap);
    }
//NAJLAE_BOM
    List<Id> opptiesToCheck = new List<id>();
    System.debug('##NAJLAE Start ');
         Id EMGS = [Select id , Name from profile where Name='EMG - Direct Touch OQM Simple (NA)'].id;
         System.debug('## EMGS :'+EMGS );
         Id EMGSTas = [Select id , Name from profile where Name='EMG - Direct Touch OQM Simple TAS (NA)'].id;
         System.debug('## EMGSTas :'+EMGSTas );
/**         Id EMGTas = [Select id , Name from profile where Name='ESD - Direct Touch OQM TAS'].id;
//         System.debug('## EMGTas :'+EMGTas );
//         Id Admin = [Select id , Name from profile where Name='System Administrator'].id; 
//        System.debug('## Admin:'+Admin);
        System.debug('## Userinfo.getProfileId():'+Userinfo.getProfileId());**/
//NAJLAE Case[00018531]
list<Opportunity> OppSecondOwner  = new list<Opportunity>(); 
//END NAJLAE Case[00018531]                  
            for(Opportunity oppty : trigger.new){
        System.debug('## oppty.Configuration_Attached__c:'+oppty.Configuration_Attached__c);
        System.debug('## oppty.Configuration_Attached__c:'+oppty.Configuration_Attached__c);  
                System.debug('## oppty.Amount:'+oppty.Amount);          //if(oppty.Configuration_Attached__c == false && oppty.StageName == '4-Offer Made' && oppty.Amount > 50000)
            
                if( (Userinfo.getProfileId()==EMGS||Userinfo.getProfileId()==EMGSTas) && oppty.Configuration_Attached__c == false && (oppty.ALUProbability__c== '100' ||oppty.ALUProbability__c== '60'||oppty.ALUProbability__c== '70'||oppty.ALUProbability__c== '80'||oppty.ALUProbability__c== '90' )   && oppty.Amount >= 50000){
                     opptiesToCheck.add(oppty.id);
                    System.debug('#HERE !!!');
                    }
   
                /**NAJLAE Case[00018531]
                System.debug('oppty.Secondary_Owner__c'+ oppty.Secondary_Owner__c);
                System.debug('oppty.BusinessPartner__c'+ oppty.BusinessPartner__c);
                if(oppty.BusinessPartner__c!=null && oppty.Secondary_Owner__c==null)
                {
                    OppSecondOwner.add(oppty);
                }
                 END Case[00018531]**/
}
    /**NAJLAE Case[00018531]
    System.debug('oppSecondOwner.size()'+ oppSecondOwner.size());
    
    if(oppSecondOwner.size()>0){
        OPP01Opportunity.MAJSecondaryOwner(OppSecondOwner);
    }
     END Case[00018531]**/
     
    System.debug('## opptiesToCheck:'+ opptiesToCheck);
    if(opptiesToCheck.size()>0){
        OPP01Opportunity.blockOpporunityUpdateWithNoValidConfigFile(opptiesToCheck, Trigger.newMap);
    }
// NAJLAE END
        
    // Modif MB
    if(Util.canTrigger('Opp_Ctt_Role')){
        
      if(OPP01Opportunity.bypassContactRoleCheck != true && !OPP01Opportunity.userProfileIsBypassed(Userinfo.getUserId())){  
         Map<id, Opportunity> nonClosedCancelledOpps =  new Map<id, Opportunity>();
        for(Opportunity opp : trigger.new){
          if(opp.StageName != '9-Closed Cancelled' && opp.RunRate__c != true){
            nonClosedCancelledOpps.put(opp.id, opp);
          }
        }
        if(nonClosedCancelledOpps.size()>0){
          OPP01Opportunity.blockOpportunityUpdateWithNoValidContactRole(nonClosedCancelledOpps, trigger.oldMap);  
        }
      }
    }
    
    //Najlae Case[00016890]
    
        MajAmount.MajAmountfromParent(Trigger.New);
    //End Najlae Case[00016890]
    TKT_Case_HelperClass.firstRun=false;
 }
}

@RestResource(urlMapping='/AccountCreation/*')
global with sharing class Ebuy_CreateAccount
{
    @HttpPost
    global Static String doPost(String Company, String Country, String Address1, String Address2, String Zipcode, String City)
    {
       List<RecordType> rt = [SELECT Id,Name  FROM RecordType WHERE DeveloperName = 'EMGCustomerRecordType' LIMIT 1];
       String sid = rt[0].Id;
       String response = '';
       Try
             {
              
                Account acc = new Account();    
              
             acc.RecordTypeId = sid;
               acc.Name = Company;                        
             acc.Street1__c = Address1;            
             acc.Street2__c = Address2;    
             acc.ZipCode__c = Zipcode;
             acc.City__c = City;
             acc.Country__c = Country;                    
                 acc.AccountSource = 'Ebuy';            
                acc.isVerified__c = false;            
           
             insert acc;        
               response = acc.Id;
              
          }
        
        Catch(Exception ex)
         {
             system.debug('@@@ Exception Message = ' + ex.getMessage());
             if((ex.getMessage()).contains('Required fields are missing')) 
             {
                 response = 'REQUIRED FIELD MISSING : '+ex.getMessage();
             }
  
        }
        
      return response;  
    
    }
}
@RestResource(urlMapping='/DealRegistration/*')
global with sharing class Ebuy_DealReg
{
    @HttpPost
    global static String doPost(String Youremail, String DealStatus, String DealName, String CustomerBudget, Decimal ExpectedRevenue,  
                               Date ExpectedBookingDate, String SourcedbyMarketing, Date ProjectImplementationDate,
                                String MarketingCampaign, String DealDescription, String ProposedAlcatelLucentSolution, String Product,
                                String CustomerName, String Address1, String Address2, String ZipCode, String City, String Country, String StateProvince,
                                String Phone, String Salutation, String CustomerContactLastName, String CustomerContactFirstName, String CustomerContactemail,
                                String CustomercontactRole, String NeworExistingCustomer, String ExistingCustomerSolutionVendor, String ExistingCustomerProduct,
                                String CurrentsolutionReseller, String CurrentsolutionRelease, String CurrentSolutionAge, String Additionalcomments) 
    {
        String response = '';
        
        Deal__c del = new Deal__c();
        
        del.BP_Email__c = Youremail;
        del.Status__c = DealStatus;
        del.Name = DealName;
        del.CustomerBudget__c = CustomerBudget;
        //del.CurrencyIsoCode = Currency;
        del.Estimated_Revenue__c = ExpectedRevenue;
        del.Expected_Booking_Date__c = ExpectedBookingDate;
        del.Sourced_By_Marketing__c = SourcedbyMarketing;
        del.Project_Implementation_Date__c = ProjectImplementationDate;
        del.Campaign_Name__c = MarketingCampaign;
        del.Deal_Description__c = DealDescription;
        del.Proposed_Alcatel_Lucent_Solution__c = ProposedAlcatelLucentSolution;
        del.Product__c = Product;
        del.Company_Name__c = CustomerName;
        del.Street1__c = Address1;
        del.Street2__c = Address2;
        del.ZipCode__c = ZipCode;
        del.City__c = City;
        del.Country__c = Country;
        del.State_Province__c = StateProvince;
        del.Phone__c = Phone;
        del.Salutation__c = Salutation;
        del.Customer_Contact_Last_Name__c = CustomerContactLastName;
        del.Customer_Contact_First_Name__c = CustomerContactFirstName;
        del.Customer_Contact_email__c = CustomerContactemail;
        del.Customer_contact_Role__c = CustomercontactRole;
        del.New_or_Existing_Customer__c = NeworExistingCustomer;
        del.Existing_Customer_Solution_Vendor__c = ExistingCustomerSolutionVendor;
        del.Existing_Customer_Product__c = ExistingCustomerProduct;
        del.Current_Release__c = CurrentsolutionReseller;
        del.Current_solution_Release__c = CurrentsolutionRelease;
        del.Solution_Age__c = CurrentSolutionAge;
        del.AdditionalComments__c = Additionalcomments;
        
    try
        {
            Insert del;
            response = del.Id;
        }    
        catch(Exception ex)
        {
            system.debug('@@@ Exception Message = ' + ex.getMessage());
            //response = ex.getMessage();
            if(response.contains('REQUIRED_FIELD_MISSING')) {
                response = 'REQUIRED FIELD MISSING';
              
            }
            else
            {
                response = ex.getMessage();
            }
            
            
        }
        
        return response;        
        
    }
}
@RestResource(urlMapping='/DealRegistration/*')
global with sharing class Ebuy_DealReg
{
    @HttpPost
    global static String doPost(String Youremail, String DealStatus, String DealName, String CustomerBudget, Decimal ExpectedRevenue,  
                               Date ExpectedBookingDate, String SourcedbyMarketing, Date ProjectImplementationDate,
                                String MarketingCampaign, String DealDescription, String ProposedAlcatelLucentSolution, String Product,
                                String CustomerName, String Address1, String Address2, String ZipCode, String City, String Country, String StateProvince,
                                String Phone, String Salutation, String CustomerContactLastName, String CustomerContactFirstName, String CustomerContactemail,
                                String CustomercontactRole, String NeworExistingCustomer, String ExistingCustomerSolutionVendor, String ExistingCustomerProduct,
                                String CurrentsolutionReseller, String CurrentsolutionRelease, String CurrentSolutionAge, String Additionalcomments) 
    {
        Deal__c del = new Deal__c();
        
        del.BP_Email__c = Youremail;
        del.Status__c = DealStatus;
        del.Name = DealName;
        del.CustomerBudget__c = CustomerBudget;
        //del.CurrencyIsoCode = Currency;
        del.Estimated_Revenue__c = ExpectedRevenue;
        del.Expected_Booking_Date__c = ExpectedBookingDate;
        del.Sourced_By_Marketing__c = SourcedbyMarketing;
        del.Project_Implementation_Date__c = ProjectImplementationDate;
        del.Campaign_Name__c = MarketingCampaign;
        del.Deal_Description__c = DealDescription;
        del.Proposed_Alcatel_Lucent_Solution__c = ProposedAlcatelLucentSolution;
        del.Product__c = Product;
        del.Company_Name__c = CustomerName;
        del.Street1__c = Address1;
        del.Street2__c = Address2;
        del.ZipCode__c = ZipCode;
        del.City__c = City;
        del.Country__c = Country;
        del.State_Province__c = StateProvince;
        del.Phone__c = Phone;
        del.Salutation__c = Salutation;
        del.Customer_Contact_Last_Name__c = CustomerContactLastName;
        del.Customer_Contact_First_Name__c = CustomerContactFirstName;
        del.Customer_Contact_email__c = CustomerContactemail;
        del.Customer_contact_Role__c = CustomercontactRole;
        del.New_or_Existing_Customer__c = NeworExistingCustomer;
        del.Existing_Customer_Solution_Vendor__c = ExistingCustomerSolutionVendor;
        del.Existing_Customer_Product__c = ExistingCustomerProduct;
        del.Current_Release__c = CurrentsolutionReseller;
        del.Current_solution_Release__c = CurrentsolutionRelease;
        del.Solution_Age__c = CurrentSolutionAge;
        del.AdditionalComments__c = Additionalcomments;
        
    Insert del;

    return del.Id;        
        
    }
}
@RestResource(urlMapping='/ContactCRDID/*')
global with sharing class Ebuy_API
{
  @HttpGet
   global static List<Opportunity> doGet()
   {
      RestRequest request = RestContext.request;
        Integer ConCRD= Integer.valueof(request.requestURI.substring(request.requestURI.lastIndexOf('/')+1));
        List<Opportunity> result =  [Select StageName, PrimaryBPCRDID__c, Opportunnity_Source__c, OpportunityNumber__c, Name, 
                                     LastModifiedDate, Id, CreatedDate, Amount, Account.Name, CloseDate From Opportunity  
                                     where PrimaryBPCRDID__c =: ConCRD AND (((NOT StageName  LIKE '9-Closed%') AND 
                                     (NOT StageName  LIKE '8-Closed%')) OR (StageName  LIKE '8-Closed%' AND 
                                     CloseDate > LAST_N_MONTHS:1 )) ];  
       
       return result;
   }
 
}
  String  records ='Select id,Approval_Matrix__C,Approval_Routing_Note__c from Approval__C where Approval_Matrix__C=null';
I am able to query these fields Approval_Matrix__C( Ready Only)   , Approval_Routing_Note__c (Editable) in Query Editor these fields have some data but i am not able to query in in code.
Please help me in test class for these. Its a critical req, please do the need as soon as possible
thanks in advance
trigger OpportunityBeforeUpdate on Opportunity (before update) {


 System.debug('***********************Before Update');
 
 //Update OQMStage Date
 if(TKT_Case_HelperClass.firstRun){
    if(Util.canTrigger('OQM01'))
    {
        Util.MyLog('## OQM01 begin prepare');
        System.debug('**************OQM01Trigger');
        // Create a list of opportunities to update 
        Map<Id,String> OQM01OpportunitiesID=new Map<Id,String>();
 
   System.debug('**************Trigger New Size'+Trigger.New.size());
   
   
   
         // Fetch Opportunity record updated
         for (Integer i = 0; i < Trigger.New.size(); i++) {
            // Keep Opportunity which have StageName field modified
            if (Trigger.old[i].StageName != Trigger.new[i].StageName) {
                // Add modified opportunity to ListOppty
                 System.debug('**************OQM Not Equal Old'+Trigger.old[i].StageName+'new'+Trigger.new[i].StageName);
                OQM01OpportunitiesID.put(Trigger.new[i].Id,Trigger.new[i].StageName);
            }
            System.debug('**************OQM outside if old'+Trigger.old[i].StageName+'new '+Trigger.new[i].StageName); 
        }
        if(OQM01OpportunitiesID.size()>0){   
              System.debug('**************Call class OQM01Trigger');
          //  OQM01Opportunity.SetOQMStageDate(OQM01OpportunitiesID);
            OQM01Opportunity.updateOQMStageDate(Trigger.new);
            
            
        }
        else 
            Util.MyLog('## OQM01 no Opportunities to treat on '+Trigger.new.size()+' opportunities');
        Util.MyLog('## OQM01 end');
    }
 
 //End
 

/**
//NAJLAE CASE[00017172]
list<Opportunity > LstOpA = new list<Opportunity >();
 for(integer i =0; i<trigger.new.size(); i++) 
  {
        if(Trigger.new[i].Sales_Manager__c!=null)
        {System.debug('CASE[00017172]');
        LstOpA.add(Trigger.new[i]);}
            
  }
if(LstOpA.size()>0) { System.debug('LstOpA.size()'+LstOpA.size()); MAJSalesManageOwner.GetSalesManageEmail(LstOpA);}
// END NAJLAE
**/
//NAJLAE CASE[00021314]
list<Opportunity > LstOpA = new list<Opportunity >();
MAJSalesUser.UpdateInsideSalesName(Trigger.new);
// END NAJLAE


    //AP03 (MLG 28/03/2009) New Opportunity's owner is inserted in AccountTeam with Read access
        //if  Trigger.old[i].OwnerId <> Trigger.new[i].OwnerId  AND Opportunity.RecordType = « CORE - Opportunity Record Type »
    if(Util.canTrigger('AP03')){
        System.Debug('## AP03 begin prepare');
        Opportunity [] AP03Opportunities=new Opportunity[]{};   
      
      for(Integer i = (Trigger.new.size()-1); i >=0 ; i--) {
       if( ((String)Trigger.new[i].OwnerId).substring(0,3) == '005' ){
            Trigger.new[i].Owner__c = Trigger.new[i].OwnerId;}
        else{
            // in case of Queue we clear out our copy field
            Trigger.new[i].Owner__c = null;
        }
        if(Trigger.new[i].OwnerId <> Trigger.old[i].OwnerId)
        if(String.ValueOf(Trigger.new[i].RecordTypeId).equals(Util.RtypeId_CoreOppRtype)) 
        {
            AP03Opportunities.add(Trigger.new[i]);
            
        }   
      } 
        System.Debug('## AP03 end prepare');
        if(AP03Opportunities.size()>0){  
            AP03Opportunity.setUserInAccountTeamReadAccess(AP03Opportunities);
        }else System.Debug('## AP03 no Opportunities to treat on '+Trigger.new.size()+' opportunities');
     }//bypass
     
      //Object (s) : Opportunity

//What : When Opportunity status get "Refused" By Salesman  
//then change Opportunity owner to Telesales who first created the opportunity. 
//Telesales user Id has been stored into the text field "FirstOwnerId__c" 
//on Opportunity thanks to Workflow WF067_Opportunity_First_Owner_Id


if(Util.canTrigger('OPP01'))
{
    Util.MyLog('## OPP01 begin prepare');
    Opportunity [] OPP01Opportunities=new Opportunity[]{};   
  
  for(Integer i = (Trigger.new.size()-1); i >=0 ; i--) 
  {
        System.Debug(Trigger.new[i]);
         if(Trigger.old[i].Opportunity_Sales_Status__c != Trigger.new[i].Opportunity_Sales_Status__c)
          if(Trigger.new[i].Opportunity_Sales_Status__c == Config.EMG_STATUS_GET_REJECTED)
            OPP01Opportunities.add(Trigger.new[i]);
  } 
    Util.MyLog('## OPP01 end prepare');
    if(OPP01Opportunities.size()>0){   
        OPP01Opportunity.modifyOpportunityOwnerOnOpportunity(OPP01Opportunities);
    }else Util.MyLog('## OPP01 no Opportunities to treat on '+Trigger.new.size()+' opportunities');
 }//bypass
   
    
    System.Debug('## AP02 begin prepare');
    Set<Id> SetAccountIds = new Set<Id>();
    Set<Id> SetBPIds = new Set<Id>();
    Map<Id,Account> mapAccount = new Map<Id,Account>();
    Map<Id,Account> mapBP = new Map<Id,Account>();
    for(Opportunity opp: Trigger.new)
    {
         SetAccountIds.add(opp.AccountId);
         if(opp.BusinessPartner__c!=null)SetBPIds.Add(opp.BusinessPartner__c);
    }
    mapAccount = Util.getAccountMapFromOpportunities(SetAccountIds);
    mapBP = Util.getBPMapFromOpportunities(SetBPIds);
    //1:récupérer Opportunity.AccountId
    for(Opportunity opp: Trigger.new)
    {
        if(opp.AccountId!=trigger.oldMap.get(opp.id).accountId)
        {
        
        if(mapAccount.get(opp.AccountId).City__c!=null)opp.AccountCitynew__c=mapAccount.get(opp.AccountId).City__c;else opp.AccountCitynew__c=null;
        if(mapAccount.get(opp.AccountId).State_Province__c!=null)opp.Account_State_Province__c=mapAccount.get(opp.AccountId).State_Province__c;else opp.Account_State_Province__c=null;
        if(mapAccount.get(opp.AccountId).Industry!=null)opp.Account_Vertical__c=mapAccount.get(opp.AccountId).Industry;else opp.Account_Vertical__c=null;
        if(mapAccount.get(opp.AccountId).ZipCode__c!=null)opp.Account_Zip_Code__c=mapAccount.get(opp.AccountId).ZipCode__c;else opp.Account_Zip_Code__c=null;
        
        }
        if(opp.BusinessPartner__c != null && opp.BusinessPartner__c!=trigger.oldMap.get(opp.id).BusinessPartner__c)
        {
        
        if(mapBP.get(opp.BusinessPartner__c).MasterDistributor__c!=null)
        {
            opp.BP_Master_Distributor_text__c=mapBP.get(opp.BusinessPartner__c).MasterDistributor__r.name;
            opp.Nombredejours__c=mapBP.get(opp.BusinessPartner__c).MasterDistributor__r.Nombredejours__c;
            
        }
        else {opp.BP_Master_Distributor_text__c=null; opp.Nombredejours__c=0;}
        if(mapBP.get(opp.BusinessPartner__c).ownerId!=null)opp.BPOwnernew__c=mapBP.get(opp.BusinessPartner__c).owner.firstname+' ' +mapBP.get(opp.BusinessPartner__c).owner.lastname;
        if(mapBP.get(opp.BusinessPartner__c).Parent.Name!=null)opp.Primary_Partner_PARENT_new__c=mapBP.get(opp.BusinessPartner__c).Parent.Name;else opp.Primary_Partner_PARENT_new__c=null;
        if(mapBP.get(opp.BusinessPartner__c).PartnerType__c!=null)opp.BusinessPartnerReportingCategory__c=mapBP.get(opp.BusinessPartner__c).PartnerType__c;else opp.BusinessPartnerReportingCategory__c=null;
       
        }
    }
    
    // Modif MB
    List<Id> opportunitiesIdsWithAttachment = new List<Id>(); 
    for(Id opptyId : Trigger.newMap.keyset()){ 
      if(trigger.newMap.get(opptyId).Configuration_Attached__c == true && trigger.oldMap.get(opptyId).Configuration_Attached__c == false){
        opportunitiesIdsWithAttachment.add(opptyId);
      }
    }
    if(opportunitiesIdsWithAttachment.size()>0){
      OPP01Opportunity.blockOpportunityUpdateWithNoAttachment(opportunitiesIdsWithAttachment, Trigger.newMap);
    }
//NAJLAE_BOM
    List<Id> opptiesToCheck = new List<id>();
    System.debug('##NAJLAE Start ');
         Id EMGS = [Select id , Name from profile where Name='EMG - Direct Touch OQM Simple (NA)'].id;
         System.debug('## EMGS :'+EMGS );
         Id EMGSTas = [Select id , Name from profile where Name='EMG - Direct Touch OQM Simple TAS (NA)'].id;
         System.debug('## EMGSTas :'+EMGSTas );
/**         Id EMGTas = [Select id , Name from profile where Name='ESD - Direct Touch OQM TAS'].id;
//         System.debug('## EMGTas :'+EMGTas );
//         Id Admin = [Select id , Name from profile where Name='System Administrator'].id; 
//        System.debug('## Admin:'+Admin);
        System.debug('## Userinfo.getProfileId():'+Userinfo.getProfileId());**/
//NAJLAE Case[00018531]
list<Opportunity> OppSecondOwner  = new list<Opportunity>(); 
//END NAJLAE Case[00018531]                  
            for(Opportunity oppty : trigger.new){
        System.debug('## oppty.Configuration_Attached__c:'+oppty.Configuration_Attached__c);
        System.debug('## oppty.Configuration_Attached__c:'+oppty.Configuration_Attached__c);  
                System.debug('## oppty.Amount:'+oppty.Amount);          //if(oppty.Configuration_Attached__c == false && oppty.StageName == '4-Offer Made' && oppty.Amount > 50000)
            
                if( (Userinfo.getProfileId()==EMGS||Userinfo.getProfileId()==EMGSTas) && oppty.Configuration_Attached__c == false && (oppty.ALUProbability__c== '100' ||oppty.ALUProbability__c== '60'||oppty.ALUProbability__c== '70'||oppty.ALUProbability__c== '80'||oppty.ALUProbability__c== '90' )   && oppty.Amount >= 50000){
                     opptiesToCheck.add(oppty.id);
                    System.debug('#HERE !!!');
                    }
   
                /**NAJLAE Case[00018531]
                System.debug('oppty.Secondary_Owner__c'+ oppty.Secondary_Owner__c);
                System.debug('oppty.BusinessPartner__c'+ oppty.BusinessPartner__c);
                if(oppty.BusinessPartner__c!=null && oppty.Secondary_Owner__c==null)
                {
                    OppSecondOwner.add(oppty);
                }
                 END Case[00018531]**/
}
    /**NAJLAE Case[00018531]
    System.debug('oppSecondOwner.size()'+ oppSecondOwner.size());
    
    if(oppSecondOwner.size()>0){
        OPP01Opportunity.MAJSecondaryOwner(OppSecondOwner);
    }
     END Case[00018531]**/
     
    System.debug('## opptiesToCheck:'+ opptiesToCheck);
    if(opptiesToCheck.size()>0){
        OPP01Opportunity.blockOpporunityUpdateWithNoValidConfigFile(opptiesToCheck, Trigger.newMap);
    }
// NAJLAE END
        
    // Modif MB
    if(Util.canTrigger('Opp_Ctt_Role')){
        
      if(OPP01Opportunity.bypassContactRoleCheck != true && !OPP01Opportunity.userProfileIsBypassed(Userinfo.getUserId())){  
         Map<id, Opportunity> nonClosedCancelledOpps =  new Map<id, Opportunity>();
        for(Opportunity opp : trigger.new){
          if(opp.StageName != '9-Closed Cancelled' && opp.RunRate__c != true){
            nonClosedCancelledOpps.put(opp.id, opp);
          }
        }
        if(nonClosedCancelledOpps.size()>0){
          OPP01Opportunity.blockOpportunityUpdateWithNoValidContactRole(nonClosedCancelledOpps, trigger.oldMap);  
        }
      }
    }
    
    //Najlae Case[00016890]
    
        MajAmount.MajAmountfromParent(Trigger.New);
    //End Najlae Case[00016890]
    TKT_Case_HelperClass.firstRun=false;
 }
}
@RestResource(urlMapping='/DealRegistration/*')
global with sharing class Ebuy_DealReg
{
    @HttpPost
    global static String doPost(String Youremail, String DealStatus, String DealName, String CustomerBudget, Decimal ExpectedRevenue,  
                               Date ExpectedBookingDate, String SourcedbyMarketing, Date ProjectImplementationDate,
                                String MarketingCampaign, String DealDescription, String ProposedAlcatelLucentSolution, String Product,
                                String CustomerName, String Address1, String Address2, String ZipCode, String City, String Country, String StateProvince,
                                String Phone, String Salutation, String CustomerContactLastName, String CustomerContactFirstName, String CustomerContactemail,
                                String CustomercontactRole, String NeworExistingCustomer, String ExistingCustomerSolutionVendor, String ExistingCustomerProduct,
                                String CurrentsolutionReseller, String CurrentsolutionRelease, String CurrentSolutionAge, String Additionalcomments) 
    {
        Deal__c del = new Deal__c();
        
        del.BP_Email__c = Youremail;
        del.Status__c = DealStatus;
        del.Name = DealName;
        del.CustomerBudget__c = CustomerBudget;
        //del.CurrencyIsoCode = Currency;
        del.Estimated_Revenue__c = ExpectedRevenue;
        del.Expected_Booking_Date__c = ExpectedBookingDate;
        del.Sourced_By_Marketing__c = SourcedbyMarketing;
        del.Project_Implementation_Date__c = ProjectImplementationDate;
        del.Campaign_Name__c = MarketingCampaign;
        del.Deal_Description__c = DealDescription;
        del.Proposed_Alcatel_Lucent_Solution__c = ProposedAlcatelLucentSolution;
        del.Product__c = Product;
        del.Company_Name__c = CustomerName;
        del.Street1__c = Address1;
        del.Street2__c = Address2;
        del.ZipCode__c = ZipCode;
        del.City__c = City;
        del.Country__c = Country;
        del.State_Province__c = StateProvince;
        del.Phone__c = Phone;
        del.Salutation__c = Salutation;
        del.Customer_Contact_Last_Name__c = CustomerContactLastName;
        del.Customer_Contact_First_Name__c = CustomerContactFirstName;
        del.Customer_Contact_email__c = CustomerContactemail;
        del.Customer_contact_Role__c = CustomercontactRole;
        del.New_or_Existing_Customer__c = NeworExistingCustomer;
        del.Existing_Customer_Solution_Vendor__c = ExistingCustomerSolutionVendor;
        del.Existing_Customer_Product__c = ExistingCustomerProduct;
        del.Current_Release__c = CurrentsolutionReseller;
        del.Current_solution_Release__c = CurrentsolutionRelease;
        del.Solution_Age__c = CurrentSolutionAge;
        del.AdditionalComments__c = Additionalcomments;
        
    Insert del;

    return del.Id;        
        
    }
}
@RestResource(urlMapping='/ContactCRDID/*')
global with sharing class Ebuy_API
{
  @HttpGet
   global static List<Opportunity> doGet()
   {
      RestRequest request = RestContext.request;
        Integer ConCRD= Integer.valueof(request.requestURI.substring(request.requestURI.lastIndexOf('/')+1));
        List<Opportunity> result =  [Select StageName, PrimaryBPCRDID__c, Opportunnity_Source__c, OpportunityNumber__c, Name, 
                                     LastModifiedDate, Id, CreatedDate, Amount, Account.Name, CloseDate From Opportunity  
                                     where PrimaryBPCRDID__c =: ConCRD AND (((NOT StageName  LIKE '9-Closed%') AND 
                                     (NOT StageName  LIKE '8-Closed%')) OR (StageName  LIKE '8-Closed%' AND 
                                     CloseDate > LAST_N_MONTHS:1 )) ];  
       
       return result;
   }
 
}

hi ,

 

im working on to write test class, in that im facing problem to how to wrire test code for the attachment class. please provide solution for that.

 

 

thakyou.