• Akash Garg 2
  • NEWBIE
  • 69 Points
  • Member since 2016
  • Administrator
  • Trident Group

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 25
    Replies
I have apex class against which test class has been written but while Run test it failed due to 1 errors at 3 levels in test

1. FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [SAP_Sales_Area_Number__c]
Attaching Apex class and test class. 
Help in correcting the test class.
 
public class OpportunityTriggerHandler extends TriggerHandler{

    protected override void beforeInsert(){
        setStandardPricebook();
        setRecordTypeFromLeadConversion();
        populateInfoFromSalesArea();
        distributorOpptyRecordType();
    }
    protected override void beforeUpdate(){        
        setStandardPricebook();//Change 0.2
        stampPlant();
        populateInfoFromSalesArea();      
    }
    protected override void afterInsert(){
    }
    protected override void afterUpdate(){
        updateTangible();
    }
    
    public void stampPlant(){        
        Set<Id> optySet = new Set<Id>();
        List<OpportunityLineItem> finaloptyLineItemList = new List<OpportunityLineItem>();
        for(Opportunity opty : (List<Opportunity>)Trigger.New)
        {           
            Opportunity o = (Opportunity)Trigger.oldMap.get(opty.Id);
            if(o.Plant__c != opty.Plant__c)
            {
                optySet.add(opty.Id);         
            }
        }
        
        if(optySet != null && !optySet.isEmpty())
        {
            List<OpportunityLineItem> optyLineItemList = new List<OpportunityLineItem>([Select Id, Plant__c, OpportunityId from OpportunityLineItem where OpportunityId IN:optySet]);
            for(OpportunityLineItem oli : optyLineItemList)
            {
                Opportunity o = (Opportunity)Trigger.newMap.get(oli.OpportunityId);
                oli.Plant__c = o.Plant__c;
                finaloptyLineItemList.add(oli);
            }
        }
        if(finaloptyLineItemList != null && !finaloptyLineItemList.isEmpty())
        {
            update finaloptyLineItemList;
        }
    }
   
    private void updateTangible(){
      
        List<Opportunity> listOpportunityTriggerNew ;
        Map<Id, Opportunity> oldMap ;
        Map<Id, Decimal> mapOpportunityIdToExpectedRevenueChanged ;
        List<Event> listEvent ;
        //Map<Id, List<Event>> mapOpportunityIdToListEvent ;
        Map<Id, Id> mapEventIdToOpportunityId ;
        List<Id> listTourPlanId ;
        Map<Id, Tour_Plan_TI__C> mapTourPlan ;
        final String eventRecordTypeName = 'Planned' ;

        mapOpportunityIdToExpectedRevenueChanged = new Map<id, Decimal>() ;
        listTourPlanId = new List<Id>() ;
        mapEventIdToOpportunityId = new Map<Id, Id>();

        listOpportunityTriggerNew = (List<Opportunity>)Trigger.New ;
        if(Trigger.isUpdate){ oldMap = (Map<Id, Opportunity>)Trigger.oldMap ; }

        for(Opportunity opportunityNew : listOpportunityTriggerNew){
            Decimal newExpectedRevenue;
            Decimal oldExpectedRevenue;
            newExpectedRevenue = (opportunityNew.ExpectedRevenue!=null)?opportunityNew.ExpectedRevenue:0.0;
            oldExpectedRevenue = ((oldMap.get(opportunityNew.Id)).ExpectedRevenue!=null)?(oldMap.get(opportunityNew.Id)).ExpectedRevenue:0.0;

            //Decimal expectedRevenueChange =  opportunityNew.ExpectedRevenue - (oldMap.get(opportunityNew.Id)).ExpectedRevenue ;
            Decimal expectedRevenueChange = newExpectedRevenue -oldExpectedRevenue ;
            if( expectedRevenueChange != Decimal.valueOf(0) ){
                mapOpportunityIdToExpectedRevenueChanged.put(opportunityNew.Id, expectedRevenueChange);
            }
        }

        if( !mapOpportunityIdToExpectedRevenueChanged.isEmpty() ){

            listEvent = [SELECT Id, WhatId, Opportunity_TI__c 
                            FROM Event
                            WHERE Opportunity_TI__c != null
                            AND Opportunity_TI__c IN :mapOpportunityIdToExpectedRevenueChanged.keySet()
                            AND Status_TI__c != 'Cancelled'
                            AND recordType.Name = :eventRecordTypeName];

            for(Event event : listEvent){
                listTourPlanId.add(event.WhatId);
                mapEventIdToOpportunityId.put(event.Id, event.Opportunity_TI__c) ;
            }

            mapTourPlan = new Map<Id,Tour_Plan_TI__C>([SELECT Id, Tangible__c
                            FROM Tour_Plan_TI__C
                            WHERE Id IN :listTourPlanId
                            ]);

            for(Event event : listEvent){
                if((mapTourPlan.get(event.WhatId)).Tangible__c == null){ (mapTourPlan.get(event.WhatId)).Tangible__c = 0.0 ; }
                (mapTourPlan.get(event.WhatId)).Tangible__c += mapOpportunityIdToExpectedRevenueChanged.get( mapEventIdToOpportunityId.get(event.Id) );
            }

            try{   update mapTourPlan.values();  }  catch(Exception e){ System.debug('Error in updating Tour plan tangible on updating opportunity'+e) ; }


        } //if ends

    }//update Tangible method ends

    private void populateInfoFromSalesArea(){

        List<Opportunity> listOpportunityWithSalesArea = new List<Opportunity>()  ;
        Set<Id> setAccountId = new Set<Id>();
        Set<Id> setSalesArea = new Set<Id>();
        Set<String> setSalesOrg = new Set<String>();
        Map<Id, Sales_Area__c> mapSalesArea = new Map<Id, Sales_Area__c>();

         for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
        
            if( opportunity.Sales_Area__c!=null && opportunity.AccountId!=null){
                listOpportunityWithSalesArea.add(opportunity);
                setAccountId.add(opportunity.AccountId);
                setSalesArea.add(Opportunity.Sales_Area__c);
            }
         }

         mapSalesArea = new Map<Id, Sales_Area__c>([SELECT Id, VKORG__c, VTWEG__c, SPART__c, Division__c, Distribution_Channel__c, Sales_Org__c, Unique_Key__c
                                    FROM Sales_Area__c
                                    WHERE ID IN :setSalesArea 
                                        AND SPART__c!=NULL AND VTWEG__c!=NULL AND VKORG__c!=NULL
                                    ]);
         for(Sales_Area__c salesArea : mapSalesArea.values()){
            setSalesOrg.add(salesArea.VKORG__c);
         }

         if(!setSalesArea.isEmpty() && !setAccountId.isEmpty()){
            
            List<Sales_Area_TI__c> listAccountSalesArea = [SELECT Id, CurrencyISOCode, Account_Name__c, Payment_Terms__c, Price_List__c, Incoterms__c, SAP_Sales_Area_Number__c, Incoterms_2__c,
                                                                          SAP_Sales_Area_Number__r.SPART__c, SAP_Sales_Area_Number__r.VTWEG__c, SAP_Sales_Area_Number__r.VKORG__c, SAP_Sales_Area_Number__r.Unique_Key__c      
                                                                FROM Sales_Area_TI__c
                                                                WHERE Account_Name__c IN :setAccountId AND ( SAP_Sales_Area_Number__c IN :setSalesArea OR SAP_Sales_Area_Number__r.VKORG__c IN :setSalesOrg)
                                                                AND Payment_Terms__c!=NULL AND Account_Name__c!=null AND Incoterms__c!=null AND SAP_Sales_Area_Number__c!=NUll
                                                                AND SAP_Sales_Area_Number__r.SPART__c!=NULL AND SAP_Sales_Area_Number__r.VTWEG__c!=NULL AND SAP_Sales_Area_Number__r.VKORG__c!=NULL 
                                                            ];
            Map<Id, List<Sales_Area_TI__c> > mapAccountToAccountSalesArea = new Map<Id, List<Sales_Area_TI__c> > ();
            
            for(Sales_Area_TI__c accountSalesArea : listAccountSalesArea){
                List<Sales_Area_TI__c> listAccSalesArea = new List<Sales_Area_TI__c>();
                if(mapAccountToAccountSalesArea.containsKey(accountSalesArea.Account_Name__c)) listAccSalesArea = mapAccountToAccountSalesArea.get(accountSalesArea.Account_Name__c);
                listAccSalesArea.add(accountSalesArea);
                mapAccountToAccountSalesArea.put(accountSalesArea.Account_Name__c, listAccSalesArea);
            }                                              

            //System.debug('map'+mapAccountToAccountSalesArea);

            Boolean salesAreaMatched = false;
            for(Opportunity opportunity : listOpportunityWithSalesArea){
                salesAreaMatched = false;
                if(mapAccountToAccountSalesArea.containsKey(opportunity.AccountId)){
                    for(Sales_Area_TI__c accountSalesArea : mapAccountToAccountSalesArea.get(opportunity.AccountId)){
                        if(opportunity.AccountId==accountSalesArea.Account_Name__c){
                            if( opportunity.Sales_Area__c!=null && accountSalesArea.SAP_Sales_Area_Number__c!=null && opportunity.Sales_Area__c==accountSalesArea.SAP_Sales_Area_Number__c ){
                               salesAreaMatched = true; 
                            }
                            else if( (mapSalesArea.get(opportunity.Sales_Area__c)).VKORG__c!=null &&  accountSalesArea.SAP_Sales_Area_Number__r.VKORG__c!=null && (mapSalesArea.get(opportunity.Sales_Area__c)).VKORG__c == accountSalesArea.SAP_Sales_Area_Number__r.VKORG__c){
                                //if(Distri Channel left1 matches && division matches)
                                String opptySalesAreaDistriChannel = (mapSalesArea.get(opportunity.Sales_Area__c)).VTWEG__c;
                                String accountSalesAreaDistriChannel = accountSalesArea.SAP_Sales_Area_Number__r.VTWEG__c;
                                System.debug('opptySalesAreaDistriChannel '+opptySalesAreaDistriChannel+'   accountSalesAreaDistriChannel '+accountSalesAreaDistriChannel);
                                if( opptySalesAreaDistriChannel!=null &&  accountSalesAreaDistriChannel!=null && ((accountSalesAreaDistriChannel.left(2)).right(1))=='0' &&  opptySalesAreaDistriChannel.left(1)==accountSalesAreaDistriChannel.left(1)){
                                    //check division matches
                                    if( (mapSalesArea.get(opportunity.Sales_Area__c)).SPART__c == accountSalesArea.SAP_Sales_Area_Number__r.SPART__c ){
                                        salesAreaMatched = true;
                                    }
                                    else if( accountSalesArea.SAP_Sales_Area_Number__r.SPART__c=='01'){
                                        salesAreaMatched = true;
                                    }
                                }
                            }
                                                       
                            if(salesAreaMatched)
                            {
                                if(Trigger.isInsert){ opportunity.CurrencyISOCode = accountSalesArea.CurrencyISOCode; }
                                opportunity.Account_Sales_Area_TI__c = accountSalesArea.Id;
                                //opportunity.INCO_Term__c = accountSalesArea.Incoterms__c; /* Commented by Trident Team*/
                                if(!String.isBlank(accountSalesArea.Price_List__c))
                                opportunity.Price_List__c = accountSalesArea.Price_List__c;
                               
                              /* Edited by Trident Team */  
                                if(Trigger.isInsert && Trigger.isBefore && opportunity.Payment_Term__c == null && opportunity.INCO_Term__c ==null )
                                {
                                    opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                    opportunity.INCO_Term__c = accountSalesArea.Incoterms__c;
                                }
                                else if(Trigger.isUpdate && Trigger.isBefore)
                                {
                                    Opportunity tempOpty = (Opportunity)Trigger.oldMap.get(opportunity.Id);
                                    if(tempOpty.Sales_Area__c != null && tempOpty.Sales_Area__c != opportunity.Sales_Area__c && tempOpty.Payment_Term__c == opportunity.Payment_Term__c && tempOpty.INCO_Term__c == opportunity.INCO_Term__c )
                                    {
                                        opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                        opportunity.INCO_Term__c = accountSalesArea.Incoterms__c;
                                    }
                                }
                                /*Edited Ends here*/
                                //opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                opportunity.INCO_Term_Location__c = accountSalesArea.Incoterms_2__c;
                                break;
                            }
                        } // account ID match check
                            
                    }//for loop ends
                }

                if(!salesAreaMatched){ opportunity.addError('No such sales area on account');  }
            }//oppty for loop ends

        }//if set not empty
     
    }// populateInfoFromSalesArea ends

    private void setRecordTypeFromLeadConversion(){


        List<RecordType> listRecordType = [SELECT Id, DeveloperName FROM RecordType WHERE sObjectType='Opportunity'];
        Map<String, Id> mapRecordTypeNametoId = new Map<String, Id>();
        for(RecordType recordType : listRecordType){
            mapRecordTypeNametoId.put(recordType.DeveloperName, recordType.Id); 
        }

       System.debug(mapRecordTypeNametoId);

        for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
            if(opportunity.Record_Type_Name_Lead__c!=null){
                System.debug('Record_Type_Name_Lead__c '+opportunity.Record_Type_Name_Lead__c);

                if( opportunity.Record_Type_Name_Lead__c.contains('International Bathrobe') &&  mapRecordTypeNametoId.containsKey('International_Bathrobe_TI')  ){ opportunity.RecordTypeId = mapRecordTypeNametoId.get('International_Bathrobe_TI'); }
                else if( opportunity.Record_Type_Name_Lead__c.contains('International Sheeting') &&  mapRecordTypeNametoId.containsKey('International_Sheeting_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('International_Sheeting_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('International Towel') &&  mapRecordTypeNametoId.containsKey('International_Towel_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('International_Towel_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Domestic Bathrobe') &&  mapRecordTypeNametoId.containsKey('Domestic_Bathrobe_TI')  ){ opportunity.RecordTypeId = mapRecordTypeNametoId.get('Domestic_Bathrobe_TI'); }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Domestic Sheeting') &&  mapRecordTypeNametoId.containsKey('Domestic_Sheeting_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Domestic_Sheeting_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Domestic Towel') &&  mapRecordTypeNametoId.containsKey('Domestic_Towel_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Domestic_Towel_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Yarn') &&  mapRecordTypeNametoId.containsKey('Yarn_TI')   ){ opportunity.RecordTypeId = mapRecordTypeNametoId.get('Yarn_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Paper') && mapRecordTypeNametoId.containsKey('Paper_TI')  ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Paper_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Chemical') && mapRecordTypeNametoId.containsKey('Chemical_TI')  ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Chemical_TI') ; }
            }
        }
    } //setRecordTypeFromLeadConversion ends    

    private void distributorOpptyRecordType(){

        for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
            if(opportunity.Distributor_Opportunity_TI__c){
                User opptyOwner = new User(Id=opportunity.OwnerId);

                System.runAs(opptyOwner){
                    for(Schema.RecordTypeInfo recordTypeInfoObject : Schema.Opportunity.sObjectType.getDescribe().getRecordTypeInfos()) {
                        if(recordTypeInfoObject.isDefaultRecordTypeMapping() ) {
                            opportunity.RecordTypeId = recordTypeInfoObject.getRecordTypeId();
                        }
                    } 
                }
            }
        }//for loop ends
    
    }  //distributorOpptyRecordType ends

    private void setStandardPricebook(){

        Id idstandardPriceBook = '01sD0000000FXh7IAG'; //dummy value for initiation

        try{
            idstandardPriceBook = [SELECT Id FROM PriceBook2 WHERE IsStandard = true AND Unique_Key__c='StandardPricebook'][0].Id;
        }
        catch(Exception e){
            if(Test.isRunningTest()){
                idstandardPriceBook = Test.getStandardPricebookId();
            }
        }
        for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
            opportunity.Pricebook2Id = idstandardPriceBook;
        }
    }//setStandardPricebook ends
}//Opportunity trigger handler class ends
 
@isTest
public class OpportunityTriggerTest {

    @testSetup
    public static void setup(){     

        TestDataFactory.createTriggerCustomSettings();
        
    }//setup ends



    public static testmethod void testUpdateTangible(){
        //create opportunity
        //create tour plan
        //create event

        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        insert account;

        Opportunity opportunity = (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        insert opportunity;

        Tour_Plan_TI__c tourPlan = (Tour_Plan_TI__c)SmartFactory.createSObject('Tour_Plan_TI__c');
        tourPlan.Status__c = 'Approved';
        tourPlan.Start_Date__c = (Date.today()).addDays(1);
        tourPlan.End_Date__c = (Date.today()).addDays(3);
        insert tourPlan;

        Event event = ((List<Event>)TestDataFactory.createPlannedEvents(1))[0];
        event.ActivityDate = (Date.today()).addDays(2);
        event.ActivityDateTime = (Date.today()).addDays(2);
        event.WhatId = tourPlan.Id;
        event.Opportunity_TI__c = opportunity.Id;
        insert event;

        //update the Opportunity
        opportunity.Amount = 112;
        update opportunity;

            
    }//testupdateTangible ends


    public static testmethod void testSetRecordTypeFromLeadConversion(){
        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];

        insert account;

        
        List<Opportunity> listOpportunity = (List<Opportunity>)SmartFactory.createSObjectList('Opportunity',false,5);

        List<Schema.RecordTypeInfo> leadRecordTypes = Lead.getSObjectType().getDescribe().getRecordTypeInfos();

        Set<Id> setOfRecordTypeIdUsed = new Set<Id>();

        for(Opportunity opportunity : listOpportunity){

            opportunity.AccountId = account.Id;

            for (Schema.RecordTypeInfo recordType : leadRecordTypes) {
                    if (recordType.isAvailable() && recordType.isActive()) {
                        if(!setOfRecordTypeIdUsed.contains(recordType.getRecordTypeId())){ //check if same record type is used already
                            opportunity.put('Record_Type_Name_Lead__c', recordType.getName());
                            setOfRecordTypeIdUsed.add(recordType.getRecordTypeId());
                            break;
                        }                       
                    }
                }
        }

        insert listOpportunity;

    }


    public static testmethod void testDistributorOpptyRecordType(){
        
        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];

        insert account;

        
        
        Opportunity opportunity = (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        opportunity.Distributor_Opportunity_TI__c = true;
        //insert opportunity;


    }

    //same sales area direct match
    public static testmethod void testPopulateInfoFromSalesArea(){
        Sales_Area__c salesArea = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        insert salesArea;

        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        insert account;

        SmartFactory.FillAllFields = true;
        Payment_Terms__c paymentTerms = (Payment_Terms__c)SmartFactory.createSObject('Payment_Terms__c');
        insert paymentTerms;
        Sales_Area_TI__c accountSalesArea = (Sales_Area_TI__c)SmartFactory.createSObject('Sales_Area_TI__c');
        SmartFactory.FillAllFields = false;
        accountSalesArea.Account_Name__c = account.Id;
        accountSalesArea.SAP_Sales_Area_Number__c = salesArea.Id;
        accountSalesArea.Payment_Terms__c = paymentTerms.Id;
        accountSalesArea.Incoterms__c = 'CFR';
        insert accountSalesArea;

        //same sales area direct match
        Opportunity opportunity =  (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        opportunity.Sales_Area__c= salesArea.Id;
        insert opportunity;
    }


    //different sales area fuzzy match
    public static testmethod void testPopulateInfoFromSalesArea2(){     
        Sales_Area__c salesArea1 = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        salesArea1.VKORG__c = 'same';
        salesArea1.VTWEG__c='10';
        salesArea1.SPART__c='01';
        insert salesArea1;

        //division 01 match
        Sales_Area__c salesArea2 = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        salesArea2.VKORG__c = 'same';
        salesArea2.VTWEG__c='12';
        salesArea2.SPART__c='23';
        insert salesArea2;

        //division exact match
        Sales_Area__c salesArea3 = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        salesArea3.VKORG__c = 'same';
        salesArea3.VTWEG__c='12';
        salesArea3.SPART__c='01';
        insert salesArea3;



        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        insert account;

        SmartFactory.FillAllFields = true;
        Payment_Terms__c paymentTerms = (Payment_Terms__c)SmartFactory.createSObject('Payment_Terms__c');
        insert paymentTerms;
        Sales_Area_TI__c accountSalesArea = (Sales_Area_TI__c)SmartFactory.createSObject('Sales_Area_TI__c');
        SmartFactory.FillAllFields = false;
        accountSalesArea.Account_Name__c = account.Id;
        accountSalesArea.SAP_Sales_Area_Number__c = salesArea1.Id;
        accountSalesArea.Payment_Terms__c = paymentTerms.Id;

        insert accountSalesArea;

        Opportunity opportunity =  (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        opportunity.Sales_Area__c= salesArea2.Id;
        insert opportunity;


        Opportunity opportunity2 =  (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity2.AccountId = account.Id;
        opportunity2.Sales_Area__c= salesArea3.Id;
        insert opportunity2;



    }

    public static testmethod void testStampPlant(){

        

        String productCode1 = 'A1';


        //Product
        Product2 product = new Product2(Name='TestProduct 1', SAP_Product_Code__c = productCode1, isActive=true);
        insert product;

        PriceBookEntry pbeStandard = new PriceBookEntry(
            Product2Id = product.Id, Pricebook2Id = Test.getStandardPricebookId(), UnitPrice = 10, CurrencyISOCode ='INR', isActive=true);
        insert pbeStandard;

       
       
        Sales_Area__c salesArea = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        insert salesArea;

        //add plant on oppty
        Plant__c plant = (Plant__c)SmartFactory.createSObject('Plant__c');
        insert plant;

         //create Product Sales Area
        Product_Sales_Area__c productSalesArea = new Product_Sales_Area__c(
            Material_Code__c = product.Id, Sales_Area__c = salesArea.Id);
        insert productSalesArea;


        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        account.CurrencyISOCode = 'INR';
        insert account;

        SmartFactory.FillAllFields = true;
        Payment_Terms__c paymentTerms = (Payment_Terms__c)SmartFactory.createSObject('Payment_Terms__c');
        insert paymentTerms;
        Sales_Area_TI__c accountSalesArea = (Sales_Area_TI__c)SmartFactory.createSObject('Sales_Area_TI__c');
        SmartFactory.FillAllFields = false;
        accountSalesArea.Account_Name__c = account.Id;
        accountSalesArea.SAP_Sales_Area_Number__c = salesArea.Id;
        accountSalesArea.Payment_Terms__c = paymentTerms.Id;
        accountSalesArea.CurrencyISOCode ='INR';
        insert accountSalesArea;

        //same sales area direct match
        Opportunity opportunity =  (Opportunity)SmartFactory.createSObject('Opportunity');
        //set yarn recordtype
        opportunity.Business_Division__c='Yarn';
        opportunity.AccountId = account.Id;
        opportunity.Sales_Area__c= salesArea.Id;
        opportunity.CurrencyISOCode ='INR';
        insert opportunity;


        //positiveTest
        OpportunityLineItem oli = new OpportunityLineItem(
            Product_Code__c= productCode1, OpportunityId=opportunity.Id, Quantity=5);

        insert oli;
        try{
            opportunity.Plant__c = plant.Id;
            update opportunity;
        }catch(Exception e){}
       

    }   


}

 
Need to understand what this lines of Trigger actually means as I'm new to Triggers.
if(salesAreaMatched)
							{
                                if(Trigger.isInsert)
								{ 
								opportunity.CurrencyISOCode = accountSalesArea.CurrencyISOCode; 
								}
                                opportunity.Account_Sales_Area_TI__c = accountSalesArea.Id;
                                opportunity.INCO_Term__c = accountSalesArea.Incoterms__c;
                                if(!String.isBlank(accountSalesArea.Price_List__c))
                                opportunity.Price_List__c = accountSalesArea.Price_List__c;
                                
                                if(Trigger.isInsert && Trigger.isBefore && opportunity.Payment_Term__c == null)
                                {
                                    opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                }
                                else if(Trigger.isUpdate && Trigger.isBefore)
                                {
                                    Opportunity tempOpty = (Opportunity)Trigger.oldMap.get(opportunity.Id);
                                    if(tempOpty.Sales_Area__c != null && tempOpty.Sales_Area__c != opportunity.Sales_Area__c && tempOpty.Payment_Term__c == opportunity.Payment_Term__c)
                                    {
                                        opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                    }
                                }
                                //opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                opportunity.INCO_Term_Location__c = accountSalesArea.Incoterms_2__c;
                                break;
                            }

 
How can i write the validation rule in which on changing value in Opportunity Picklist value it compares the value with 2 picklist fields of custom object .
If value in Opportunity picklist is matches with the any of the 1 field of custom object then it saves record otherwise it throws the error.

I have write the following validation rule but it didn't work.

Kindly help in correcting the validation rule.
TEXT(INCO_Term__c) <> "" && 
OR( 
TEXT(INCO_Term__c) <> TEXT(Account_Sales_Area_TI__r.Inco__c) , 
TEXT(INCO_Term__c) <> TEXT(Account_Sales_Area_TI__r.Incoterms__c) 
)

 
Hi

Please help to write the TEST class for the following apex class:-
public with sharing class Controller_QuotePage {
   public Opportunity qt {get; set;}
   public List<Opportunity_Product__c> theLineItems {get; set;}
   public Controller_QuotePage(ApexPages.StandardController controller) 
   {
       Id quoteID = ((Opportunity) controller.getRecord()).Id;
       loadQuote(quoteId);
       loadQuoteLineItems(quoteId);
    }
    
    public List<Opportunity_Product__c> getLineItems(){
         
         return theLineItems;
    }
    

   private void loadQuote(String quoteId) {
        this.qt = [Select Id, Name       
                   FROM Opportunity where    
                  Id=:quoteId];  
      
   }
    
   private void loadQuoteLineItems(String quoteId) {

       this.theLineItems = [SELECT Id, Name                          
                             FROM Opportunity_Product__c WHERE Opportunity__c =:   
                             quoteId];  
            
    }


}

 
Hi
I have created a custom button on opportunity page to export data to excel of Opportunity Header and its Related List.
It download to local system when i click button.
How can I download it on a network path directly or FTP path??
VF Page:-
<apex:page Standardcontroller="Opportunity" extensions="Controller_QuotePage" contenttype="application/vnd.ms-excel#test.xls">
<apex:pageBlock >
<apex:pageBlockTable value="{!qt}" var="cs">
<apex:column value="{!cs.ID}" />
<apex:column value="{!cs.Name}" />
 </apex:pageBlockTable>
<apex:pageBlockTable value="{!LineItems}" var="cs1">
<apex:column value="{!cs1.ID}" />
<apex:column value="{!cs1.Name}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Apex controller: -
public with sharing class Controller_QuotePage {
   public Opportunity qt {get; set;}
   public List<Opportunity_Product__c> theLineItems {get; set;}
   public Controller_QuotePage(ApexPages.StandardController controller) 
   {
       Id quoteID = ((Opportunity) controller.getRecord()).Id;
       loadQuote(quoteId);
       loadQuoteLineItems(quoteId);
    }    
    public List<Opportunity_Product__c> getLineItems(){
         
         return theLineItems;
    }  
   private void loadQuote(String quoteId) {
        this.qt = [Select Id, Name       
                   FROM Opportunity where    
                  Id=:quoteId];        
   }    
   private void loadQuoteLineItems(String quoteId) {
       this.theLineItems = [SELECT Id, Name                          
                             FROM Opportunity_Product__c WHERE Opportunity__c =:   
                             quoteId];             
    }
}

Please advice next

 
Hi
I have created a custom button on opportunity page to export data to excel of Opportunity Header and its Related List.
It download to local system when i click button.
How can I download it on a network path directly or FTP path??
VF Page:-
<apex:page Standardcontroller="Opportunity" extensions="Controller_QuotePage" contenttype="application/vnd.ms-excel#test.xls">
<apex:pageBlock >
<apex:pageBlockTable value="{!qt}" var="cs">
<apex:column value="{!cs.ID}" />
<apex:column value="{!cs.Name}" />
<apex:column value="{!Opportunity.Sub_Region__c}" />
<apex:column value="{!Opportunity.Business_Type__c}" />
<apex:column value="{!Opportunity.Due_date_of_Tender_Submission__c}" />
<apex:column value="{!Opportunity.Name}" />--> 
 </apex:pageBlockTable>
<apex:pageBlockTable value="{!LineItems}" var="cs1">
<apex:column value="{!cs1.ID}" />
<apex:column value="{!cs1.Name}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Apex controller: -
public with sharing class Controller_QuotePage {
   public Opportunity qt {get; set;}
   public List<Opportunity_Product__c> theLineItems {get; set;}
   public Controller_QuotePage(ApexPages.StandardController controller) 
   {
       Id quoteID = ((Opportunity) controller.getRecord()).Id;
       loadQuote(quoteId);
       loadQuoteLineItems(quoteId);
    }
    public List<Opportunity_Product__c> getLineItems(){
         
         return theLineItems;
    }
   private void loadQuote(String quoteId) {
        this.qt = [Select Id, Name       
                   FROM Opportunity where    
                  Id=:quoteId];        
   }    
   private void loadQuoteLineItems(String quoteId) {
       this.theLineItems = [SELECT Id, Name                          
                             FROM Opportunity_Product__c WHERE Opportunity__c =:   
                             quoteId];              
    }
}



 
Akash Garg 
error of test class while deploying trigger to Production from Sandbox
Hello,
I got below error of another apex test class while deploying my trigger and trigger test class to production.
User-added image
My Trigger Test Class i trying to deploy is:-
 
trigger QuoteTriggerInsertQPG on Quote (after insert) {
if(!QuoteInsertFromTriggerHelpper.InsideQuoteInsert){

    
    for(Quote qqq : trigger.new){
    if(qqq.merging__c != true){
   
    map<Id,Quote> QMap = new map<Id,Quote>([select Id, OpportunityId, RecordtypeId,NPD_Required__c, RecordType.developerName from quote 
        where Id IN: trigger.new]);
        List<Quote> quoteId = new List<Quote>();
    Set<String> RecordTypeDevNames = new set<String>();
    set<Id> oppIds = new set<Id>();
    list<Quote_Product_Group__c> QPGlist = new list<Quote_Product_Group__c>();
    list<Quote_Product__c> QPlist = new list<Quote_Product__c>();
    map<Id,Quote_Product_Group__c> QPGmap = new map<Id,Quote_Product_Group__c>();
    
    if(QMap.values()[0].npd_required__c == true){
     
    for(Quote q: QMap.values()){
        RecordTypeDevNames.add(q.RecordType.developerName);
        oppIds.add(q.OpportunityId);
        quoteId.add(q);
    }
    list<recordType> QPRecordTypes = [select Id, DeveloperName from RecordType 
        where sObjectType='Quote_Product__c' and developerName IN: RecordTypeDevNames];
    list<recordType> QPGRecordTypes = [select Id, DeveloperName from RecordType 
        where sObjectType='Quote_Product_Group__c' and developerName IN: RecordTypeDevNames];
    map<Id,Opportunity> Map_oppPG_oppP = new map<Id,Opportunity>([select Id, AccountId, 
        (select id, Account__c,Program_name__c,Quality_reference__c,Opportunity__c,Number_of_Sizes__c,Model__c,
            Fabric_Type__c,Fabric_Design_Type__c,Required_Price_Pc__c,Required_Price_kg__c,Quantity__c,Quantity_UOM__c,
            Packaging_Type_Gross_Level__c,Packaging_Type_Carton_Level__c,Pile_Cotton_Quality_Type__c,Short_Description__c,
            QualityDesign_Type__c,Pile_Yarn_Type__c,Pile_Yarn_Description__c,recordtype.developername from opportunity_product_Groups__r
        ),
        (select id,size_wise_ratio__c,SORTNO_SAP__c,Converted_from_Lead__c,Accessories__c,Private_Label__c,Type_of_pulp__c,npd_flag__c,
            Hanger_Needed__c,Stitch_Type__c,Bartuck_Needed__c, Opportunity_Product_Group__c, Process__c,Count__c,Type__c,
            Other_Spl_Requirment__c,Shade_Reference__c,Required_Price_kg__c,Packing__c,Spl_Requirement__c,
            Raw_Material_3_Per__c,Raw_Material_3__c,Raw_Material_2__c,Raw_Material_2_Per__c,Raw_Material_1__c,Quantity__c,
            End_use__c,Ply__c,Raw_Material__c,Product_form__c,Reel_Width__c,Reel_Width_UOM__c,Sheet_Length__c,
            Sheet_Length_UOM__c,Sheet_Breadth__c,Sheet_Breadth_UOM__c,Ash__c,With_Watermark__c,plant__c,
            No_of_Watermarks_as_per_A3_sheet__c,shade__c,OPacity__c,Cobb_UOM__c,Cobb__c,Whiteness__c,
            Brightness_UOM__c,Brightness__c,GSM_UOM__c,Bulk_CC_gm__c,Quantity_UOM__c,
            Num_of_stitches_1000_size__c,Names_of_Sizes_Bathrobe__c,For__c,Names_of_Sizes__c,Size_Tolerance__c,
            Tolerance_weight__c,Product__c,Test_Protocol__c,Customer_Test_Protocol__c,Needle_Type__c,Pile_Blend__c,
            Sample_Sort__c,Costing_Depth__c,Printed__c,Finish__c,width__c,length__c,size_uom__c,
            Number_of_Colors_Styles__c,Embroidery_Applique__c,Wt_Pc__c,Is_Existing__c,Short_Description__c,
            If_Beach__c,GSM__c,recordtype.developername,SAP_Labdip_Item_No__c,LABDIP_ITEM_SAP__c,T_YARN_COUNT__c, T_YARN_MIXING__c, T_NPD_PRODUCT_TYPE_MY__c, T_YARN_MELANGETYPE__c, T_BLEND_TYPE_NPD__c, T_NPD_DYED_PART__c,T_REAMRK1__c,
            T_YARN_ENDUSE_PLY__c, T_YARN_PLY_COUNT_NPD__c, T_NPD_PLANT__c, Process_Depth_Type__c, T_YRN_PP_SHADE_DEPTH__c, Remark_2__c,Yarn_Product_Type__c
            from opportunity_products__r where Technical_Feasibility__c !='FAILED' and SORTNO_SAP__c != ''
        )
        from Opportunity where Id IN: oppIds]);
    map<String, RecordType> MapQPRecordTypes = new map<String, RecordType>();
    map<String, RecordType> MapQPGRecordTypes = new map<String, RecordType>();
    for(RecordType QPRT : QPRecordTypes){
        if(!MapQPRecordTypes.containsKey(QPRT.developerName)){
            MapQPRecordTypes.put(QPRT.developerName,QPRT);
        }
    }
    for(RecordType QPGRT : QPGRecordTypes){
        if(!MapQPGRecordTypes.containsKey(QPGRT.developerName)){
            MapQPGRecordTypes.put(QPGRT.developerName,QPGRT);
        }
    }
    for(Quote q : trigger.new){
        if(QMap.containsKey(q.Id)){
            String RTdevName = QMap.get(q.id).recordtype.developerName;
            if(RTdevName == 'Bathrobe' || RTdevName == 'Sheeting' || RTdevName == 'Towel' || RTdevName == 'International_Sheeting'){
                if(Map_oppPG_oppP.containsKey(q.OpportunityId)){
                    integer OPG_count = 0;
                    for(opportunity_product_Group__c opg : Map_oppPG_oppP.get(q.OpportunityId).opportunity_product_Groups__r){
                        Quote_Product_Group__c qpg = new Quote_Product_Group__c();
                        if(OPG_count == 0){
                            qpg.Quote__c = q.Id;
                        }else{
                            qpg.Quote__c = QuoteInsertFromTriggerHelpper.CreateQuote(q).Id;
                        }
                        OPG_count++;
                        qpg.Number_of_Sizes__c = opg.Number_of_Sizes__c;
                        qpg.Quality_Reference__c =opg.Quality_Reference__c;
                        qpg.Account__c = opg.Account__c;
                        qpg.Program_name__c = opg.Program_name__c;
                        qpg.Short_Description__c =opg.Short_Description__c ;
                        qpg.Quality_Design_Type__c = opg.QualityDesign_Type__c;
                        qpg.Pile_Yarn_Type__c = opg.Pile_Yarn_Type__c;
                        qpg.Other_Pile_Yarn_Type__c = opg.Pile_Yarn_Description__c;
                        qpg.Pile_Cotton_Quality_Type__c = opg.Pile_Cotton_Quality_Type__c;
                        qpg.Packaging_Type_Carton_Level__c = opg.Packaging_Type_Carton_Level__c;
                        qpg.Packaging_Type_Gross_Level__c = opg.Packaging_Type_Gross_Level__c;
                        qpg.Quantity__c = opg.Quantity__c;
                        qpg.Quantity_UOM__c = opg.Quantity_UOM__c;
                        if(MapQPGRecordTypes.containsKey(RTdevName)){
                            qpg.recordtypeId = MapQPGRecordTypes.get(RTdevName).Id;
                        }
                        if(opg.recordtype.developername == 'Towel'|| opg.recordtype.developername == 'Sheeting'){
                            qpg.Required_Price_Kg__c = opg.Required_Price_Kg__c;
                        }else if(opg.recordtype.developername == 'Bathrobe'){
                            qpg.Model__c = opg.Model__c;
                            qpg.Fabric_type__c = opg.Fabric_Type__c;
                            qpg.Fabric_Design_Type__c = opg.Fabric_Design_Type__c;
                            qpg.Required_Price_Pc__c = opg.Required_Price_Pc__c;
                        }
                        QPGlist.add(qpg);
                        QPGmap.put(opg.Id,qpg);
                        
                    }
                 }
            }
        }
    }
    insert QPGlist;
    for(Quote q : trigger.new){
        if(QMap.containsKey(q.Id)){
            String RTdevName = QMap.get(q.id).recordtype.developerName;
            if(Map_oppPG_oppP.containsKey(q.OpportunityId)){
                for(opportunity_product__c op : Map_oppPG_oppP.get(q.OpportunityId).opportunity_products__r){
                    Quote_Product__c qp= new Quote_Product__c();
                    if(QPGmap.containsKey(op.Opportunity_Product_Group__c)){ 
                        qp.Quote_Product_Group__c = QPGmap.get(op.Opportunity_Product_Group__c).Id;
                        qp.quote__c = QPGmap.get(op.Opportunity_Product_Group__c).quote__c;
                    }
                    else{qp.Quote__c = quoteId[0].id;}
                    qp.Product__c = op.Product__c;
                    qp.Is_Existing__c = op.Is_Existing__c;
                    qp.T_NPD_PLANT__c = op.plant__c;
                    if(MapQPRecordTypes.containsKey(RTdevName)){
                        qp.recordtypeId = MapQPRecordTypes.get(RTdevName).Id;
                    }
                    qp.Short_Description__c =  op.Short_Description__c;
                    if(op.recordtype.developername == 'Towel'|| op.recordtype.developername == 'Sheeting' || op.recordtype.developername == 'Bathrobe'){
                       
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.If_Beach__c = op.If_Beach__c;
                        qp.GSM__c = op.GSM__c;
                        qp.Wt_Pc_gms__c = op.Wt_Pc__c;
                        qp.Embroidery_Applique__c = op.Embroidery_Applique__c;
                        qp.of_Colors_Styles__c =op.Number_of_Colors_Styles__c;
                        qp.Finish__c = op.Finish__c;
                        qp.width__c = op.width__c;
                        qp.length__c =op.length__c;
                        qp.size_uom__c = op.size_uom__c;
                        qp.Printed__c =op.Printed__c;
                        qp.Costing_Depth__c = op.Costing_Depth__c;
                        qp.Quantity_UOM__c=op.Quantity_UOM__c;
                        qp.Sample_Sort_Ref__c = op.Sample_Sort__c;
                        qp.Pile_Blend__c = op.Pile_Blend__c;
                        qp.Needle_Type__c = op.Needle_Type__c;
                        qp.Bartuck_Needed__c = op.Bartuck_Needed__c;
                        qp.Stitch_Type__c = op.Stitch_Type__c;
                        qp.Hanger_Needed__c =op.Hanger_Needed__c;
                        qp.Customer_Test_Protocol__c =op.Customer_Test_Protocol__c;
                        qp.Test_Protocol_Customer__c = op.Test_Protocol__c;
                        qp.Short_Description__c =  op.Short_Description__c;
                        qp.size_wise_ratio__c = op.size_wise_ratio__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.SAP_Sort_No__c = op.SORTNO_SAP__c;
                        if(!qp.Is_Existing__c &&qp.Product__c ==null){
                            if(qp.GSM__c!=null)
                            {
                            qp.Wt_Pc_gms__c = (qp.GSM__c*(qp.Length__c*qp.Width__c))/1000;
                            }
                            else if(qp.GSM__c== null && qp.Wt_Pc_gms__c !=null)
                            {
                            qp.GSM__c =  (qp.Wt_Pc_gms__c*1000)/(qp.Length__c*qp.Width__c);
                            }
                        }
                    }
                    if(op.recordtype.developername == 'Towel' || op.recordtype.developername == 'Sheeting'){
                        qp.Names_of_Sizes__c = op.Names_of_Sizes__c;
                        qp.Tolerance_weight__c =op.Tolerance_weight__c;
                        qp.Size_Tolerance__c = op.Size_Tolerance__c;
                    }
                    if(op.recordtype.developername == 'Towel'){
                        qp.labdip_flag__c = op.npd_flag__c; 
                    }                   
                    if(op.recordtype.developername == 'Bathrobe'){
                        qp.For__c = op.For__c;
                        qp.Names_of_Sizes__c = op.Names_of_Sizes_Bathrobe__c;
                        qp.Num_of_stitches_1000_size__c =op.Num_of_stitches_1000_size__c;
                        qp.Accessories__c =op.Accessories__c;
                    }else if(op.recordtype.developername == 'Paper'){
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Quantity_UOM__c=op.Quantity_UOM__c;
                        qp.Bulk_CC_gm__c= op.Bulk_CC_gm__c;
                        qp.GSM__c = op.GSM__c;
                        qp.GSM_UOM__c =op.GSM_UOM__c;
                        qp.Brightness__c = op.Brightness__c;
                        qp.Brightness_UOM__c = op.Brightness_UOM__c;
                        qp.Whiteness__c = op.Whiteness__c ;
                        qp.Cobb__c = op.Cobb__c;
                        qp.Cobb_UOM__c = op.Cobb_UOM__c;
                        qp.OPacity__c =op.OPacity__c;
                        qp.Product_form__c = op.Product_form__c;
                        qp.Reel_Width__c =op.Reel_Width__c;
                        //qp.Reel_Width_UOM__c =op.Reel_Width_UOM__c;
                        qp.Sheet_Length__c =op.Sheet_Length__c;
                        //qp.Sheet_Length_UOM__c =op.Sheet_Length_UOM__c;
                        qp.Sheet_Breadth__c =op.Sheet_Breadth__c ;
                        qp.Size_UOM__c = op.Size_UOM__c;
                        //qp.Sheet_Breadth_UOM__c =op.Sheet_Breadth_UOM__c ;
                        qp.Ash__c = op.Ash__c;
                        qp.With_Watermark__c =op.With_Watermark__c ;
                        qp.No_of_Watermarks_as_per_A3_sheet__c= op.No_of_Watermarks_as_per_A3_sheet__c;
                        qp.shade__c =op.shade__c;
                        qp.Type_of_pulp__c = op.Type_of_pulp__c;
                        qp.Private_Label__c = op.Private_label__c;
                    }else if(op.recordtype.developername == 'Dyed_Yarn'){
                        
                        qp.SAP_Labdip_Recipe__c = op.SAP_Labdip_Item_No__c;
                        qp.SAP_Labdip_Item__c = op.LABDIP_ITEM_SAP__c;
                        qp.labdip_flag__c = op.npd_flag__c;
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Process__c = op.Process__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Count__c = op.Count__c;
                        qp.Type__c = op.Type__c;
                        qp.End_Use__c = op.End_use__c;
                        qp.Ply__c = op.Ply__c;
                        qp.Raw_Material_1__c = op.Raw_Material__c;
                        qp.Raw_Material_1_per__c = op.Raw_Material_1__c;
                        qp.Raw_Material_2__c =op.Raw_Material_2__c;
                        qp.Raw_Material_2_pre__c= op.Raw_Material_2_Per__c;
                        qp.Raw_Material_3__c = op.Raw_Material_3__c;
                        qp.Raw_Material_3_per__c = op.Raw_Material_3_Per__c;
                        qp.Shade_Reference__c =op.Shade_Reference__c;
                        qp.Required_Price_kg__c = op.Required_Price_kg__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Quantity_UOM__c = op.Quantity_UOM__c;
                        qp.Packing__c = op.Packing__c;
                        qp.Spl_Requirement__c = op.Spl_Requirement__c;
                        qp.Other_Spl_Requirement__c = op.Other_Spl_Requirment__c;
                         //added as per Sharad for mapping for Quote PDF
                        qp.Yarn_Cone_Weight__c = ''+op.T_YARN_CONEWEIGHT__c;
                        qp.Yarn_Packaging_Style__c = op.T_YARN_PACKINGSTYLE__c;
                        qp.Yarn_Packaging_Type__c = op.T_YARN_PACKINGTYPE__c;
                        qp.Yarn_Waxing__c = op.T_YARN_WAXING__c;
                        qp.Net_Weight_per_carton__c = op.Net_Weight_per_carton__c;
                        qp.Net_Weight_per_pallet__c = op.Net_Weight_per_pallet__c;
   
                        qp.depth__c = op.Process_Depth_Type__c;

                        
                        
                     }else if(op.recordtype.developername == 'Melange_Yarn'){
                     
                        qp.SAP_Labdip_Recipe__c = op.SAP_Labdip_Item_No__c;
                        qp.SAP_Labdip_Item__c = op.LABDIP_ITEM_SAP__c;
                        qp.labdip_flag__c = op.npd_flag__c;     
                        qp.Opp_Product_Id__c = op.id;                  
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Process__c = op.Process__c;
                        qp.Count__c = op.Count__c;
                        qp.Type__c = op.Type__c;
                        qp.End_Use__c = op.End_use__c;
                        qp.Ply__c = op.Ply__c;
                        qp.Raw_Material_1__c = op.Raw_Material__c;
                        qp.Raw_Material_1_per__c = op.Raw_Material_1__c;
                        qp.Raw_Material_2__c =op.Raw_Material_2__c;
                        qp.Raw_Material_2_pre__c= op.Raw_Material_2_Per__c;
                        qp.Raw_Material_3__c = op.Raw_Material_3__c;
                        qp.Raw_Material_3_per__c = op.Raw_Material_3_Per__c;
                        qp.Shade_Reference__c =op.Shade_Reference__c;
                        qp.Required_Price_kg__c = op.Required_Price_kg__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Quantity_UOM__c = op.Quantity_UOM__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Packing__c = op.Packing__c;
                        qp.Spl_Requirement__c = op.Spl_Requirement__c;
                        qp.Other_Spl_Requirement__c = op.Other_Spl_Requirment__c;
                        //added as per Sharad for mapping for Quote PDF
                        qp.Yarn_Cone_Weight__c = ''+op.T_YARN_CONEWEIGHT__c;
                        qp.Yarn_Packaging_Style__c = op.T_YARN_PACKINGSTYLE__c;
                        qp.Yarn_Packaging_Type__c = op.T_YARN_PACKINGTYPE__c;
                        qp.Yarn_Waxing__c = op.T_YARN_WAXING__c;
                        qp.Net_Weight_per_carton__c = op.Net_Weight_per_carton__c;
                        qp.Net_Weight_per_pallet__c = op.Net_Weight_per_pallet__c;
                        
                        //added on 03/10/15
                        qp.T_YARN_COUNT__c = op.T_YARN_COUNT__c;
                        qp.T_YARN_MIXING__c = op.T_YARN_MIXING__c;
                        // ***** Edited due to duplicate mapping (23-03)
                        //qp.T_NPD_PRODUCT_TYPE_MY__c = op.T_NPD_PRODUCT_TYPE_MY__c;                        
                        qp.T_NPD_PRODUCT_TYPE_MY__c = op.Yarn_Product_Type__c;
                        
                        qp.T_YARN_MELANGETYPE__c = op.T_YARN_MELANGETYPE__c;
                        qp.T_BLEND_TYPE_NPD__c = op.T_BLEND_TYPE_NPD__c;
                        qp.T_NPD_DYED_PART__c = op.T_NPD_DYED_PART__c;
                        qp.T_REAMRK1__c = op.T_REAMRK1__c;
                        qp.End_Use__c = op.T_YARN_ENDUSE_PLY__c;
                        qp.T_YARN_PLY_COUNT_NPD__c = op.T_YARN_PLY_COUNT_NPD__c;
                        qp.T_NPD_PLANT__c = op.T_NPD_PLANT__c;
                        qp.Product__c = op.product__c;
                        qp.depth__c = op.Process_Depth_Type__c;
                        qp.depth2__c = op.T_YRN_PP_SHADE_DEPTH__c;
                        qp.shade__c = op.shade__c;
                        qp.Shade_Reference__c = op.Shade_Reference__c;
                        qp.T_REMARK2__c = op.Remark_2__c;
                        
                     }else if(op.recordtype.developername == 'Griege_Yarn'){
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Process__c = op.Process__c;
                        qp.Count__c = op.Count__c;
                        qp.Type__c = op.Type__c;
                        qp.End_Use__c = op.End_use__c;
                        qp.Ply__c = op.Ply__c;
                        qp.Raw_Material_1__c = op.Raw_Material__c;
                        qp.Raw_Material_1_per__c = op.Raw_Material_1__c;
                        qp.Raw_Material_2__c =op.Raw_Material_2__c;
                        qp.Raw_Material_2_pre__c= op.Raw_Material_2_Per__c;
                        qp.Raw_Material_3__c = op.Raw_Material_3__c;
                        qp.Raw_Material_3_per__c = op.Raw_Material_3_Per__c;
                        qp.Required_Price_kg__c = op.Required_Price_kg__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Quantity_UOM__c = op.Quantity_UOM__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Packing__c = op.Packing__c;
                        qp.Spl_Requirement__c = op.Spl_Requirement__c;
                        qp.Other_Spl_Requirement__c = op.Other_Spl_Requirment__c;
                         //added as per Sharad for mapping for Quote PDF
                        qp.Yarn_Cone_Weight__c = ''+op.T_YARN_CONEWEIGHT__c;
                        qp.Yarn_Packaging_Style__c = op.T_YARN_PACKINGSTYLE__c;
                        qp.Yarn_Packaging_Type__c = op.T_YARN_PACKINGTYPE__c;
                        qp.Yarn_Waxing__c = op.T_YARN_WAXING__c;
                        qp.Net_Weight_per_carton__c = op.Net_Weight_per_carton__c;
                        qp.Net_Weight_per_pallet__c = op.Net_Weight_per_pallet__c;
                     }else if(op.recordtype.developername == 'Chemical'){
                        qp.Quantity__c =op.Quantity__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Quantity_UOM__c=op.Quantity_UOM__c;
                        qp.required_price__c = op.Required_Price_kg__c;
                     }
                     QPList.add(qp);
                 }
             }
         }
     } 
     insert QPList;}

My trigger Test Class i trying to deploy:-
 
@isTest
public class QuoteTriggerInsertQPGTest{
private static testMethod void TriggerInsertQPGTest(){
Account acc = new Account(); 
         acc.Name = 'Test';   
         acc.Total_Purchase_of_Relevant_Products_In__c = 123;   
         acc.Trident_share_in_total_purchase_In_MTs__c = 123; 
         acc.Total_Purchase_of_relevant_products__c = 123;   
         acc.Sales_District__c = 'Z00002-Key Account - India';
         acc.BillingPostalCode='1234';
         acc.ShippingPostalCode='1456';
         acc.BillingState='Delhi';
         acc.ShippingCountry ='India';
         acc.ShippingState ='Goa';
         acc.BillingCountry ='India';
         acc.BillingState='Delhi';
          insert acc;
          
opportunity o = new opportunity();
o.name = 'test';
o.stagename= 'Qualified';
o.closedate = Date.today() + 10;
o.accountid = acc.id;
insert o;
Opportunity_product__c op = new Opportunity_product__c();
op.opportunity__c = o.id;
op.Ash__c = 22;
op.Bartuck_Needed__c = true;
op.T_NPD_ACCESSORIES_COST__c = 56;
op.T_NPD_PACKING_COST__c = 45;
op.T_PRODUCT_SIZE_BATHROBE__c = 'True';
op.Brightness__c = 8;
insert op;
opportunity_product_Group__c opg = new opportunity_product_Group__c();
opg.Number_of_Sizes__c= 2;
opg.opportunity__c = o.id;
insert opg;
Quote q = new Quote();
q.name='Test';
q.opportunityid = o.id;
insert q;
Pcm_sheet__c p = new Pcm_sheet__c();
p.Quote__c = q.id;
insert p;
PCM_LineItem__c pli = new PCM_LineItem__c();
pli.Pcm_sheet__c = p.id;
insert pli;
}
}

Please anyone guide where my error is??
 

 
Hi 
Can anyone help in writing the test class who gives 100% code coverage .

I Have written a test class, its working but gives only 72% code coverage.

Here is the Apex Class-
global class tridentUpdateCFormsWebService
{    
    webservice static SFAResponse updateCForms(CForms_element[] cfrmRec) {   
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                              // to capture web service failure exceptions.      
        List<C_Forms__c> cformList = new List<C_Forms__c>();
        List<string> sapCustList = new List<string>();
        for(CForms_element cfrmCust : cfrmRec)
        {
            if(cfrmCust.SAP_CustomerId != null && cfrmCust.SAP_CustomerId != '')
            sapCustList.add(cfrmCust.SAP_CustomerId);
        }
        Map<string,string> mapCust = new Map<string,string>();
        for(account cust : [select id, Cust_SAP_No__c from Account where Cust_SAP_No__c in : sapCustList])
        {mapCust.put(cust.Cust_SAP_No__c,cust.Id);}
        if(cfrmRec[0].SAP_Message == null || cfrmRec[0].SAP_Message == '')
        {
            for(CForms_element cfrm_Rec : cfrmRec)
            {
                C_Forms__c cform_Rec = new C_Forms__c();
                                
                cform_Rec.Excise_Invoice_No_vbeln_new__c = cfrm_Rec.Excise_Invoice_No_vbeln_new;
                cform_Rec.Customer_SAP_Code__c = cfrm_Rec.SAP_CustomerId;
                
                if(mapCust.get(cfrm_Rec.SAP_CustomerId) != null)
                cform_Rec.Account__c = mapCust.get(cfrm_Rec.SAP_CustomerId);
                cform_Rec.Customer_Name_name1_new__c = cfrm_Rec.Customer_Name_name1_new;              
                cform_Rec.Region_regio_new__c = cfrm_Rec.Region_regio_new;                
                cform_Rec.VAT_Amount_zvat_amt_new__c = cfrm_Rec.VAT_Amount_zvat_amt_new;
                cform_Rec.Diff_Liability_zdiff_amt_new__c = cfrm_Rec.Diff_Liability_zdiff_amt_new;
                cform_Rec.Accounting_Document_Number_belnr_new__c = cfrm_Rec.Accounting_Document_Number_belnr_new;              
                cform_Rec.Company_Code_bukrs_new__c = cfrm_Rec.Company_Code_bukrs_new;     
                cform_Rec.Fiscal_Year_gjahr_new__c = cfrm_Rec.Fiscal_Year_gjahr_new;
                cform_Rec.Quarter_zquarter_new__c = cfrm_Rec.Quarter_zquarter_new;
                cform_Rec.Invoice_Value_zinv_value_new__c = cfrm_Rec.Invoice_Value_zinv_value_new;
                cform_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new__c = cfrm_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new;
                                    
                cformList.add(cform_Rec);
            }
            try{
                upsert cformList;
                                                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = true;
                return objResponse;
            }
            catch(exception e){
                excep.Record_Id__c = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                //excep.Order__c = cfrmRec[0].cformsId;
                excep.error__c = e.getmessage();
                insert excep;
                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
                return objResponse;// this will return result.
            }
        }
        else
        {
            list<Exceptions__c> lstexcep = new list<Exceptions__c>();
            for(integer i=0; i < cfrmRec.size(); i++)
            {
                Exceptions__c exp = new Exceptions__c();
                exp.Name = 'E';             
                
                lstexcep.add(exp);
            }
            insert lstexcep;
                       
            objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
            objResponse.Status = false;
            return objResponse;// this will return result.
        }                            
    }
    global class CForms_element
    {
        webservice string SAP_CustomerId;        
        webservice string Customer_Name_name1_new;
        webservice string Excise_Invoice_No_vbeln_new;
        webservice string Region_regio_new;
        webservice string VAT_Amount_zvat_amt_new;
        webservice string Diff_Liability_zdiff_amt_new;
        webservice string Accounting_Document_Number_belnr_new;
        webservice string Company_Code_bukrs_new;
        webservice string Fiscal_Year_gjahr_new;
        webservice string Quarter_zquarter_new;
        webservice string Invoice_Value_zinv_value_new;
        webservice string Tax_on_sales_and_Purchases_cod_mwskz_new;
        webservice string SAP_Message;
    } 
    global class SFAResponse
    {
        webservice String SFDC_Rec_No;       
        webservice Boolean Status; 
        webservice String Description;
    }
 }

and here is the test class i have written:-
@isTest
private class tridentUpdateCFormsWebService_Test 
{
    private static testmethod void testCase()
    {
        
        C_Forms__c pgl = new C_Forms__c() ; 
            //pgl.Name='CF-1234' ; 
            pgl.Excise_Invoice_No_vbeln_new__c = '125' ;
            pgl.Customer_Name_name1_new__c = 'test' ; 
            pgl.Region_regio_new__c = '1';
            pgl.VAT_Amount_zvat_amt_new__c  = '9';
            pgl.Diff_Liability_zdiff_amt_new__c  = '1';      
            pgl.Accounting_Document_Number_belnr_new__c  = '12';      
            pgl.Company_Code_bukrs_new__c = '123';
            pgl.Fiscal_Year_gjahr_new__c  = '1';
            pgl.Quarter_zquarter_new__c  = '2';
            pgl.Invoice_Value_zinv_value_new__c  = '12';
            pgl.Tax_on_sales_and_Purchases_cod_mwskz_new__c  = '2';
        insert pgl ; 
        
        tridentUpdateCFormsWebService.CForms_element ele = new tridentUpdateCFormsWebService.CForms_element() ;
            ele.Excise_Invoice_No_vbeln_new = '125' ;
            ele.Customer_Name_name1_new = 'test' ; 
            ele.Region_regio_new = 'test';
            ele.VAT_Amount_zvat_amt_new = '1';
            ele.Diff_Liability_zdiff_amt_new = '1';      
            ele.Accounting_Document_Number_belnr_new = '122';      
            ele.Company_Code_bukrs_new = '123';
            ele.Fiscal_Year_gjahr_new = '1';
            ele.Quarter_zquarter_new = '1';
            ele.Invoice_Value_zinv_value_new = '12';
            ele.Tax_on_sales_and_Purchases_cod_mwskz_new = '2';
            ele.SAP_CustomerId = '7564';
        tridentUpdateCFormsWebService.SFAResponse resp = tridentUpdateCFormsWebService.updateCForms(new List<tridentUpdateCFormsWebService.CForms_element>{ele}) ;
    }
    
                            // This method will generate exception so catch block will be covered
    private static testmethod void testCaseException()
    {  
        C_Forms__c pgl = new C_Forms__c() ; 
            //pgl.Name='CF-1234' ; 
            pgl.Excise_Invoice_No_vbeln_new__c = '125' ;
            pgl.Customer_Name_name1_new__c = 'test' ; 
            pgl.Region_regio_new__c = '1';
            pgl.VAT_Amount_zvat_amt_new__c  = '9';
            pgl.Diff_Liability_zdiff_amt_new__c  = '1';      
            pgl.Accounting_Document_Number_belnr_new__c  = '12';      
            pgl.Company_Code_bukrs_new__c = '123';
            pgl.Fiscal_Year_gjahr_new__c  = '1';
            pgl.Quarter_zquarter_new__c  = '2';
            pgl.Invoice_Value_zinv_value_new__c  = '12';
            pgl.Tax_on_sales_and_Purchases_cod_mwskz_new__c  = '2';
        insert pgl ; 
        
        tridentUpdateCFormsWebService.CForms_element ele = new tridentUpdateCFormsWebService.CForms_element() ;
            ele.Excise_Invoice_No_vbeln_new = 'String For Exception' ;
            ele.Customer_Name_name1_new = 'test' ; 
            ele.Region_regio_new = 'test';
            ele.VAT_Amount_zvat_amt_new = '1';
            ele.Diff_Liability_zdiff_amt_new = '1';      
            ele.Accounting_Document_Number_belnr_new = 'String For Exception';      
            ele.Company_Code_bukrs_new = '123';
            ele.Fiscal_Year_gjahr_new = '1';
            ele.Quarter_zquarter_new = '1';
            ele.Invoice_Value_zinv_value_new = '12';
            ele.Tax_on_sales_and_Purchases_cod_mwskz_new = '2'; 
            ele.SAP_CustomerId = '7564';
        tridentUpdateCFormsWebService.SFAResponse resp = tridentUpdateCFormsWebService.updateCForms(new List<tridentUpdateCFormsWebService.CForms_element>{ele}) ;
    }
    
}

can anyone has the resolution for above problem.
 
Hi
I'm new to salesforce.
Can anyone help in writing the test class.
global class tridentUpdateOverduePGLWebService
{    
    webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) 
    {       
        //HttpRequest req = new HttpRequest();   
        //req.setHeader('Content-Type','application/x-www-form-urlencoded');
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                          // to capture web service failure exceptions.
        list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{};
        
    for (Integer i=0; i<OverdueRec.size();i++)
    {
        OverDue_PGL__c OverDueObj= new OverDue_PGL__c();
        
        OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new;
        OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new;
        OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new;
        OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new;
        OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new;      
        OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new;      
        OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new;
                              
        OverdueLst.add(OverDueObj);
        system.debug('Values taken');
  }

    if (Overduelst.size()>0)
    {                     
        try
            {
                insert OverdueLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                system.debug('Record Updated');     
            }    
       catch(exception e)
            {
                system.debug('Error');
                excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                
              //objResponse.SFDCId = OverdueLst.CustName;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
            }
     }
     else
     {        
      objResponse.Status = false;
      objResponse.Description ='No Item found to update';
      system.debug('Record not Updated');
     }
   return objResponse;                                                  // this will return result.
   }
        global class Overdue_element
      {
        webservice string CustomerName_name1_new;
        webservice string Total_Outstanding_INR_DMBTR_new;
        webservice string Payment_Term_Zterm_new;
        webservice string Overdue_Amount_INR_ovr_amt_new;
        webservice string Ageing_Days_days_new;
        webservice string Excise_Invoice_exnum_new;
        webservice string Item_Text_sgtxt_new;
    }
     global class SFAResponse
    {
      //webservice Id SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }
}

need urgently.
Please guide and help
Hi

I want to write a test class to increase code coverage for below mention trigger.
Can anyone help.
trigger paymenttermUpdate on Account (after update) {
    set<Id> acctIds = new set<Id>();
    map<Id, Account> mapAccount = new map<Id, Account>();
    list<Payment_Terms__c> listContact = new list<Payment_Terms__c>();
    
    for(Account acct : trigger.new) {
        acctIds.add(acct.Id);
        mapAccount.put(acct.Id, acct);
    }
    
    listContact = [SELECT Name, Payment_Terms__c,Account__c FROM Payment_Terms__c WHERE Account__c IN : acctIds];
    
    if(listContact.size() > 0) {
        for(Payment_Terms__c con : listContact) {
            con.Name = mapAccount.get(con.Account__c).Payment_Term_on_account_picklist__c;
            con.Payment_Terms__c = mapAccount.get(con.Account__c).Payment_Term_on_account_picklist__c;
        }
        update listContact;
    }
}

 
Hi 
I'm new to apex.
can anyone help in writing TEST CLASSES of these 3 apex classes.
 
global class tridentUpdateCFormsWebService
{    
    webservice static SFAResponse updateCForms(CForms_element[] cfrmRec) {   
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                              // to capture web service failure exceptions.      
        List<C_Forms__c> cformList = new List<C_Forms__c>();
        List<string> sapCustList = new List<string>();
        for(CForms_element cfrmCust : cfrmRec)
        {
            if(cfrmCust.SAP_CustomerId != null && cfrmCust.SAP_CustomerId != '')
            sapCustList.add(cfrmCust.SAP_CustomerId);
        }
        Map<string,string> mapCust = new Map<string,string>();
        for(account cust : [select id, Cust_SAP_No__c from Account where Cust_SAP_No__c in : sapCustList])
        {mapCust.put(cust.Cust_SAP_No__c,cust.Id);}
        if(cfrmRec[0].SAP_Message == null || cfrmRec[0].SAP_Message == '')
        {
            for(CForms_element cfrm_Rec : cfrmRec)
            {
                C_Forms__c cform_Rec = new C_Forms__c();
                                
                cform_Rec.Excise_Invoice_No_vbeln_new__c = cfrm_Rec.Excise_Invoice_No_vbeln_new;
                cform_Rec.Customer_SAP_Code__c = cfrm_Rec.SAP_CustomerId;
                
                if(mapCust.get(cfrm_Rec.SAP_CustomerId) != null)
                cform_Rec.Account__c = mapCust.get(cfrm_Rec.SAP_CustomerId);
                cform_Rec.Customer_Name_name1_new__c = cfrm_Rec.Customer_Name_name1_new;              
                cform_Rec.Region_regio_new__c = cfrm_Rec.Region_regio_new;                
                cform_Rec.VAT_Amount_zvat_amt_new__c = cfrm_Rec.VAT_Amount_zvat_amt_new;
                cform_Rec.Diff_Liability_zdiff_amt_new__c = cfrm_Rec.Diff_Liability_zdiff_amt_new;
                cform_Rec.Accounting_Document_Number_belnr_new__c = cfrm_Rec.Accounting_Document_Number_belnr_new;              
                cform_Rec.Company_Code_bukrs_new__c = cfrm_Rec.Company_Code_bukrs_new;     
                cform_Rec.Fiscal_Year_gjahr_new__c = cfrm_Rec.Fiscal_Year_gjahr_new;
                cform_Rec.Quarter_zquarter_new__c = cfrm_Rec.Quarter_zquarter_new;
                cform_Rec.Invoice_Value_zinv_value_new__c = cfrm_Rec.Invoice_Value_zinv_value_new;
                cform_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new__c = cfrm_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new;
                                    
                cformList.add(cform_Rec);
            }
            try{
                upsert cformList;
                                                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = true;
                return objResponse;
            }
            catch(exception e){
                excep.Record_Id__c = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                //excep.Order__c = cfrmRec[0].cformsId;
                excep.error__c = e.getmessage();
                insert excep;
                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
                return objResponse;// this will return result.
            }
        }
        else
        {
            list<Exceptions__c> lstexcep = new list<Exceptions__c>();
            for(integer i=0; i < cfrmRec.size(); i++)
            {
                Exceptions__c exp = new Exceptions__c();
                exp.Name = 'E';             
                
                lstexcep.add(exp);
            }
            insert lstexcep;
                       
            objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
            objResponse.Status = false;
            return objResponse;// this will return result.
        }                            
    }
    global class CForms_element
    {
        webservice string SAP_CustomerId;        
        webservice string Customer_Name_name1_new;
        webservice string Excise_Invoice_No_vbeln_new;
        webservice string Region_regio_new;
        webservice string VAT_Amount_zvat_amt_new;
        webservice string Diff_Liability_zdiff_amt_new;
        webservice string Accounting_Document_Number_belnr_new;
        webservice string Company_Code_bukrs_new;
        webservice string Fiscal_Year_gjahr_new;
        webservice string Quarter_zquarter_new;
        webservice string Invoice_Value_zinv_value_new;
        webservice string Tax_on_sales_and_Purchases_cod_mwskz_new;
        webservice string SAP_Message;
    } 
    global class SFAResponse
    {
        webservice String SFDC_Rec_No;       
        webservice Boolean Status; 
        webservice String Description;
    }
 }
 
global class tridentUpdateStockWebService
{
    Webservice static SFAResponse updateStock(Stock_element[] StockRec) 
    {
        SFAResponse objResponse = new SFAResponse();
        list <Stock_Report__c> StockLst = new list <Stock_Report__c>{};
        Exceptions__c excep = new Exceptions__c();                              // to capture web service failure exceptions.
        
        
        Set<string> sapCustList = new Set<string>();
        for(Stock_element customerR : StockRec)
        {
            if(customerR.CustNo != null && customerR.CustNo != '')
            sapCustList.add(customerR.CustNo);
        }
        Map<string,string> mapCust = new Map<string,string>();
        for(account cust : [select id, Cust_SAP_No__c from Account where Cust_SAP_No__c in : sapCustList])
        {mapCust.put(cust.Cust_SAP_No__c,cust.Id);}
        
        
        for (Integer i=0; i< StockRec.size(); i++)
        {
            Stock_Report__c StockVr = new Stock_Report__c();
            StockVr.Customer_Name_name1_new__c= StockRec[i].Customer_Name_name1_new;
            
            if(mapCust.get(StockRec[i].CustNo) != null)
            StockVr.Customer__c = mapCust.get(StockRec[i].CustNo);
            
            StockVr.Customer_Number__c= StockRec[i].CustNo;   
            StockVr.Special_Stock_No_SONUM_new__c= StockRec[i].Special_Stock_No_SONUM_new;
            StockVr.Total_Stock_Gesme_new__c= StockRec[i].Total_Stock_Gesme_new;
            StockVr.Material_Code_Matnr_new__c= StockRec[i].Material_Code_Matnr_new;
            StockVr.Material_Description_MAktx_new__c= StockRec[i].Material_Description_MAktx_new;
            StockVr.Batch_Charg_new__c= StockRec[i].Batch_Charg_new;
            StockVr.Product_Type_Lv_type_new__c= StockRec[i].Product_Type_Lv_type_new;
            StockVr.Plant_Werks_new__c= StockRec[i].Plant_Werks_new;
            
            StockLst.add(StockVr);
            system.debug('Values taken'); 
        }
        if (StockLst.size()>0)
     {
        try
        { 
                upsert StockLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                return objResponse;     // this will return result.
        }    
       catch(exception e)
        {
                excep.Record_Id__c = StockLst[0].Customer_Name_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                objResponse.SFDCId = StockLst[0].Customer_Name_name1_new__c;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
        }
     }
        return objResponse;     //this will return result.               
    }           
    
    global class stock_element
    {
        Webservice string CustNo;
        Webservice string Customer_Name_name1_new;
        Webservice string Special_Stock_No_SONUM_new;
        Webservice string Total_Stock_Gesme_new;
        Webservice string Material_Code_Matnr_new;
        Webservice string Material_Description_MAktx_new;
        Webservice string Batch_Charg_new;
        Webservice string Product_Type_Lv_type_new;
        Webservice string Plant_Werks_new;
        
    }
    
    global class SFAResponse
    {
        webservice String SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }

}
 
global class tridentUpdateOverduePGLWebService
{    
    webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) 
    {       
        //HttpRequest req = new HttpRequest();   
        //req.setHeader('Content-Type','application/x-www-form-urlencoded');
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                          // to capture web service failure exceptions.
        list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{};
        
    for (Integer i=0; i<OverdueRec.size();i++)
    {
        OverDue_PGL__c OverDueObj= new OverDue_PGL__c();
        
        OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new;
        OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new;
        OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new;
        OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new;
        OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new;      
        OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new;      
        OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new;
                              
        OverdueLst.add(OverDueObj);
        system.debug('Values taken');
  }

    if (Overduelst.size()>0)
    {                     
        try
            {
                insert OverdueLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                system.debug('Record Updated');     
            }    
       catch(exception e)
            {
                system.debug('Error');
                excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                
              //objResponse.SFDCId = OverdueLst.CustName;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
            }
     }
     else
     {        
      objResponse.Status = false;
      objResponse.Description ='No Item found to update';
      system.debug('Record not Updated');
     }
   return objResponse;                                                  // this will return result.
   }
        global class Overdue_element
      {
        webservice string CustomerName_name1_new;
        webservice string Total_Outstanding_INR_DMBTR_new;
        webservice string Payment_Term_Zterm_new;
        webservice string Overdue_Amount_INR_ovr_amt_new;
        webservice string Ageing_Days_days_new;
        webservice string Excise_Invoice_exnum_new;
        webservice string Item_Text_sgtxt_new;
    }
     global class SFAResponse
    {
      //webservice Id SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }
}

 
Hi

I have created a new custom profile and for this profile, my custom button on custom related list is not working but it is working for all other profiles.

Button code is:-
if('{!Opportunity_Product_Group__c.RecordTypeId}'== '{!$Setup.Record_Type__c.OPG_Towel__c}') { 
window.open("/a1Z/e?retURL={!Opportunity_Product_Group__c.Id}&RecordType={!$Setup.Record_Type__c.OP_Towel__c}&{!$Setup.Record_Type__c.OPG_Feild__c}={!Opportunity_Product_Group__c.Name}",'_top'); 
} 
else if('{!Opportunity_Product_Group__c.RecordTypeId}'== '{!$Setup.Record_Type__c.OPG_Bathrobe__c}'){ 
window.open("/a1Z/e?retURL={!Opportunity_Product_Group__c.Id}&RecordType={!$Setup.Record_Type__c.OP_Bathrobe__c}&{!$Setup.Record_Type__c.OPG_Feild__c}={!Opportunity_Product_Group__c.Name}",'_top'); 

} 
else if('{!Opportunity_Product_Group__c.RecordTypeId}'== '{!$Setup.Record_Type__c.OPG_Sheeting__c}'){ 
window.open("/a1Z/e?retURL={!Opportunity_Product_Group__c.Id}&RecordType={!$Setup.Record_Type__c.OP_Sheeting__c}&{!$Setup.Record_Type__c.OPG_Feild__c}={!Opportunity_Product_Group__c.Name}",'_top'); 

}

please can anyone knows how to solve this, as this is very urgent.
Hi

I'm trying to deploy 1 Pagelayout + 4 Custom Fields + 3 Apex Classes with test classes + 1Workflow Rule with 1 Field Update for Case Object.

But every time it gives error of CODE COVERAGE FAILURE or CODE COVERAGE IS 0 %.

Please help as it is very urgent for me to deploy it to Production Org.
Hi

I have a VF page called as tridentQuotePage on which i select the value of route from customobject name as Route__c.
I also added one outputfield on vf page whose value is getting from business type field of OPPORTUNITY Object which is the picklist with values Export and Domestic.
Now, i want when there is value Export on vf page then route should be filtered to certain value which contains X as second letter in Route__c object.
and 
when i select domestic then, it don't show the value which contains X as second letter in Route__c and show rest of the values.

My VF page is
<apex:page Controller="tridentOppDetailOnQuoteController">
      
    <apex:form id="myForm"> 
    <apex:inputHidden id="payid" value="{!paymentids}" />
    <div style="font-size:18px"> 
    <apex:PageMessages />
    </div>
    <center>
    <apex:commandButton action="{!cancelQuote}" value="Back" rendered="{!!render}" style="Color:blue;width:100px;height:28px;font-size:18px;"/></center>
    <apex:outputpanel rendered="{!render}">
        <apex:pageBlock id="PageBlock">
       
             <apex:pageblockSection columns="2" title="Quotation Details">
                 <apex:inputField value="{!quot.QuoteNumber}"/>
                 <apex:inputField value="{!quot.Inco_Terms__c}" required="true"/>
                 <apex:outputField value="{!opp.PaymentTerms__c}"/>
                 <apex:outputField value="{!opp.IncoTerm_1_opp__c}"/>
                   <!-- <apex:outputText >
          Payment Term  
                    <apex:inputtext value="{!lukupdoc2name}" style="align:left;" id="luckup2id" /><a href ="" style="cursor: pointer" onClick="javascript:return openDocumentPopup2(this.parentNode)" >
                    <img src="/s.gif" alt="Payment Lookup (New Window)" title="Payment Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';"  /></a>
              <br/>
                 
                </apex:outputText>-->
       <!-- <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Payment Term"/>
                                <apex:outputPanel >
                                    <div class="requiredInput">
                                        <div class="requiredBlock"></div>
                                        <apex:inputtext value="{!lukupdoc2name}" style="align:left;" id="luckup2id" /><a href ="" style="cursor: pointer" onClick="javascript:return openDocumentPopup2(this.parentNode)" >
                    <img src="/s.gif" alt="Payment Lookup (New Window)" title="Payment Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';"  /></a>
        
              <br/>
                                    </div>
                                </apex:outputPanel>
                    </apex:pageBlockSectionItem> -->
                 <apex:inputField value="{!quot.Name}"/>
                 <apex:inputField value="{!quot.Inco_Term2__c}" required="true"/>
                 <apex:inputField value="{!quot.Terms_Conditions__c}" required="true"/>
                  <apex:inputField value="{!quot.Route_Name__c}" required="true"/>
                 <apex:outputField value="{!quot.Quote_Status__c}"/>
                 <apex:inputField value="{!quot.Description}"/>
                 <apex:outputField value="{!Opp.name}"/>
                 <apex:outputField value="{!opp.Sales_Area__c}"/> 
                 <apex:outputField value="{!opp.Required_Delivery_Date_First_Delivery__c}"/>
                 <apex:outputField value="{!opp.Accountid}"/>
                 <apex:outputField value="{!quot.Tentative_Delivery_Date__c}" />
                 <apex:outputField value="{!opp.Contact__c}"/>
                 <apex:outputField value="{!quot.Total_Quantity__c}"/>
                 
                 <apex:inputField value="{!quot.For_Record__c}"/>
                 <apex:outputField value="{!opp.Qty_UOM__c}"/> 
                 <apex:inputField value="{!quot.Validity_Date__c}" required="true"/>
                 <apex:outputField value="{!opp.Ship_To_Party__c}" />
                 <!--apex:outputField value="{!opp.Contact__c}" /> -->
                 <apex:outputField value="{!quot.Total_Value__c}"/>
                <!-- <apex:inputField value="{!quot.Payment_Terms__c}" required="true" id="Account"/>-->
                 <apex:outputField value="{!quot.Accepted_Rejected_By__c}"/>
                 <apex:outputField value="{!opp.Business_Type__c}"/>
             </apex:pageblockSection>
              <apex:pageBlockSection >
        
      </apex:pageBlockSection>
             <apex:pageblockSection columns="2" title="Customer Decline">
                 <apex:outputField value="{!quot.Decline_Reason__c}"/>
             </apex:pageblockSection>
             
             <apex:pageblockButtons >
                 <apex:commandButton action="{!saveProduct}" value="Save"/>
                 <apex:commandButton action="{!cancelQuote}" value="Cancel" immediate="true"/>
             </apex:pageblockButtons>
        </apex:pageBlock>  
        </apex:outputpanel>
    </apex:form>
<script type="text/javascript">
   var currConColumn = '';
                       
            function openDocumentPopup2(obj)
            {
                currConColumn = obj;
                var likeString = "{!Agentid}";   
                var pterms="{!quot.name}";                    
                var url ;
                url = "PaymentTerm_Lookup?likestring="+likeString;
                openWind(url);
               
                return false;
            }
             
            function openWind(URL)
            {
            
                curPopupWindow = window.open(URL, "_blank","width=500, height=400,dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=1", false);            
            }
            
            function setSelectedDocumentDetails2(etId, etName )//, etsub)
            {   
                document.getElementById("j_id0:myForm:payid").value = etId;               
                var inputArr = currConColumn.getElementsByTagName('input');                            
                inputArr[0].value =  etName;
                inputArr[1].value =  etId;
                               
              
                if(curPopupWindow != null)                                                  
                    curPopupWindow.close(); 
                 
                currConColumn = null;
                return false;
                
            }
            
            

</script>
</apex:page>

My controller is 
public class tridentOppDetailOnQuoteController {

    public String lukupdoc2name { get; set; }
    public string hiddendocId{get;set;}
    public String hiddendoc2Id { get; set; }
    public string paymentids{get;set;}
    public String Agentid{ get; set; }
    List<payment_terms__c>  pt;
    List<Account>  acc;
    public boolean render { get; set; }
    public opportunity opp{get;set;}
    public Quote quot{get;set;}
    private Id id1{get;set;} // id of opp
   
    public tridentOppDetailOnQuoteController (){      
    render = true;   
   
        quot = new Quote();         
        Agentid = ApexPages.currentPage().getParameters().get('Agentid');
        id1 = ApexPages.currentPage().getParameters().get('Id');
        if(id1!=null){
                opp= [SELECT Id,Name,Sales_Area__c,SAP_Inquiry_Code__c,Program__r.name,Required_Delivery_Date_First_Delivery__c,
                      Contact__c,Qty_UOM__c,accountid,RecordType.developername,IncoTerm_1_opp__c,Ship_To_Party__c,PaymentTerms__c,Business_Type__c FROM opportunity WHERE Id =:ApexPages.currentPage().getParameters().get('Id')];
            
            if(opp.SAP_Inquiry_Code__c == null){
                   render = false;
                   ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'You cannot create a Quote until SAP Inquiry code is received from SAP'));
                }
               quot.Inco_Terms__c=[Select id,Inco_Terms__c from account where id=:Agentid ].Inco_Terms__c  ;  
              
     /*pt = [Select Id,Account__c,name, Primary__c from  payment_terms__c  where Account__c =: opp.accountid and primary__c = true];
         if(pt.size()>0){
            quot.Payment_Terms__c = pt[0].id;
            lukupdoc2name=pt[0].name;
            }
      else{quot.Payment_Terms__c = null;}*/
      
      acc=[Select Id from  Account  where Name =: opp.Ship_To_Party__c];
      if (acc.size()>0){
      quot.Ship_To_Party__c=acc[0].id;
      }
      else { quot.Ship_To_Party__c=null;}
   RecordType quoteRts =[SELECT Name,id,developername  FROM RecordType WHERE sObjectType='Quote' and developername =:opp.RecordType.developername]; 
   quot.RecordTypeId = quoteRts.id ;
        } }
     public PageReference saveProduct() {
          
          PageReference pr=null;
          try{ 
            //  quot.Business_Criteria__c = [Select Id from Business_Criteria__c where  name= '0000000000'].id;     
              quot.opportunityid=opp.id; 
              quot.agent__c = opp.accountid;
              quot.Required_Delivery_Date__c =opp.Required_Delivery_Date_First_Delivery__c ;
              quot.PaymentTerms__c = opp.PaymentTerms__c;
              quot.IncoTerm_1_quot__c = opp.IncoTerm_1_opp__c;
              quot.contactid= opp.contact__c;
             // quot.SalesArea__c = opp.Sales_Area__c;
              quot.Quantity_UOM__c = opp.Qty_UOM__c;  
              quot.Program__C = opp.Program__r.name;
              quot.Ship_To_Party__c= opp.Ship_To_Party__c;
              /*if(paymentids != '')quot.Payment_Terms__c=paymentids;
              else
              quot.Payment_Terms__c=pt[0].id;*/
              quot.New_Business_Type__c= opp.Business_Type__c;
              insert quot;    
              
             pr =  new PageReference('/' + quot.id); 
              
                       
          }           
          catch(DmlException e){    
         ApexPages.Message msg = new ApexPages.Message(Apexpages.Severity.ERROR,e.getdmlMessage(0));           
         ApexPages.addMessage(msg);               
                          
          }           
          
          return pr;     
          
      }
      
       public pagereference cancelQuote(){
           
           PageReference reference=new PageReference('/'+opp.id);
               reference.setRedirect(true);
               return reference; 
       }
       
     
     
                 
}


PLEASE HELP in geeting the required output.

​Thank in advance for helping
Hi

I have a VF page called as tridentQuotePage on which i select the value of route from customobject name as Route__c.
I also added one outputfield on vf page whose value is getting from business type field of OPPORTUNITY Object which is the picklist with values Export and Domestic.
Now, i want when there is value Export on vf page then route should be filtered to certain value which contains X as second letter in Route__c object.
and 
when i select domestic then, it don't show the value which contains X as second letter in Route__c and show rest of the values.

My VF page is
<apex:page Controller="tridentOppDetailOnQuoteController">
      
    <apex:form id="myForm"> 
    <apex:inputHidden id="payid" value="{!paymentids}" />
    <div style="font-size:18px"> 
    <apex:PageMessages />
    </div>
    <center>
    <apex:commandButton action="{!cancelQuote}" value="Back" rendered="{!!render}" style="Color:blue;width:100px;height:28px;font-size:18px;"/></center>
    <apex:outputpanel rendered="{!render}">
        <apex:pageBlock id="PageBlock">
       
             <apex:pageblockSection columns="2" title="Quotation Details">
                 <apex:inputField value="{!quot.QuoteNumber}"/>
                 <apex:inputField value="{!quot.Inco_Terms__c}" required="true"/>
                 <apex:outputField value="{!opp.PaymentTerms__c}"/>
                 <apex:outputField value="{!opp.IncoTerm_1_opp__c}"/>
                   <!-- <apex:outputText >
          Payment Term  
                    <apex:inputtext value="{!lukupdoc2name}" style="align:left;" id="luckup2id" /><a href ="" style="cursor: pointer" onClick="javascript:return openDocumentPopup2(this.parentNode)" >
                    <img src="/s.gif" alt="Payment Lookup (New Window)" title="Payment Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';"  /></a>
              <br/>
                 
                </apex:outputText>-->
       <!-- <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Payment Term"/>
                                <apex:outputPanel >
                                    <div class="requiredInput">
                                        <div class="requiredBlock"></div>
                                        <apex:inputtext value="{!lukupdoc2name}" style="align:left;" id="luckup2id" /><a href ="" style="cursor: pointer" onClick="javascript:return openDocumentPopup2(this.parentNode)" >
                    <img src="/s.gif" alt="Payment Lookup (New Window)" title="Payment Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';"  /></a>
        
              <br/>
                                    </div>
                                </apex:outputPanel>
                    </apex:pageBlockSectionItem> -->
                 <apex:inputField value="{!quot.Name}"/>
                 <apex:inputField value="{!quot.Inco_Term2__c}" required="true"/>
                 <apex:inputField value="{!quot.Terms_Conditions__c}" required="true"/>
                  <apex:inputField value="{!quot.Route_Name__c}" required="true"/>
                 <apex:outputField value="{!quot.Quote_Status__c}"/>
                 <apex:inputField value="{!quot.Description}"/>
                 <apex:outputField value="{!Opp.name}"/>
                 <apex:outputField value="{!opp.Sales_Area__c}"/> 
                 <apex:outputField value="{!opp.Required_Delivery_Date_First_Delivery__c}"/>
                 <apex:outputField value="{!opp.Accountid}"/>
                 <apex:outputField value="{!quot.Tentative_Delivery_Date__c}" />
                 <apex:outputField value="{!opp.Contact__c}"/>
                 <apex:outputField value="{!quot.Total_Quantity__c}"/>
                 
                 <apex:inputField value="{!quot.For_Record__c}"/>
                 <apex:outputField value="{!opp.Qty_UOM__c}"/> 
                 <apex:inputField value="{!quot.Validity_Date__c}" required="true"/>
                 <apex:outputField value="{!opp.Ship_To_Party__c}" />
                 <!--apex:outputField value="{!opp.Contact__c}" /> -->
                 <apex:outputField value="{!quot.Total_Value__c}"/>
                <!-- <apex:inputField value="{!quot.Payment_Terms__c}" required="true" id="Account"/>-->
                 <apex:outputField value="{!quot.Accepted_Rejected_By__c}"/>
                 <apex:outputField value="{!opp.Business_Type__c}"/>
             </apex:pageblockSection>
              <apex:pageBlockSection >
        
      </apex:pageBlockSection>
             <apex:pageblockSection columns="2" title="Customer Decline">
                 <apex:outputField value="{!quot.Decline_Reason__c}"/>
             </apex:pageblockSection>
             
             <apex:pageblockButtons >
                 <apex:commandButton action="{!saveProduct}" value="Save"/>
                 <apex:commandButton action="{!cancelQuote}" value="Cancel" immediate="true"/>
             </apex:pageblockButtons>
        </apex:pageBlock>  
        </apex:outputpanel>
    </apex:form>
<script type="text/javascript">
   var currConColumn = '';
                       
            function openDocumentPopup2(obj)
            {
                currConColumn = obj;
                var likeString = "{!Agentid}";   
                var pterms="{!quot.name}";                    
                var url ;
                url = "PaymentTerm_Lookup?likestring="+likeString;
                openWind(url);
               
                return false;
            }
             
            function openWind(URL)
            {
            
                curPopupWindow = window.open(URL, "_blank","width=500, height=400,dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=1", false);            
            }
            
            function setSelectedDocumentDetails2(etId, etName )//, etsub)
            {   
                document.getElementById("j_id0:myForm:payid").value = etId;               
                var inputArr = currConColumn.getElementsByTagName('input');                            
                inputArr[0].value =  etName;
                inputArr[1].value =  etId;
                               
              
                if(curPopupWindow != null)                                                  
                    curPopupWindow.close(); 
                 
                currConColumn = null;
                return false;
                
            }
            
            

</script>
</apex:page>

My controller is 
public class tridentOppDetailOnQuoteController {

    public String lukupdoc2name { get; set; }
    public string hiddendocId{get;set;}
    public String hiddendoc2Id { get; set; }
    public string paymentids{get;set;}
    public String Agentid{ get; set; }
    List<payment_terms__c>  pt;
    List<Account>  acc;
    public boolean render { get; set; }
    public opportunity opp{get;set;}
    public Quote quot{get;set;}
    private Id id1{get;set;} // id of opp
   
    public tridentOppDetailOnQuoteController (){      
    render = true;   
   
        quot = new Quote();         
        Agentid = ApexPages.currentPage().getParameters().get('Agentid');
        id1 = ApexPages.currentPage().getParameters().get('Id');
        if(id1!=null){
                opp= [SELECT Id,Name,Sales_Area__c,SAP_Inquiry_Code__c,Program__r.name,Required_Delivery_Date_First_Delivery__c,
                      Contact__c,Qty_UOM__c,accountid,RecordType.developername,IncoTerm_1_opp__c,Ship_To_Party__c,PaymentTerms__c,Business_Type__c FROM opportunity WHERE Id =:ApexPages.currentPage().getParameters().get('Id')];
            
            if(opp.SAP_Inquiry_Code__c == null){
                   render = false;
                   ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'You cannot create a Quote until SAP Inquiry code is received from SAP'));
                }
               quot.Inco_Terms__c=[Select id,Inco_Terms__c from account where id=:Agentid ].Inco_Terms__c  ;  
              
     /*pt = [Select Id,Account__c,name, Primary__c from  payment_terms__c  where Account__c =: opp.accountid and primary__c = true];
         if(pt.size()>0){
            quot.Payment_Terms__c = pt[0].id;
            lukupdoc2name=pt[0].name;
            }
      else{quot.Payment_Terms__c = null;}*/
      
      acc=[Select Id from  Account  where Name =: opp.Ship_To_Party__c];
      if (acc.size()>0){
      quot.Ship_To_Party__c=acc[0].id;
      }
      else { quot.Ship_To_Party__c=null;}
   RecordType quoteRts =[SELECT Name,id,developername  FROM RecordType WHERE sObjectType='Quote' and developername =:opp.RecordType.developername]; 
   quot.RecordTypeId = quoteRts.id ;
        } }
     public PageReference saveProduct() {
          
          PageReference pr=null;
          try{ 
            //  quot.Business_Criteria__c = [Select Id from Business_Criteria__c where  name= '0000000000'].id;     
              quot.opportunityid=opp.id; 
              quot.agent__c = opp.accountid;
              quot.Required_Delivery_Date__c =opp.Required_Delivery_Date_First_Delivery__c ;
              quot.PaymentTerms__c = opp.PaymentTerms__c;
              quot.IncoTerm_1_quot__c = opp.IncoTerm_1_opp__c;
              quot.contactid= opp.contact__c;
             // quot.SalesArea__c = opp.Sales_Area__c;
              quot.Quantity_UOM__c = opp.Qty_UOM__c;  
              quot.Program__C = opp.Program__r.name;
              quot.Ship_To_Party__c= opp.Ship_To_Party__c;
              /*if(paymentids != '')quot.Payment_Terms__c=paymentids;
              else
              quot.Payment_Terms__c=pt[0].id;*/
              quot.New_Business_Type__c= opp.Business_Type__c;
              insert quot;    
              
             pr =  new PageReference('/' + quot.id); 
              
                       
          }           
          catch(DmlException e){    
         ApexPages.Message msg = new ApexPages.Message(Apexpages.Severity.ERROR,e.getdmlMessage(0));           
         ApexPages.addMessage(msg);               
                          
          }           
          
          return pr;     
          
      }
      
       public pagereference cancelQuote(){
           
           PageReference reference=new PageReference('/'+opp.id);
               reference.setRedirect(true);
               return reference; 
       }
       
     
     
                 
}


PLEASE HELP in geeting the required output.

Thank in advance for helping
I have written a apex class with test class both are running but my code coverage is only 66%.Please help to solve the problem.
Apex Class-
global class Deleteoppotest implements Schedulable{

    global void execute(SchedulableContext SC) {
        deleteoppo();
    }

    public static void deleteoppo() {

        for(List<opportunity> objoppo : [SELECT Id FROM opportunity WHERE CreatedDate <= :(Date.Today() - 200) LIMIT 10])
            {
                delete objoppo;
            }    
    }
}

Test Class
@isTest
private class Deleteoppotestcls {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test



        Opportunity op = new Opportunity();
        op.Name = 'test1';
        op.StageName = 'Qualified';
        op.CloseDate = Date.Today();
        op.Description ='testingoppotestcls';
        op.Business_Type__c = 'Domestic';


        insert op;


        Deleteoppotest.deleteoppo();

    }
}

 
I have a one click javascript custom button on my opportunity page and I want to add that button on salesforce1.
Please help to add this button urgently.

ONE CLICK JAVASCRIPT code of that button is as follows:-

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 
var cOpp = new sforce.SObject("Opportunity"); 
var QuoteRecord = sforce.connection.query("Select Opportunity__c,Id From Opportunity_Product__c where Opportunity__c='{!Opportunity.Id}'"); 
var records = QuoteRecord.getArray("records"); 
cOpp.Sales_Area__c = "{!Opportunity.Sales_Area__c}"; 
cOpp.NPD_Required__c = "{!Opportunity.NPD_Required__c}"; 

if(records[0] != null) 

if(!((cOpp.Sales_Area__c == null) || (cOpp.Sales_Area__c == ''))){ 
if((cOpp.NPD_Required__c == true) || (cOpp.NPD_Required__c == 'true')) 
window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=1&scontrolCaching=1','_self'); 
else 
window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=0&scontrolCaching=1','_self'); 

else 
alert('Before trigger to SAP, Please select a SalesArea first.'); 
}
else

alert('You cannot send Opportunity to SAP as no Opportunity Product is associated with it'); 
}
I have a one click javascript custom button on my opportunity page and I want to add that button on salesforce1.
Please help to add this button urgently.


ONE CLICK JAVASCRIPT code of that button is as follows:-

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 
var cOpp = new sforce.SObject("Opportunity"); 
var QuoteRecord = sforce.connection.query("Select Opportunity__c,Id From Opportunity_Product__c where Opportunity__c='{!Opportunity.Id}'"); 
var records = QuoteRecord.getArray("records"); 
cOpp.Sales_Area__c = "{!Opportunity.Sales_Area__c}"; 
cOpp.NPD_Required__c = "{!Opportunity.NPD_Required__c}"; 

if(records[0] != null)

if(!((cOpp.Sales_Area__c == null) || (cOpp.Sales_Area__c == ''))){ 
if((cOpp.NPD_Required__c == true) || (cOpp.NPD_Required__c == 'true')) 
window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=1&scontrolCaching=1','_self'); 
else 
window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=0&scontrolCaching=1','_self'); 

else 
alert('Before trigger to SAP, Please select a SalesArea first.'); 
}
else

alert('You cannot send Opportunity to SAP as no Opportunity Product is associated with it'); 
}
I have apex class against which test class has been written but while Run test it failed due to 1 errors at 3 levels in test

1. FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [SAP_Sales_Area_Number__c]
Attaching Apex class and test class. 
Help in correcting the test class.
 
public class OpportunityTriggerHandler extends TriggerHandler{

    protected override void beforeInsert(){
        setStandardPricebook();
        setRecordTypeFromLeadConversion();
        populateInfoFromSalesArea();
        distributorOpptyRecordType();
    }
    protected override void beforeUpdate(){        
        setStandardPricebook();//Change 0.2
        stampPlant();
        populateInfoFromSalesArea();      
    }
    protected override void afterInsert(){
    }
    protected override void afterUpdate(){
        updateTangible();
    }
    
    public void stampPlant(){        
        Set<Id> optySet = new Set<Id>();
        List<OpportunityLineItem> finaloptyLineItemList = new List<OpportunityLineItem>();
        for(Opportunity opty : (List<Opportunity>)Trigger.New)
        {           
            Opportunity o = (Opportunity)Trigger.oldMap.get(opty.Id);
            if(o.Plant__c != opty.Plant__c)
            {
                optySet.add(opty.Id);         
            }
        }
        
        if(optySet != null && !optySet.isEmpty())
        {
            List<OpportunityLineItem> optyLineItemList = new List<OpportunityLineItem>([Select Id, Plant__c, OpportunityId from OpportunityLineItem where OpportunityId IN:optySet]);
            for(OpportunityLineItem oli : optyLineItemList)
            {
                Opportunity o = (Opportunity)Trigger.newMap.get(oli.OpportunityId);
                oli.Plant__c = o.Plant__c;
                finaloptyLineItemList.add(oli);
            }
        }
        if(finaloptyLineItemList != null && !finaloptyLineItemList.isEmpty())
        {
            update finaloptyLineItemList;
        }
    }
   
    private void updateTangible(){
      
        List<Opportunity> listOpportunityTriggerNew ;
        Map<Id, Opportunity> oldMap ;
        Map<Id, Decimal> mapOpportunityIdToExpectedRevenueChanged ;
        List<Event> listEvent ;
        //Map<Id, List<Event>> mapOpportunityIdToListEvent ;
        Map<Id, Id> mapEventIdToOpportunityId ;
        List<Id> listTourPlanId ;
        Map<Id, Tour_Plan_TI__C> mapTourPlan ;
        final String eventRecordTypeName = 'Planned' ;

        mapOpportunityIdToExpectedRevenueChanged = new Map<id, Decimal>() ;
        listTourPlanId = new List<Id>() ;
        mapEventIdToOpportunityId = new Map<Id, Id>();

        listOpportunityTriggerNew = (List<Opportunity>)Trigger.New ;
        if(Trigger.isUpdate){ oldMap = (Map<Id, Opportunity>)Trigger.oldMap ; }

        for(Opportunity opportunityNew : listOpportunityTriggerNew){
            Decimal newExpectedRevenue;
            Decimal oldExpectedRevenue;
            newExpectedRevenue = (opportunityNew.ExpectedRevenue!=null)?opportunityNew.ExpectedRevenue:0.0;
            oldExpectedRevenue = ((oldMap.get(opportunityNew.Id)).ExpectedRevenue!=null)?(oldMap.get(opportunityNew.Id)).ExpectedRevenue:0.0;

            //Decimal expectedRevenueChange =  opportunityNew.ExpectedRevenue - (oldMap.get(opportunityNew.Id)).ExpectedRevenue ;
            Decimal expectedRevenueChange = newExpectedRevenue -oldExpectedRevenue ;
            if( expectedRevenueChange != Decimal.valueOf(0) ){
                mapOpportunityIdToExpectedRevenueChanged.put(opportunityNew.Id, expectedRevenueChange);
            }
        }

        if( !mapOpportunityIdToExpectedRevenueChanged.isEmpty() ){

            listEvent = [SELECT Id, WhatId, Opportunity_TI__c 
                            FROM Event
                            WHERE Opportunity_TI__c != null
                            AND Opportunity_TI__c IN :mapOpportunityIdToExpectedRevenueChanged.keySet()
                            AND Status_TI__c != 'Cancelled'
                            AND recordType.Name = :eventRecordTypeName];

            for(Event event : listEvent){
                listTourPlanId.add(event.WhatId);
                mapEventIdToOpportunityId.put(event.Id, event.Opportunity_TI__c) ;
            }

            mapTourPlan = new Map<Id,Tour_Plan_TI__C>([SELECT Id, Tangible__c
                            FROM Tour_Plan_TI__C
                            WHERE Id IN :listTourPlanId
                            ]);

            for(Event event : listEvent){
                if((mapTourPlan.get(event.WhatId)).Tangible__c == null){ (mapTourPlan.get(event.WhatId)).Tangible__c = 0.0 ; }
                (mapTourPlan.get(event.WhatId)).Tangible__c += mapOpportunityIdToExpectedRevenueChanged.get( mapEventIdToOpportunityId.get(event.Id) );
            }

            try{   update mapTourPlan.values();  }  catch(Exception e){ System.debug('Error in updating Tour plan tangible on updating opportunity'+e) ; }


        } //if ends

    }//update Tangible method ends

    private void populateInfoFromSalesArea(){

        List<Opportunity> listOpportunityWithSalesArea = new List<Opportunity>()  ;
        Set<Id> setAccountId = new Set<Id>();
        Set<Id> setSalesArea = new Set<Id>();
        Set<String> setSalesOrg = new Set<String>();
        Map<Id, Sales_Area__c> mapSalesArea = new Map<Id, Sales_Area__c>();

         for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
        
            if( opportunity.Sales_Area__c!=null && opportunity.AccountId!=null){
                listOpportunityWithSalesArea.add(opportunity);
                setAccountId.add(opportunity.AccountId);
                setSalesArea.add(Opportunity.Sales_Area__c);
            }
         }

         mapSalesArea = new Map<Id, Sales_Area__c>([SELECT Id, VKORG__c, VTWEG__c, SPART__c, Division__c, Distribution_Channel__c, Sales_Org__c, Unique_Key__c
                                    FROM Sales_Area__c
                                    WHERE ID IN :setSalesArea 
                                        AND SPART__c!=NULL AND VTWEG__c!=NULL AND VKORG__c!=NULL
                                    ]);
         for(Sales_Area__c salesArea : mapSalesArea.values()){
            setSalesOrg.add(salesArea.VKORG__c);
         }

         if(!setSalesArea.isEmpty() && !setAccountId.isEmpty()){
            
            List<Sales_Area_TI__c> listAccountSalesArea = [SELECT Id, CurrencyISOCode, Account_Name__c, Payment_Terms__c, Price_List__c, Incoterms__c, SAP_Sales_Area_Number__c, Incoterms_2__c,
                                                                          SAP_Sales_Area_Number__r.SPART__c, SAP_Sales_Area_Number__r.VTWEG__c, SAP_Sales_Area_Number__r.VKORG__c, SAP_Sales_Area_Number__r.Unique_Key__c      
                                                                FROM Sales_Area_TI__c
                                                                WHERE Account_Name__c IN :setAccountId AND ( SAP_Sales_Area_Number__c IN :setSalesArea OR SAP_Sales_Area_Number__r.VKORG__c IN :setSalesOrg)
                                                                AND Payment_Terms__c!=NULL AND Account_Name__c!=null AND Incoterms__c!=null AND SAP_Sales_Area_Number__c!=NUll
                                                                AND SAP_Sales_Area_Number__r.SPART__c!=NULL AND SAP_Sales_Area_Number__r.VTWEG__c!=NULL AND SAP_Sales_Area_Number__r.VKORG__c!=NULL 
                                                            ];
            Map<Id, List<Sales_Area_TI__c> > mapAccountToAccountSalesArea = new Map<Id, List<Sales_Area_TI__c> > ();
            
            for(Sales_Area_TI__c accountSalesArea : listAccountSalesArea){
                List<Sales_Area_TI__c> listAccSalesArea = new List<Sales_Area_TI__c>();
                if(mapAccountToAccountSalesArea.containsKey(accountSalesArea.Account_Name__c)) listAccSalesArea = mapAccountToAccountSalesArea.get(accountSalesArea.Account_Name__c);
                listAccSalesArea.add(accountSalesArea);
                mapAccountToAccountSalesArea.put(accountSalesArea.Account_Name__c, listAccSalesArea);
            }                                              

            //System.debug('map'+mapAccountToAccountSalesArea);

            Boolean salesAreaMatched = false;
            for(Opportunity opportunity : listOpportunityWithSalesArea){
                salesAreaMatched = false;
                if(mapAccountToAccountSalesArea.containsKey(opportunity.AccountId)){
                    for(Sales_Area_TI__c accountSalesArea : mapAccountToAccountSalesArea.get(opportunity.AccountId)){
                        if(opportunity.AccountId==accountSalesArea.Account_Name__c){
                            if( opportunity.Sales_Area__c!=null && accountSalesArea.SAP_Sales_Area_Number__c!=null && opportunity.Sales_Area__c==accountSalesArea.SAP_Sales_Area_Number__c ){
                               salesAreaMatched = true; 
                            }
                            else if( (mapSalesArea.get(opportunity.Sales_Area__c)).VKORG__c!=null &&  accountSalesArea.SAP_Sales_Area_Number__r.VKORG__c!=null && (mapSalesArea.get(opportunity.Sales_Area__c)).VKORG__c == accountSalesArea.SAP_Sales_Area_Number__r.VKORG__c){
                                //if(Distri Channel left1 matches && division matches)
                                String opptySalesAreaDistriChannel = (mapSalesArea.get(opportunity.Sales_Area__c)).VTWEG__c;
                                String accountSalesAreaDistriChannel = accountSalesArea.SAP_Sales_Area_Number__r.VTWEG__c;
                                System.debug('opptySalesAreaDistriChannel '+opptySalesAreaDistriChannel+'   accountSalesAreaDistriChannel '+accountSalesAreaDistriChannel);
                                if( opptySalesAreaDistriChannel!=null &&  accountSalesAreaDistriChannel!=null && ((accountSalesAreaDistriChannel.left(2)).right(1))=='0' &&  opptySalesAreaDistriChannel.left(1)==accountSalesAreaDistriChannel.left(1)){
                                    //check division matches
                                    if( (mapSalesArea.get(opportunity.Sales_Area__c)).SPART__c == accountSalesArea.SAP_Sales_Area_Number__r.SPART__c ){
                                        salesAreaMatched = true;
                                    }
                                    else if( accountSalesArea.SAP_Sales_Area_Number__r.SPART__c=='01'){
                                        salesAreaMatched = true;
                                    }
                                }
                            }
                                                       
                            if(salesAreaMatched)
                            {
                                if(Trigger.isInsert){ opportunity.CurrencyISOCode = accountSalesArea.CurrencyISOCode; }
                                opportunity.Account_Sales_Area_TI__c = accountSalesArea.Id;
                                //opportunity.INCO_Term__c = accountSalesArea.Incoterms__c; /* Commented by Trident Team*/
                                if(!String.isBlank(accountSalesArea.Price_List__c))
                                opportunity.Price_List__c = accountSalesArea.Price_List__c;
                               
                              /* Edited by Trident Team */  
                                if(Trigger.isInsert && Trigger.isBefore && opportunity.Payment_Term__c == null && opportunity.INCO_Term__c ==null )
                                {
                                    opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                    opportunity.INCO_Term__c = accountSalesArea.Incoterms__c;
                                }
                                else if(Trigger.isUpdate && Trigger.isBefore)
                                {
                                    Opportunity tempOpty = (Opportunity)Trigger.oldMap.get(opportunity.Id);
                                    if(tempOpty.Sales_Area__c != null && tempOpty.Sales_Area__c != opportunity.Sales_Area__c && tempOpty.Payment_Term__c == opportunity.Payment_Term__c && tempOpty.INCO_Term__c == opportunity.INCO_Term__c )
                                    {
                                        opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                        opportunity.INCO_Term__c = accountSalesArea.Incoterms__c;
                                    }
                                }
                                /*Edited Ends here*/
                                //opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                opportunity.INCO_Term_Location__c = accountSalesArea.Incoterms_2__c;
                                break;
                            }
                        } // account ID match check
                            
                    }//for loop ends
                }

                if(!salesAreaMatched){ opportunity.addError('No such sales area on account');  }
            }//oppty for loop ends

        }//if set not empty
     
    }// populateInfoFromSalesArea ends

    private void setRecordTypeFromLeadConversion(){


        List<RecordType> listRecordType = [SELECT Id, DeveloperName FROM RecordType WHERE sObjectType='Opportunity'];
        Map<String, Id> mapRecordTypeNametoId = new Map<String, Id>();
        for(RecordType recordType : listRecordType){
            mapRecordTypeNametoId.put(recordType.DeveloperName, recordType.Id); 
        }

       System.debug(mapRecordTypeNametoId);

        for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
            if(opportunity.Record_Type_Name_Lead__c!=null){
                System.debug('Record_Type_Name_Lead__c '+opportunity.Record_Type_Name_Lead__c);

                if( opportunity.Record_Type_Name_Lead__c.contains('International Bathrobe') &&  mapRecordTypeNametoId.containsKey('International_Bathrobe_TI')  ){ opportunity.RecordTypeId = mapRecordTypeNametoId.get('International_Bathrobe_TI'); }
                else if( opportunity.Record_Type_Name_Lead__c.contains('International Sheeting') &&  mapRecordTypeNametoId.containsKey('International_Sheeting_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('International_Sheeting_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('International Towel') &&  mapRecordTypeNametoId.containsKey('International_Towel_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('International_Towel_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Domestic Bathrobe') &&  mapRecordTypeNametoId.containsKey('Domestic_Bathrobe_TI')  ){ opportunity.RecordTypeId = mapRecordTypeNametoId.get('Domestic_Bathrobe_TI'); }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Domestic Sheeting') &&  mapRecordTypeNametoId.containsKey('Domestic_Sheeting_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Domestic_Sheeting_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Domestic Towel') &&  mapRecordTypeNametoId.containsKey('Domestic_Towel_TI') ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Domestic_Towel_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Yarn') &&  mapRecordTypeNametoId.containsKey('Yarn_TI')   ){ opportunity.RecordTypeId = mapRecordTypeNametoId.get('Yarn_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Paper') && mapRecordTypeNametoId.containsKey('Paper_TI')  ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Paper_TI') ; }
                else if( opportunity.Record_Type_Name_Lead__c.contains('Chemical') && mapRecordTypeNametoId.containsKey('Chemical_TI')  ){ opportunity.RecordTypeId =  mapRecordTypeNametoId.get('Chemical_TI') ; }
            }
        }
    } //setRecordTypeFromLeadConversion ends    

    private void distributorOpptyRecordType(){

        for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
            if(opportunity.Distributor_Opportunity_TI__c){
                User opptyOwner = new User(Id=opportunity.OwnerId);

                System.runAs(opptyOwner){
                    for(Schema.RecordTypeInfo recordTypeInfoObject : Schema.Opportunity.sObjectType.getDescribe().getRecordTypeInfos()) {
                        if(recordTypeInfoObject.isDefaultRecordTypeMapping() ) {
                            opportunity.RecordTypeId = recordTypeInfoObject.getRecordTypeId();
                        }
                    } 
                }
            }
        }//for loop ends
    
    }  //distributorOpptyRecordType ends

    private void setStandardPricebook(){

        Id idstandardPriceBook = '01sD0000000FXh7IAG'; //dummy value for initiation

        try{
            idstandardPriceBook = [SELECT Id FROM PriceBook2 WHERE IsStandard = true AND Unique_Key__c='StandardPricebook'][0].Id;
        }
        catch(Exception e){
            if(Test.isRunningTest()){
                idstandardPriceBook = Test.getStandardPricebookId();
            }
        }
        for(Opportunity opportunity : (List<Opportunity>)Trigger.New){
            opportunity.Pricebook2Id = idstandardPriceBook;
        }
    }//setStandardPricebook ends
}//Opportunity trigger handler class ends
 
@isTest
public class OpportunityTriggerTest {

    @testSetup
    public static void setup(){     

        TestDataFactory.createTriggerCustomSettings();
        
    }//setup ends



    public static testmethod void testUpdateTangible(){
        //create opportunity
        //create tour plan
        //create event

        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        insert account;

        Opportunity opportunity = (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        insert opportunity;

        Tour_Plan_TI__c tourPlan = (Tour_Plan_TI__c)SmartFactory.createSObject('Tour_Plan_TI__c');
        tourPlan.Status__c = 'Approved';
        tourPlan.Start_Date__c = (Date.today()).addDays(1);
        tourPlan.End_Date__c = (Date.today()).addDays(3);
        insert tourPlan;

        Event event = ((List<Event>)TestDataFactory.createPlannedEvents(1))[0];
        event.ActivityDate = (Date.today()).addDays(2);
        event.ActivityDateTime = (Date.today()).addDays(2);
        event.WhatId = tourPlan.Id;
        event.Opportunity_TI__c = opportunity.Id;
        insert event;

        //update the Opportunity
        opportunity.Amount = 112;
        update opportunity;

            
    }//testupdateTangible ends


    public static testmethod void testSetRecordTypeFromLeadConversion(){
        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];

        insert account;

        
        List<Opportunity> listOpportunity = (List<Opportunity>)SmartFactory.createSObjectList('Opportunity',false,5);

        List<Schema.RecordTypeInfo> leadRecordTypes = Lead.getSObjectType().getDescribe().getRecordTypeInfos();

        Set<Id> setOfRecordTypeIdUsed = new Set<Id>();

        for(Opportunity opportunity : listOpportunity){

            opportunity.AccountId = account.Id;

            for (Schema.RecordTypeInfo recordType : leadRecordTypes) {
                    if (recordType.isAvailable() && recordType.isActive()) {
                        if(!setOfRecordTypeIdUsed.contains(recordType.getRecordTypeId())){ //check if same record type is used already
                            opportunity.put('Record_Type_Name_Lead__c', recordType.getName());
                            setOfRecordTypeIdUsed.add(recordType.getRecordTypeId());
                            break;
                        }                       
                    }
                }
        }

        insert listOpportunity;

    }


    public static testmethod void testDistributorOpptyRecordType(){
        
        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];

        insert account;

        
        
        Opportunity opportunity = (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        opportunity.Distributor_Opportunity_TI__c = true;
        //insert opportunity;


    }

    //same sales area direct match
    public static testmethod void testPopulateInfoFromSalesArea(){
        Sales_Area__c salesArea = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        insert salesArea;

        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        insert account;

        SmartFactory.FillAllFields = true;
        Payment_Terms__c paymentTerms = (Payment_Terms__c)SmartFactory.createSObject('Payment_Terms__c');
        insert paymentTerms;
        Sales_Area_TI__c accountSalesArea = (Sales_Area_TI__c)SmartFactory.createSObject('Sales_Area_TI__c');
        SmartFactory.FillAllFields = false;
        accountSalesArea.Account_Name__c = account.Id;
        accountSalesArea.SAP_Sales_Area_Number__c = salesArea.Id;
        accountSalesArea.Payment_Terms__c = paymentTerms.Id;
        accountSalesArea.Incoterms__c = 'CFR';
        insert accountSalesArea;

        //same sales area direct match
        Opportunity opportunity =  (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        opportunity.Sales_Area__c= salesArea.Id;
        insert opportunity;
    }


    //different sales area fuzzy match
    public static testmethod void testPopulateInfoFromSalesArea2(){     
        Sales_Area__c salesArea1 = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        salesArea1.VKORG__c = 'same';
        salesArea1.VTWEG__c='10';
        salesArea1.SPART__c='01';
        insert salesArea1;

        //division 01 match
        Sales_Area__c salesArea2 = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        salesArea2.VKORG__c = 'same';
        salesArea2.VTWEG__c='12';
        salesArea2.SPART__c='23';
        insert salesArea2;

        //division exact match
        Sales_Area__c salesArea3 = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        salesArea3.VKORG__c = 'same';
        salesArea3.VTWEG__c='12';
        salesArea3.SPART__c='01';
        insert salesArea3;



        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        insert account;

        SmartFactory.FillAllFields = true;
        Payment_Terms__c paymentTerms = (Payment_Terms__c)SmartFactory.createSObject('Payment_Terms__c');
        insert paymentTerms;
        Sales_Area_TI__c accountSalesArea = (Sales_Area_TI__c)SmartFactory.createSObject('Sales_Area_TI__c');
        SmartFactory.FillAllFields = false;
        accountSalesArea.Account_Name__c = account.Id;
        accountSalesArea.SAP_Sales_Area_Number__c = salesArea1.Id;
        accountSalesArea.Payment_Terms__c = paymentTerms.Id;

        insert accountSalesArea;

        Opportunity opportunity =  (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity.AccountId = account.Id;
        opportunity.Sales_Area__c= salesArea2.Id;
        insert opportunity;


        Opportunity opportunity2 =  (Opportunity)SmartFactory.createSObject('Opportunity');
        opportunity2.AccountId = account.Id;
        opportunity2.Sales_Area__c= salesArea3.Id;
        insert opportunity2;



    }

    public static testmethod void testStampPlant(){

        

        String productCode1 = 'A1';


        //Product
        Product2 product = new Product2(Name='TestProduct 1', SAP_Product_Code__c = productCode1, isActive=true);
        insert product;

        PriceBookEntry pbeStandard = new PriceBookEntry(
            Product2Id = product.Id, Pricebook2Id = Test.getStandardPricebookId(), UnitPrice = 10, CurrencyISOCode ='INR', isActive=true);
        insert pbeStandard;

       
       
        Sales_Area__c salesArea = ((List<Sales_Area__c>)TestDataFactory.createSalesAreas(1))[0];
        insert salesArea;

        //add plant on oppty
        Plant__c plant = (Plant__c)SmartFactory.createSObject('Plant__c');
        insert plant;

         //create Product Sales Area
        Product_Sales_Area__c productSalesArea = new Product_Sales_Area__c(
            Material_Code__c = product.Id, Sales_Area__c = salesArea.Id);
        insert productSalesArea;


        Account account = ((List<Account>)TestDataFactory.createAccounts(1))[0];
        account.CurrencyISOCode = 'INR';
        insert account;

        SmartFactory.FillAllFields = true;
        Payment_Terms__c paymentTerms = (Payment_Terms__c)SmartFactory.createSObject('Payment_Terms__c');
        insert paymentTerms;
        Sales_Area_TI__c accountSalesArea = (Sales_Area_TI__c)SmartFactory.createSObject('Sales_Area_TI__c');
        SmartFactory.FillAllFields = false;
        accountSalesArea.Account_Name__c = account.Id;
        accountSalesArea.SAP_Sales_Area_Number__c = salesArea.Id;
        accountSalesArea.Payment_Terms__c = paymentTerms.Id;
        accountSalesArea.CurrencyISOCode ='INR';
        insert accountSalesArea;

        //same sales area direct match
        Opportunity opportunity =  (Opportunity)SmartFactory.createSObject('Opportunity');
        //set yarn recordtype
        opportunity.Business_Division__c='Yarn';
        opportunity.AccountId = account.Id;
        opportunity.Sales_Area__c= salesArea.Id;
        opportunity.CurrencyISOCode ='INR';
        insert opportunity;


        //positiveTest
        OpportunityLineItem oli = new OpportunityLineItem(
            Product_Code__c= productCode1, OpportunityId=opportunity.Id, Quantity=5);

        insert oli;
        try{
            opportunity.Plant__c = plant.Id;
            update opportunity;
        }catch(Exception e){}
       

    }   


}

 
Need to understand what this lines of Trigger actually means as I'm new to Triggers.
if(salesAreaMatched)
							{
                                if(Trigger.isInsert)
								{ 
								opportunity.CurrencyISOCode = accountSalesArea.CurrencyISOCode; 
								}
                                opportunity.Account_Sales_Area_TI__c = accountSalesArea.Id;
                                opportunity.INCO_Term__c = accountSalesArea.Incoterms__c;
                                if(!String.isBlank(accountSalesArea.Price_List__c))
                                opportunity.Price_List__c = accountSalesArea.Price_List__c;
                                
                                if(Trigger.isInsert && Trigger.isBefore && opportunity.Payment_Term__c == null)
                                {
                                    opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                }
                                else if(Trigger.isUpdate && Trigger.isBefore)
                                {
                                    Opportunity tempOpty = (Opportunity)Trigger.oldMap.get(opportunity.Id);
                                    if(tempOpty.Sales_Area__c != null && tempOpty.Sales_Area__c != opportunity.Sales_Area__c && tempOpty.Payment_Term__c == opportunity.Payment_Term__c)
                                    {
                                        opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                    }
                                }
                                //opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                opportunity.INCO_Term_Location__c = accountSalesArea.Incoterms_2__c;
                                break;
                            }

 
How can i write the validation rule in which on changing value in Opportunity Picklist value it compares the value with 2 picklist fields of custom object .
If value in Opportunity picklist is matches with the any of the 1 field of custom object then it saves record otherwise it throws the error.

I have write the following validation rule but it didn't work.

Kindly help in correcting the validation rule.
TEXT(INCO_Term__c) <> "" && 
OR( 
TEXT(INCO_Term__c) <> TEXT(Account_Sales_Area_TI__r.Inco__c) , 
TEXT(INCO_Term__c) <> TEXT(Account_Sales_Area_TI__r.Incoterms__c) 
)

 
Akash Garg 
error of test class while deploying trigger to Production from Sandbox
Hello,
I got below error of another apex test class while deploying my trigger and trigger test class to production.
User-added image
My Trigger Test Class i trying to deploy is:-
 
trigger QuoteTriggerInsertQPG on Quote (after insert) {
if(!QuoteInsertFromTriggerHelpper.InsideQuoteInsert){

    
    for(Quote qqq : trigger.new){
    if(qqq.merging__c != true){
   
    map<Id,Quote> QMap = new map<Id,Quote>([select Id, OpportunityId, RecordtypeId,NPD_Required__c, RecordType.developerName from quote 
        where Id IN: trigger.new]);
        List<Quote> quoteId = new List<Quote>();
    Set<String> RecordTypeDevNames = new set<String>();
    set<Id> oppIds = new set<Id>();
    list<Quote_Product_Group__c> QPGlist = new list<Quote_Product_Group__c>();
    list<Quote_Product__c> QPlist = new list<Quote_Product__c>();
    map<Id,Quote_Product_Group__c> QPGmap = new map<Id,Quote_Product_Group__c>();
    
    if(QMap.values()[0].npd_required__c == true){
     
    for(Quote q: QMap.values()){
        RecordTypeDevNames.add(q.RecordType.developerName);
        oppIds.add(q.OpportunityId);
        quoteId.add(q);
    }
    list<recordType> QPRecordTypes = [select Id, DeveloperName from RecordType 
        where sObjectType='Quote_Product__c' and developerName IN: RecordTypeDevNames];
    list<recordType> QPGRecordTypes = [select Id, DeveloperName from RecordType 
        where sObjectType='Quote_Product_Group__c' and developerName IN: RecordTypeDevNames];
    map<Id,Opportunity> Map_oppPG_oppP = new map<Id,Opportunity>([select Id, AccountId, 
        (select id, Account__c,Program_name__c,Quality_reference__c,Opportunity__c,Number_of_Sizes__c,Model__c,
            Fabric_Type__c,Fabric_Design_Type__c,Required_Price_Pc__c,Required_Price_kg__c,Quantity__c,Quantity_UOM__c,
            Packaging_Type_Gross_Level__c,Packaging_Type_Carton_Level__c,Pile_Cotton_Quality_Type__c,Short_Description__c,
            QualityDesign_Type__c,Pile_Yarn_Type__c,Pile_Yarn_Description__c,recordtype.developername from opportunity_product_Groups__r
        ),
        (select id,size_wise_ratio__c,SORTNO_SAP__c,Converted_from_Lead__c,Accessories__c,Private_Label__c,Type_of_pulp__c,npd_flag__c,
            Hanger_Needed__c,Stitch_Type__c,Bartuck_Needed__c, Opportunity_Product_Group__c, Process__c,Count__c,Type__c,
            Other_Spl_Requirment__c,Shade_Reference__c,Required_Price_kg__c,Packing__c,Spl_Requirement__c,
            Raw_Material_3_Per__c,Raw_Material_3__c,Raw_Material_2__c,Raw_Material_2_Per__c,Raw_Material_1__c,Quantity__c,
            End_use__c,Ply__c,Raw_Material__c,Product_form__c,Reel_Width__c,Reel_Width_UOM__c,Sheet_Length__c,
            Sheet_Length_UOM__c,Sheet_Breadth__c,Sheet_Breadth_UOM__c,Ash__c,With_Watermark__c,plant__c,
            No_of_Watermarks_as_per_A3_sheet__c,shade__c,OPacity__c,Cobb_UOM__c,Cobb__c,Whiteness__c,
            Brightness_UOM__c,Brightness__c,GSM_UOM__c,Bulk_CC_gm__c,Quantity_UOM__c,
            Num_of_stitches_1000_size__c,Names_of_Sizes_Bathrobe__c,For__c,Names_of_Sizes__c,Size_Tolerance__c,
            Tolerance_weight__c,Product__c,Test_Protocol__c,Customer_Test_Protocol__c,Needle_Type__c,Pile_Blend__c,
            Sample_Sort__c,Costing_Depth__c,Printed__c,Finish__c,width__c,length__c,size_uom__c,
            Number_of_Colors_Styles__c,Embroidery_Applique__c,Wt_Pc__c,Is_Existing__c,Short_Description__c,
            If_Beach__c,GSM__c,recordtype.developername,SAP_Labdip_Item_No__c,LABDIP_ITEM_SAP__c,T_YARN_COUNT__c, T_YARN_MIXING__c, T_NPD_PRODUCT_TYPE_MY__c, T_YARN_MELANGETYPE__c, T_BLEND_TYPE_NPD__c, T_NPD_DYED_PART__c,T_REAMRK1__c,
            T_YARN_ENDUSE_PLY__c, T_YARN_PLY_COUNT_NPD__c, T_NPD_PLANT__c, Process_Depth_Type__c, T_YRN_PP_SHADE_DEPTH__c, Remark_2__c,Yarn_Product_Type__c
            from opportunity_products__r where Technical_Feasibility__c !='FAILED' and SORTNO_SAP__c != ''
        )
        from Opportunity where Id IN: oppIds]);
    map<String, RecordType> MapQPRecordTypes = new map<String, RecordType>();
    map<String, RecordType> MapQPGRecordTypes = new map<String, RecordType>();
    for(RecordType QPRT : QPRecordTypes){
        if(!MapQPRecordTypes.containsKey(QPRT.developerName)){
            MapQPRecordTypes.put(QPRT.developerName,QPRT);
        }
    }
    for(RecordType QPGRT : QPGRecordTypes){
        if(!MapQPGRecordTypes.containsKey(QPGRT.developerName)){
            MapQPGRecordTypes.put(QPGRT.developerName,QPGRT);
        }
    }
    for(Quote q : trigger.new){
        if(QMap.containsKey(q.Id)){
            String RTdevName = QMap.get(q.id).recordtype.developerName;
            if(RTdevName == 'Bathrobe' || RTdevName == 'Sheeting' || RTdevName == 'Towel' || RTdevName == 'International_Sheeting'){
                if(Map_oppPG_oppP.containsKey(q.OpportunityId)){
                    integer OPG_count = 0;
                    for(opportunity_product_Group__c opg : Map_oppPG_oppP.get(q.OpportunityId).opportunity_product_Groups__r){
                        Quote_Product_Group__c qpg = new Quote_Product_Group__c();
                        if(OPG_count == 0){
                            qpg.Quote__c = q.Id;
                        }else{
                            qpg.Quote__c = QuoteInsertFromTriggerHelpper.CreateQuote(q).Id;
                        }
                        OPG_count++;
                        qpg.Number_of_Sizes__c = opg.Number_of_Sizes__c;
                        qpg.Quality_Reference__c =opg.Quality_Reference__c;
                        qpg.Account__c = opg.Account__c;
                        qpg.Program_name__c = opg.Program_name__c;
                        qpg.Short_Description__c =opg.Short_Description__c ;
                        qpg.Quality_Design_Type__c = opg.QualityDesign_Type__c;
                        qpg.Pile_Yarn_Type__c = opg.Pile_Yarn_Type__c;
                        qpg.Other_Pile_Yarn_Type__c = opg.Pile_Yarn_Description__c;
                        qpg.Pile_Cotton_Quality_Type__c = opg.Pile_Cotton_Quality_Type__c;
                        qpg.Packaging_Type_Carton_Level__c = opg.Packaging_Type_Carton_Level__c;
                        qpg.Packaging_Type_Gross_Level__c = opg.Packaging_Type_Gross_Level__c;
                        qpg.Quantity__c = opg.Quantity__c;
                        qpg.Quantity_UOM__c = opg.Quantity_UOM__c;
                        if(MapQPGRecordTypes.containsKey(RTdevName)){
                            qpg.recordtypeId = MapQPGRecordTypes.get(RTdevName).Id;
                        }
                        if(opg.recordtype.developername == 'Towel'|| opg.recordtype.developername == 'Sheeting'){
                            qpg.Required_Price_Kg__c = opg.Required_Price_Kg__c;
                        }else if(opg.recordtype.developername == 'Bathrobe'){
                            qpg.Model__c = opg.Model__c;
                            qpg.Fabric_type__c = opg.Fabric_Type__c;
                            qpg.Fabric_Design_Type__c = opg.Fabric_Design_Type__c;
                            qpg.Required_Price_Pc__c = opg.Required_Price_Pc__c;
                        }
                        QPGlist.add(qpg);
                        QPGmap.put(opg.Id,qpg);
                        
                    }
                 }
            }
        }
    }
    insert QPGlist;
    for(Quote q : trigger.new){
        if(QMap.containsKey(q.Id)){
            String RTdevName = QMap.get(q.id).recordtype.developerName;
            if(Map_oppPG_oppP.containsKey(q.OpportunityId)){
                for(opportunity_product__c op : Map_oppPG_oppP.get(q.OpportunityId).opportunity_products__r){
                    Quote_Product__c qp= new Quote_Product__c();
                    if(QPGmap.containsKey(op.Opportunity_Product_Group__c)){ 
                        qp.Quote_Product_Group__c = QPGmap.get(op.Opportunity_Product_Group__c).Id;
                        qp.quote__c = QPGmap.get(op.Opportunity_Product_Group__c).quote__c;
                    }
                    else{qp.Quote__c = quoteId[0].id;}
                    qp.Product__c = op.Product__c;
                    qp.Is_Existing__c = op.Is_Existing__c;
                    qp.T_NPD_PLANT__c = op.plant__c;
                    if(MapQPRecordTypes.containsKey(RTdevName)){
                        qp.recordtypeId = MapQPRecordTypes.get(RTdevName).Id;
                    }
                    qp.Short_Description__c =  op.Short_Description__c;
                    if(op.recordtype.developername == 'Towel'|| op.recordtype.developername == 'Sheeting' || op.recordtype.developername == 'Bathrobe'){
                       
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.If_Beach__c = op.If_Beach__c;
                        qp.GSM__c = op.GSM__c;
                        qp.Wt_Pc_gms__c = op.Wt_Pc__c;
                        qp.Embroidery_Applique__c = op.Embroidery_Applique__c;
                        qp.of_Colors_Styles__c =op.Number_of_Colors_Styles__c;
                        qp.Finish__c = op.Finish__c;
                        qp.width__c = op.width__c;
                        qp.length__c =op.length__c;
                        qp.size_uom__c = op.size_uom__c;
                        qp.Printed__c =op.Printed__c;
                        qp.Costing_Depth__c = op.Costing_Depth__c;
                        qp.Quantity_UOM__c=op.Quantity_UOM__c;
                        qp.Sample_Sort_Ref__c = op.Sample_Sort__c;
                        qp.Pile_Blend__c = op.Pile_Blend__c;
                        qp.Needle_Type__c = op.Needle_Type__c;
                        qp.Bartuck_Needed__c = op.Bartuck_Needed__c;
                        qp.Stitch_Type__c = op.Stitch_Type__c;
                        qp.Hanger_Needed__c =op.Hanger_Needed__c;
                        qp.Customer_Test_Protocol__c =op.Customer_Test_Protocol__c;
                        qp.Test_Protocol_Customer__c = op.Test_Protocol__c;
                        qp.Short_Description__c =  op.Short_Description__c;
                        qp.size_wise_ratio__c = op.size_wise_ratio__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.SAP_Sort_No__c = op.SORTNO_SAP__c;
                        if(!qp.Is_Existing__c &&qp.Product__c ==null){
                            if(qp.GSM__c!=null)
                            {
                            qp.Wt_Pc_gms__c = (qp.GSM__c*(qp.Length__c*qp.Width__c))/1000;
                            }
                            else if(qp.GSM__c== null && qp.Wt_Pc_gms__c !=null)
                            {
                            qp.GSM__c =  (qp.Wt_Pc_gms__c*1000)/(qp.Length__c*qp.Width__c);
                            }
                        }
                    }
                    if(op.recordtype.developername == 'Towel' || op.recordtype.developername == 'Sheeting'){
                        qp.Names_of_Sizes__c = op.Names_of_Sizes__c;
                        qp.Tolerance_weight__c =op.Tolerance_weight__c;
                        qp.Size_Tolerance__c = op.Size_Tolerance__c;
                    }
                    if(op.recordtype.developername == 'Towel'){
                        qp.labdip_flag__c = op.npd_flag__c; 
                    }                   
                    if(op.recordtype.developername == 'Bathrobe'){
                        qp.For__c = op.For__c;
                        qp.Names_of_Sizes__c = op.Names_of_Sizes_Bathrobe__c;
                        qp.Num_of_stitches_1000_size__c =op.Num_of_stitches_1000_size__c;
                        qp.Accessories__c =op.Accessories__c;
                    }else if(op.recordtype.developername == 'Paper'){
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Quantity_UOM__c=op.Quantity_UOM__c;
                        qp.Bulk_CC_gm__c= op.Bulk_CC_gm__c;
                        qp.GSM__c = op.GSM__c;
                        qp.GSM_UOM__c =op.GSM_UOM__c;
                        qp.Brightness__c = op.Brightness__c;
                        qp.Brightness_UOM__c = op.Brightness_UOM__c;
                        qp.Whiteness__c = op.Whiteness__c ;
                        qp.Cobb__c = op.Cobb__c;
                        qp.Cobb_UOM__c = op.Cobb_UOM__c;
                        qp.OPacity__c =op.OPacity__c;
                        qp.Product_form__c = op.Product_form__c;
                        qp.Reel_Width__c =op.Reel_Width__c;
                        //qp.Reel_Width_UOM__c =op.Reel_Width_UOM__c;
                        qp.Sheet_Length__c =op.Sheet_Length__c;
                        //qp.Sheet_Length_UOM__c =op.Sheet_Length_UOM__c;
                        qp.Sheet_Breadth__c =op.Sheet_Breadth__c ;
                        qp.Size_UOM__c = op.Size_UOM__c;
                        //qp.Sheet_Breadth_UOM__c =op.Sheet_Breadth_UOM__c ;
                        qp.Ash__c = op.Ash__c;
                        qp.With_Watermark__c =op.With_Watermark__c ;
                        qp.No_of_Watermarks_as_per_A3_sheet__c= op.No_of_Watermarks_as_per_A3_sheet__c;
                        qp.shade__c =op.shade__c;
                        qp.Type_of_pulp__c = op.Type_of_pulp__c;
                        qp.Private_Label__c = op.Private_label__c;
                    }else if(op.recordtype.developername == 'Dyed_Yarn'){
                        
                        qp.SAP_Labdip_Recipe__c = op.SAP_Labdip_Item_No__c;
                        qp.SAP_Labdip_Item__c = op.LABDIP_ITEM_SAP__c;
                        qp.labdip_flag__c = op.npd_flag__c;
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Process__c = op.Process__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Count__c = op.Count__c;
                        qp.Type__c = op.Type__c;
                        qp.End_Use__c = op.End_use__c;
                        qp.Ply__c = op.Ply__c;
                        qp.Raw_Material_1__c = op.Raw_Material__c;
                        qp.Raw_Material_1_per__c = op.Raw_Material_1__c;
                        qp.Raw_Material_2__c =op.Raw_Material_2__c;
                        qp.Raw_Material_2_pre__c= op.Raw_Material_2_Per__c;
                        qp.Raw_Material_3__c = op.Raw_Material_3__c;
                        qp.Raw_Material_3_per__c = op.Raw_Material_3_Per__c;
                        qp.Shade_Reference__c =op.Shade_Reference__c;
                        qp.Required_Price_kg__c = op.Required_Price_kg__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Quantity_UOM__c = op.Quantity_UOM__c;
                        qp.Packing__c = op.Packing__c;
                        qp.Spl_Requirement__c = op.Spl_Requirement__c;
                        qp.Other_Spl_Requirement__c = op.Other_Spl_Requirment__c;
                         //added as per Sharad for mapping for Quote PDF
                        qp.Yarn_Cone_Weight__c = ''+op.T_YARN_CONEWEIGHT__c;
                        qp.Yarn_Packaging_Style__c = op.T_YARN_PACKINGSTYLE__c;
                        qp.Yarn_Packaging_Type__c = op.T_YARN_PACKINGTYPE__c;
                        qp.Yarn_Waxing__c = op.T_YARN_WAXING__c;
                        qp.Net_Weight_per_carton__c = op.Net_Weight_per_carton__c;
                        qp.Net_Weight_per_pallet__c = op.Net_Weight_per_pallet__c;
   
                        qp.depth__c = op.Process_Depth_Type__c;

                        
                        
                     }else if(op.recordtype.developername == 'Melange_Yarn'){
                     
                        qp.SAP_Labdip_Recipe__c = op.SAP_Labdip_Item_No__c;
                        qp.SAP_Labdip_Item__c = op.LABDIP_ITEM_SAP__c;
                        qp.labdip_flag__c = op.npd_flag__c;     
                        qp.Opp_Product_Id__c = op.id;                  
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Process__c = op.Process__c;
                        qp.Count__c = op.Count__c;
                        qp.Type__c = op.Type__c;
                        qp.End_Use__c = op.End_use__c;
                        qp.Ply__c = op.Ply__c;
                        qp.Raw_Material_1__c = op.Raw_Material__c;
                        qp.Raw_Material_1_per__c = op.Raw_Material_1__c;
                        qp.Raw_Material_2__c =op.Raw_Material_2__c;
                        qp.Raw_Material_2_pre__c= op.Raw_Material_2_Per__c;
                        qp.Raw_Material_3__c = op.Raw_Material_3__c;
                        qp.Raw_Material_3_per__c = op.Raw_Material_3_Per__c;
                        qp.Shade_Reference__c =op.Shade_Reference__c;
                        qp.Required_Price_kg__c = op.Required_Price_kg__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Quantity_UOM__c = op.Quantity_UOM__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Packing__c = op.Packing__c;
                        qp.Spl_Requirement__c = op.Spl_Requirement__c;
                        qp.Other_Spl_Requirement__c = op.Other_Spl_Requirment__c;
                        //added as per Sharad for mapping for Quote PDF
                        qp.Yarn_Cone_Weight__c = ''+op.T_YARN_CONEWEIGHT__c;
                        qp.Yarn_Packaging_Style__c = op.T_YARN_PACKINGSTYLE__c;
                        qp.Yarn_Packaging_Type__c = op.T_YARN_PACKINGTYPE__c;
                        qp.Yarn_Waxing__c = op.T_YARN_WAXING__c;
                        qp.Net_Weight_per_carton__c = op.Net_Weight_per_carton__c;
                        qp.Net_Weight_per_pallet__c = op.Net_Weight_per_pallet__c;
                        
                        //added on 03/10/15
                        qp.T_YARN_COUNT__c = op.T_YARN_COUNT__c;
                        qp.T_YARN_MIXING__c = op.T_YARN_MIXING__c;
                        // ***** Edited due to duplicate mapping (23-03)
                        //qp.T_NPD_PRODUCT_TYPE_MY__c = op.T_NPD_PRODUCT_TYPE_MY__c;                        
                        qp.T_NPD_PRODUCT_TYPE_MY__c = op.Yarn_Product_Type__c;
                        
                        qp.T_YARN_MELANGETYPE__c = op.T_YARN_MELANGETYPE__c;
                        qp.T_BLEND_TYPE_NPD__c = op.T_BLEND_TYPE_NPD__c;
                        qp.T_NPD_DYED_PART__c = op.T_NPD_DYED_PART__c;
                        qp.T_REAMRK1__c = op.T_REAMRK1__c;
                        qp.End_Use__c = op.T_YARN_ENDUSE_PLY__c;
                        qp.T_YARN_PLY_COUNT_NPD__c = op.T_YARN_PLY_COUNT_NPD__c;
                        qp.T_NPD_PLANT__c = op.T_NPD_PLANT__c;
                        qp.Product__c = op.product__c;
                        qp.depth__c = op.Process_Depth_Type__c;
                        qp.depth2__c = op.T_YRN_PP_SHADE_DEPTH__c;
                        qp.shade__c = op.shade__c;
                        qp.Shade_Reference__c = op.Shade_Reference__c;
                        qp.T_REMARK2__c = op.Remark_2__c;
                        
                     }else if(op.recordtype.developername == 'Griege_Yarn'){
                        qp.Is_Converted__c = op.Converted_from_Lead__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Process__c = op.Process__c;
                        qp.Count__c = op.Count__c;
                        qp.Type__c = op.Type__c;
                        qp.End_Use__c = op.End_use__c;
                        qp.Ply__c = op.Ply__c;
                        qp.Raw_Material_1__c = op.Raw_Material__c;
                        qp.Raw_Material_1_per__c = op.Raw_Material_1__c;
                        qp.Raw_Material_2__c =op.Raw_Material_2__c;
                        qp.Raw_Material_2_pre__c= op.Raw_Material_2_Per__c;
                        qp.Raw_Material_3__c = op.Raw_Material_3__c;
                        qp.Raw_Material_3_per__c = op.Raw_Material_3_Per__c;
                        qp.Required_Price_kg__c = op.Required_Price_kg__c;
                        qp.Quantity__c = op.Quantity__c;
                        qp.Quantity_UOM__c = op.Quantity_UOM__c;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Packing__c = op.Packing__c;
                        qp.Spl_Requirement__c = op.Spl_Requirement__c;
                        qp.Other_Spl_Requirement__c = op.Other_Spl_Requirment__c;
                         //added as per Sharad for mapping for Quote PDF
                        qp.Yarn_Cone_Weight__c = ''+op.T_YARN_CONEWEIGHT__c;
                        qp.Yarn_Packaging_Style__c = op.T_YARN_PACKINGSTYLE__c;
                        qp.Yarn_Packaging_Type__c = op.T_YARN_PACKINGTYPE__c;
                        qp.Yarn_Waxing__c = op.T_YARN_WAXING__c;
                        qp.Net_Weight_per_carton__c = op.Net_Weight_per_carton__c;
                        qp.Net_Weight_per_pallet__c = op.Net_Weight_per_pallet__c;
                     }else if(op.recordtype.developername == 'Chemical'){
                        qp.Quantity__c =op.Quantity__c;
                        qp.Opp_Product_Id__c = op.id;
                        qp.Pending_Quantity__c=op.Quantity__c;
                        qp.Quantity_UOM__c=op.Quantity_UOM__c;
                        qp.required_price__c = op.Required_Price_kg__c;
                     }
                     QPList.add(qp);
                 }
             }
         }
     } 
     insert QPList;}

My trigger Test Class i trying to deploy:-
 
@isTest
public class QuoteTriggerInsertQPGTest{
private static testMethod void TriggerInsertQPGTest(){
Account acc = new Account(); 
         acc.Name = 'Test';   
         acc.Total_Purchase_of_Relevant_Products_In__c = 123;   
         acc.Trident_share_in_total_purchase_In_MTs__c = 123; 
         acc.Total_Purchase_of_relevant_products__c = 123;   
         acc.Sales_District__c = 'Z00002-Key Account - India';
         acc.BillingPostalCode='1234';
         acc.ShippingPostalCode='1456';
         acc.BillingState='Delhi';
         acc.ShippingCountry ='India';
         acc.ShippingState ='Goa';
         acc.BillingCountry ='India';
         acc.BillingState='Delhi';
          insert acc;
          
opportunity o = new opportunity();
o.name = 'test';
o.stagename= 'Qualified';
o.closedate = Date.today() + 10;
o.accountid = acc.id;
insert o;
Opportunity_product__c op = new Opportunity_product__c();
op.opportunity__c = o.id;
op.Ash__c = 22;
op.Bartuck_Needed__c = true;
op.T_NPD_ACCESSORIES_COST__c = 56;
op.T_NPD_PACKING_COST__c = 45;
op.T_PRODUCT_SIZE_BATHROBE__c = 'True';
op.Brightness__c = 8;
insert op;
opportunity_product_Group__c opg = new opportunity_product_Group__c();
opg.Number_of_Sizes__c= 2;
opg.opportunity__c = o.id;
insert opg;
Quote q = new Quote();
q.name='Test';
q.opportunityid = o.id;
insert q;
Pcm_sheet__c p = new Pcm_sheet__c();
p.Quote__c = q.id;
insert p;
PCM_LineItem__c pli = new PCM_LineItem__c();
pli.Pcm_sheet__c = p.id;
insert pli;
}
}

Please anyone guide where my error is??
 

 
Hi
I'm new to salesforce.
Can anyone help in writing the test class.
global class tridentUpdateOverduePGLWebService
{    
    webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) 
    {       
        //HttpRequest req = new HttpRequest();   
        //req.setHeader('Content-Type','application/x-www-form-urlencoded');
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                          // to capture web service failure exceptions.
        list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{};
        
    for (Integer i=0; i<OverdueRec.size();i++)
    {
        OverDue_PGL__c OverDueObj= new OverDue_PGL__c();
        
        OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new;
        OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new;
        OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new;
        OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new;
        OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new;      
        OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new;      
        OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new;
                              
        OverdueLst.add(OverDueObj);
        system.debug('Values taken');
  }

    if (Overduelst.size()>0)
    {                     
        try
            {
                insert OverdueLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                system.debug('Record Updated');     
            }    
       catch(exception e)
            {
                system.debug('Error');
                excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                
              //objResponse.SFDCId = OverdueLst.CustName;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
            }
     }
     else
     {        
      objResponse.Status = false;
      objResponse.Description ='No Item found to update';
      system.debug('Record not Updated');
     }
   return objResponse;                                                  // this will return result.
   }
        global class Overdue_element
      {
        webservice string CustomerName_name1_new;
        webservice string Total_Outstanding_INR_DMBTR_new;
        webservice string Payment_Term_Zterm_new;
        webservice string Overdue_Amount_INR_ovr_amt_new;
        webservice string Ageing_Days_days_new;
        webservice string Excise_Invoice_exnum_new;
        webservice string Item_Text_sgtxt_new;
    }
     global class SFAResponse
    {
      //webservice Id SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }
}

need urgently.
Please guide and help
Hi

I want to write a test class to increase code coverage for below mention trigger.
Can anyone help.
trigger paymenttermUpdate on Account (after update) {
    set<Id> acctIds = new set<Id>();
    map<Id, Account> mapAccount = new map<Id, Account>();
    list<Payment_Terms__c> listContact = new list<Payment_Terms__c>();
    
    for(Account acct : trigger.new) {
        acctIds.add(acct.Id);
        mapAccount.put(acct.Id, acct);
    }
    
    listContact = [SELECT Name, Payment_Terms__c,Account__c FROM Payment_Terms__c WHERE Account__c IN : acctIds];
    
    if(listContact.size() > 0) {
        for(Payment_Terms__c con : listContact) {
            con.Name = mapAccount.get(con.Account__c).Payment_Term_on_account_picklist__c;
            con.Payment_Terms__c = mapAccount.get(con.Account__c).Payment_Term_on_account_picklist__c;
        }
        update listContact;
    }
}

 
Hi 
I'm new to apex.
can anyone help in writing TEST CLASSES of these 3 apex classes.
 
global class tridentUpdateCFormsWebService
{    
    webservice static SFAResponse updateCForms(CForms_element[] cfrmRec) {   
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                              // to capture web service failure exceptions.      
        List<C_Forms__c> cformList = new List<C_Forms__c>();
        List<string> sapCustList = new List<string>();
        for(CForms_element cfrmCust : cfrmRec)
        {
            if(cfrmCust.SAP_CustomerId != null && cfrmCust.SAP_CustomerId != '')
            sapCustList.add(cfrmCust.SAP_CustomerId);
        }
        Map<string,string> mapCust = new Map<string,string>();
        for(account cust : [select id, Cust_SAP_No__c from Account where Cust_SAP_No__c in : sapCustList])
        {mapCust.put(cust.Cust_SAP_No__c,cust.Id);}
        if(cfrmRec[0].SAP_Message == null || cfrmRec[0].SAP_Message == '')
        {
            for(CForms_element cfrm_Rec : cfrmRec)
            {
                C_Forms__c cform_Rec = new C_Forms__c();
                                
                cform_Rec.Excise_Invoice_No_vbeln_new__c = cfrm_Rec.Excise_Invoice_No_vbeln_new;
                cform_Rec.Customer_SAP_Code__c = cfrm_Rec.SAP_CustomerId;
                
                if(mapCust.get(cfrm_Rec.SAP_CustomerId) != null)
                cform_Rec.Account__c = mapCust.get(cfrm_Rec.SAP_CustomerId);
                cform_Rec.Customer_Name_name1_new__c = cfrm_Rec.Customer_Name_name1_new;              
                cform_Rec.Region_regio_new__c = cfrm_Rec.Region_regio_new;                
                cform_Rec.VAT_Amount_zvat_amt_new__c = cfrm_Rec.VAT_Amount_zvat_amt_new;
                cform_Rec.Diff_Liability_zdiff_amt_new__c = cfrm_Rec.Diff_Liability_zdiff_amt_new;
                cform_Rec.Accounting_Document_Number_belnr_new__c = cfrm_Rec.Accounting_Document_Number_belnr_new;              
                cform_Rec.Company_Code_bukrs_new__c = cfrm_Rec.Company_Code_bukrs_new;     
                cform_Rec.Fiscal_Year_gjahr_new__c = cfrm_Rec.Fiscal_Year_gjahr_new;
                cform_Rec.Quarter_zquarter_new__c = cfrm_Rec.Quarter_zquarter_new;
                cform_Rec.Invoice_Value_zinv_value_new__c = cfrm_Rec.Invoice_Value_zinv_value_new;
                cform_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new__c = cfrm_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new;
                                    
                cformList.add(cform_Rec);
            }
            try{
                upsert cformList;
                                                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = true;
                return objResponse;
            }
            catch(exception e){
                excep.Record_Id__c = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                //excep.Order__c = cfrmRec[0].cformsId;
                excep.error__c = e.getmessage();
                insert excep;
                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
                return objResponse;// this will return result.
            }
        }
        else
        {
            list<Exceptions__c> lstexcep = new list<Exceptions__c>();
            for(integer i=0; i < cfrmRec.size(); i++)
            {
                Exceptions__c exp = new Exceptions__c();
                exp.Name = 'E';             
                
                lstexcep.add(exp);
            }
            insert lstexcep;
                       
            objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
            objResponse.Status = false;
            return objResponse;// this will return result.
        }                            
    }
    global class CForms_element
    {
        webservice string SAP_CustomerId;        
        webservice string Customer_Name_name1_new;
        webservice string Excise_Invoice_No_vbeln_new;
        webservice string Region_regio_new;
        webservice string VAT_Amount_zvat_amt_new;
        webservice string Diff_Liability_zdiff_amt_new;
        webservice string Accounting_Document_Number_belnr_new;
        webservice string Company_Code_bukrs_new;
        webservice string Fiscal_Year_gjahr_new;
        webservice string Quarter_zquarter_new;
        webservice string Invoice_Value_zinv_value_new;
        webservice string Tax_on_sales_and_Purchases_cod_mwskz_new;
        webservice string SAP_Message;
    } 
    global class SFAResponse
    {
        webservice String SFDC_Rec_No;       
        webservice Boolean Status; 
        webservice String Description;
    }
 }
 
global class tridentUpdateStockWebService
{
    Webservice static SFAResponse updateStock(Stock_element[] StockRec) 
    {
        SFAResponse objResponse = new SFAResponse();
        list <Stock_Report__c> StockLst = new list <Stock_Report__c>{};
        Exceptions__c excep = new Exceptions__c();                              // to capture web service failure exceptions.
        
        
        Set<string> sapCustList = new Set<string>();
        for(Stock_element customerR : StockRec)
        {
            if(customerR.CustNo != null && customerR.CustNo != '')
            sapCustList.add(customerR.CustNo);
        }
        Map<string,string> mapCust = new Map<string,string>();
        for(account cust : [select id, Cust_SAP_No__c from Account where Cust_SAP_No__c in : sapCustList])
        {mapCust.put(cust.Cust_SAP_No__c,cust.Id);}
        
        
        for (Integer i=0; i< StockRec.size(); i++)
        {
            Stock_Report__c StockVr = new Stock_Report__c();
            StockVr.Customer_Name_name1_new__c= StockRec[i].Customer_Name_name1_new;
            
            if(mapCust.get(StockRec[i].CustNo) != null)
            StockVr.Customer__c = mapCust.get(StockRec[i].CustNo);
            
            StockVr.Customer_Number__c= StockRec[i].CustNo;   
            StockVr.Special_Stock_No_SONUM_new__c= StockRec[i].Special_Stock_No_SONUM_new;
            StockVr.Total_Stock_Gesme_new__c= StockRec[i].Total_Stock_Gesme_new;
            StockVr.Material_Code_Matnr_new__c= StockRec[i].Material_Code_Matnr_new;
            StockVr.Material_Description_MAktx_new__c= StockRec[i].Material_Description_MAktx_new;
            StockVr.Batch_Charg_new__c= StockRec[i].Batch_Charg_new;
            StockVr.Product_Type_Lv_type_new__c= StockRec[i].Product_Type_Lv_type_new;
            StockVr.Plant_Werks_new__c= StockRec[i].Plant_Werks_new;
            
            StockLst.add(StockVr);
            system.debug('Values taken'); 
        }
        if (StockLst.size()>0)
     {
        try
        { 
                upsert StockLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                return objResponse;     // this will return result.
        }    
       catch(exception e)
        {
                excep.Record_Id__c = StockLst[0].Customer_Name_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                objResponse.SFDCId = StockLst[0].Customer_Name_name1_new__c;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
        }
     }
        return objResponse;     //this will return result.               
    }           
    
    global class stock_element
    {
        Webservice string CustNo;
        Webservice string Customer_Name_name1_new;
        Webservice string Special_Stock_No_SONUM_new;
        Webservice string Total_Stock_Gesme_new;
        Webservice string Material_Code_Matnr_new;
        Webservice string Material_Description_MAktx_new;
        Webservice string Batch_Charg_new;
        Webservice string Product_Type_Lv_type_new;
        Webservice string Plant_Werks_new;
        
    }
    
    global class SFAResponse
    {
        webservice String SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }

}
 
global class tridentUpdateOverduePGLWebService
{    
    webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) 
    {       
        //HttpRequest req = new HttpRequest();   
        //req.setHeader('Content-Type','application/x-www-form-urlencoded');
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                          // to capture web service failure exceptions.
        list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{};
        
    for (Integer i=0; i<OverdueRec.size();i++)
    {
        OverDue_PGL__c OverDueObj= new OverDue_PGL__c();
        
        OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new;
        OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new;
        OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new;
        OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new;
        OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new;      
        OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new;      
        OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new;
                              
        OverdueLst.add(OverDueObj);
        system.debug('Values taken');
  }

    if (Overduelst.size()>0)
    {                     
        try
            {
                insert OverdueLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                system.debug('Record Updated');     
            }    
       catch(exception e)
            {
                system.debug('Error');
                excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                
              //objResponse.SFDCId = OverdueLst.CustName;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
            }
     }
     else
     {        
      objResponse.Status = false;
      objResponse.Description ='No Item found to update';
      system.debug('Record not Updated');
     }
   return objResponse;                                                  // this will return result.
   }
        global class Overdue_element
      {
        webservice string CustomerName_name1_new;
        webservice string Total_Outstanding_INR_DMBTR_new;
        webservice string Payment_Term_Zterm_new;
        webservice string Overdue_Amount_INR_ovr_amt_new;
        webservice string Ageing_Days_days_new;
        webservice string Excise_Invoice_exnum_new;
        webservice string Item_Text_sgtxt_new;
    }
     global class SFAResponse
    {
      //webservice Id SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }
}

 
Hi

I have created a new custom profile and for this profile, my custom button on custom related list is not working but it is working for all other profiles.

Button code is:-
if('{!Opportunity_Product_Group__c.RecordTypeId}'== '{!$Setup.Record_Type__c.OPG_Towel__c}') { 
window.open("/a1Z/e?retURL={!Opportunity_Product_Group__c.Id}&RecordType={!$Setup.Record_Type__c.OP_Towel__c}&{!$Setup.Record_Type__c.OPG_Feild__c}={!Opportunity_Product_Group__c.Name}",'_top'); 
} 
else if('{!Opportunity_Product_Group__c.RecordTypeId}'== '{!$Setup.Record_Type__c.OPG_Bathrobe__c}'){ 
window.open("/a1Z/e?retURL={!Opportunity_Product_Group__c.Id}&RecordType={!$Setup.Record_Type__c.OP_Bathrobe__c}&{!$Setup.Record_Type__c.OPG_Feild__c}={!Opportunity_Product_Group__c.Name}",'_top'); 

} 
else if('{!Opportunity_Product_Group__c.RecordTypeId}'== '{!$Setup.Record_Type__c.OPG_Sheeting__c}'){ 
window.open("/a1Z/e?retURL={!Opportunity_Product_Group__c.Id}&RecordType={!$Setup.Record_Type__c.OP_Sheeting__c}&{!$Setup.Record_Type__c.OPG_Feild__c}={!Opportunity_Product_Group__c.Name}",'_top'); 

}

please can anyone knows how to solve this, as this is very urgent.