• praveen avvari
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
Hi ,
I am getting below Error when i try to drill down from Account, this is happening for all Accounts
Error ID: 460854949-25603 (504848161)
Any idea what is the issue here
Regards,
Praveen
Hi,

I have a requirment to send Account information to a Mulesfot API on click of a Button on Account object, 
and this information will be used to update in workday.
Need to know any one have examples on how to achieve this
or stpes to follow to achieve this 

Thanks in advance
Praveen
 
Hi,
I am getting "System.LimitException: Too many SOQL queries: 101" from belo test class, please help me to reslove this isse.
----------------------------------------------------------------------------------------------
@isTest
public class OpportunityProductTriggerTest {
    
        private static Map<String, Id> getRecordTypes() {
        Map<String, Id> recordTypeByName = new Map<String, Id>();
        List<RecordType> rts = [select id,developerName from RecordType];
        system.debug(rts);
        for(RecordType r: rts) {
            recordTypeByName.put(r.developerName, r.Id);
        }
       
            return recordTypeByName;
        }
    
        @isTest static void TestInsert() {
      
        Map<String, Id> rts = getRecordTypes();
        Product2 p = TestDataFactory.createProduct('Test', 'Goods', 'Food goods', 'Fixed Amount', true);
        p.CPM_applicable__c = true;
        p.IsActive = true;
  //      p.RevenueRecognition__c = 'POC Cost';
        insert p;

        Id pbId = Test.getStandardPricebookId();
        PriceBookEntry pb = TestDataFactory.creatPriceBook(p.Id, 10, true, pbId);
        insert pb;

        SYSTEM.debug('== ' + rts.keySet());
        Account company = TestDataFactory.createAccount('Au_feminin','test1@gmail.com', 'France', 'Paris', 'Street', 'France', 'Paris', 'Paris street', 'LUX-TVA', '2211', rts.get('Company'));
        insert company;

        Account acc = TestDataFactory.createAccount('Apple','test2@gmail.com', 'Belgium', 'Liege', 'Street', 'Belgium', 'Liege', 'street', 'LUX-TVA', '223', rts.get('Annonceur'));
        insert acc;

        Opportunity opp = TestDataFactory.createOpportunity('Test', 'Qualification', Date.today(), company.Id, acc.Id, null, 'CW8_AGENT_TYPE-1',rts.get('Default'), 'No', 'CUSTOMER_CONTRACT_TYPE-2');
        opp.Probability = 4;
        insert opp;

        OpportunityLineItem lineItem1 = new OpportunityLineItem (OpportunityID=opp.id,
                                                                 //PriceBookEntryID=pbe1.id, 
                                                                 PriceBookEntryID=pb.id, 
                                                                 //fatima
                                                                 Product2Id = p.id,
                                                                 ServiceDate = System.today() + 500,
                                                                 Realization_to_date__c = System.today() + 510,
                                                                 UnitPrice = 50,
                                                                 Contact_volume__c = 500,
                                                                 Quantity=1, 
                                                                 Cost_Center_Company__c = 'Alfemminile',
                                                                 Cost_Center__c = 'CC-ALF51',
                                                                 DeleteScheduleItem__c = true,
                                                                 Estimated_costs_copy_from_line_item_sche__c = 5
                                                                 
                                                                );

        insert lineItem1;

        system.debug('Foued_toto => ' + lineItem1.Id);
                    
            
        
        SetStaticVariable.AutomaticCreation = true;
            
        OpportunityLineItemSchedule olis = new OpportunityLineItemSchedule(ActualCosts__c = 100, EstimatedCost__c = 500, 
                                                                           OpportunityLineItemId = lineItem1.Id,
                                        Type='Revenue', Revenue = 200, ScheduleDate = System.today()+220,
                                        FromDate__c = system.today()+250, EndDate__c = system.today() + 880,
                                        Revenue_Recognition_Product__c = 'Custom');
        insert olis;
            
                        Billing_Schedule__c bil = new Billing_Schedule__c(
                                    Opportunity__c = opp.id,
                                    Amount__c = 20.5,
                                    Opportunity_Product_Id__c = lineItem1.Id,
                                    Start_Date__c = System.today() + 500,
                                     End_Date__c = System.today() + 510

            
                );              
            insert bil; 
            
            
            
                    Product2 p2 = TestDataFactory.createProduct('Test', 'Goods', 'Food goods', 'Fixed Amount', true);
        p2.CPM_applicable__c = true;
        p2.Volume__c = 700;
        p2.IsActive = true;
        insert p2;

        Id pbId2 = Test.getStandardPricebookId();
        PriceBookEntry pb2 = TestDataFactory.creatPriceBook(p2.Id, 10, true, pbId2);
        insert pb2;

        SYSTEM.debug('== ' + rts.keySet());
        

        Opportunity opp2 = TestDataFactory.createOpportunity('Test', 'Qualification', Date.today(), company.Id, acc.Id, null, 'CW8_AGENT_TYPE-1',rts.get('Default'), 'No', 'CUSTOMER_CONTRACT_TYPE-2');
        opp2.Probability = 4;
        insert opp2;

        OpportunityLineItem lineItem2 = new OpportunityLineItem (OpportunityID=opp2.id,
                                                                 //PriceBookEntryID=pbe1.id, 
                                                                 PriceBookEntryID=pb2.id, 
                                                                 //fatima
                                                                 Product2Id = p2.id,
                                                                 ServiceDate = System.today() + 500,
                                                                 Realization_to_date__c = System.today() + 510,
                                                                 UnitPrice = 50,
                                                                 Contact_volume__c = null,
                                                                 Quantity=1, 
                                                                 Cost_Center_Company__c = 'Alfemminile',
                                                                 Cost_Center__c = 'CC-ALF51',
                                                                 DeleteScheduleItem__c = true,
                                                                 Estimated_costs_copy_from_line_item_sche__c = 5
                                                                 
                                                                );

        insert lineItem2;
            lineItem2.UnitPrice = 8;
            lineItem2.Contact_volume__c = 500;
            lineItem2.Discount = 7;
            update lineItem2;
            
      //      lineItem2.UnitPrice = null;
            lineItem2.Quantity = null;
            lineItem2.TotalPrice = 5;
            update lineItem2;
            
            OpportunityLineItem lineItem3 = new OpportunityLineItem (OpportunityID=opp2.id,
                                                                 //PriceBookEntryID=pbe1.id, 
                                                                 PriceBookEntryID=pb2.id, 
                                                                 //fatima
                                                                 Product2Id = p2.id,
                                                                 ServiceDate = System.today() + 500,
                                                                 Realization_to_date__c = System.today() + 510,
                                                                 UnitPrice = null,
                                                                 Contact_volume__c = null,
                                                                 Quantity=1, 
                                                                 Cost_Center_Company__c = 'Alfemminile',
                                                                 Cost_Center__c = 'CC-ALF51',
                                                                 DeleteScheduleItem__c = true,
                                                                 Estimated_costs_copy_from_line_item_sche__c = 5
                                                                 
                                                                );

        insert lineItem3;
            
                    
        p.RevenueRecognition__c = 'POC Cost';
        update p;
           
        lineItem1.ServiceDate = System.Today() + 600;
        lineItem1.Realization_to_date__c = System.Today() + 610;
        lineItem1.UnitPrice = 20;
        lineItem1.Quantity = 7;
            
        update lineItem1;
            
        delete lineItem1;
        }
                

}
--------------------------------------------------------------------------------------------
Hi , My test class is not coverging all of the code. 
can you please help me what is missing here, so that i can get 100% coverage
Apex Test Class:
--------------------------------------------------------------------------------------
@isTest
public class QuoteTriggerTest {
    
        private static Map<String, Id> getRecordTypes() {
        Map<String, Id> recordTypeByName = new Map<String, Id>();
        List<RecordType> rts = [select id,developerName from RecordType];
        system.debug(rts);
        for(RecordType r: rts) {
            recordTypeByName.put(r.developerName, r.Id);
        }
        return recordTypeByName;
    }
    
        @isTest static void TestQuote() {

        
            Map<String, Id> rts = getRecordTypes();
            Product2 p = TestDataFactory.createProduct('Test1', 'Goods', 'Food goods', 'Fixed Amount', true);
            p.IsActive = true;
            insert p;

            Id pbId = Test.getStandardPricebookId();

            PriceBookEntry pb = TestDataFactory.creatPriceBook(p.Id, 10, true, pbId);
            insert pb;

            Account company = TestDataFactory.createAccount('Au_feminin1','test1@gmail.com', 'France', 'Paris', 'Street', 'France', 'Paris', 'Paris street', 'LUX-TVA', '2211', rts.get('Company'));
            insert company;
            Account acc = TestDataFactory.createAccount('Apple1','test2@gmail.com', 'Belgium', 'Liege', 'Street', 'Belgium', 'Liege', 'street', 'BHS-TIN', '223', rts.get('Annonceur'));
            insert acc;
            
            Brand__c br = new Brand__c(
                                name = 'brand 2', Account__c = acc.id
                                
            );
            insert br;
        
            Contact con = new Contact(LastName = 'contact 2');
            insert con;
            
            
            Opportunity opp = new Opportunity(
                                            Name = 'Testing',
                                            StageName = 'Qualification',
                                            closeDate = System.today() + 50,
                                            Company__c = company.id,
                                            accountId = acc.id,
                                            recordtypeId = rts.get('Programmatic'),
                                            Sector__c = 'CW1_SECTOR-81',
                                            Contract_Type__c = 'CUSTOMER_CONTRACT_TYPE-8',
                                            SyncedQuoteId = null
                                            //SyncedQuoteId = q.id
                                            
            );
            
            insert opp;

            OpportunityLineItem OppLineItem = new OpportunityLineItem(
                                                                 OpportunityID=opp.id,
                                                                 PriceBookEntryID=pb.Id, 
                                                                 Product2Id = p.id,
                                                                 ServiceDate = System.today() + 500,
                                                                 Realization_to_date__c = System.today() + 510,
                                                                 UnitPrice = 50,
                                                                 Quantity=4, 
                                                                 Cost_Center_Company__c = 'Alfemminile',
                                                                 Cost_Center__c = 'CC-ALF51'   
                                                                 
                                                                 
            );
            insert OppLineItem;
            
            SetStaticVariable.AutomaticCreation = true;
            
            OpportunityLineItemSchedule olis = new OpportunityLineItemSchedule(ActualCosts__c = 100, EstimatedCost__c = 200, OpportunityLineItemId = OppLineItem.Id,
                                        Type='Revenue', Revenue = 200,ScheduleDate = System.today()+20,
                                        FromDate__c = system.today()+20, EndDate__c = system.today() + 80,
                                                                  Revenue_Recognition_Product__c = 'Custom');
            insert olis;

            Quote q = new Quote( //AccountId = acc.Id,
                              Advertiser_Contact__c = con.id,
                              Agency_Contact__c = con.id,
                              Brand__c = br.id,          
                              status = 'Review Pending',
                              shippingCountry = 'Belgium',
                              name = 'Test Quote 1',
                              OpportunityId = opp.id,
                              Pricebook2Id = pbId
                        //      IsSyncing = true
            );
                
            insert q;
            
            QuoteLineItem qli = TestDataFactory.createQuoteLineItem(q.id, 1, 1, pb.Id, opp.Id, OppLineItem.Id);
            insert qli;          
                                               
            Billing_Schedule__c bil = new Billing_Schedule__c(
                                    Opportunity__c = opp.id,
                                    Amount__c = 20.5,
                                    Synched_Quote__c = q.id,
                                    Opportunity_Product_Id__c = OppLineItem.Id,
                                    Start_Date__c = System.today() + 500,
                                    End_Date__c = System.today() + 510
            
                );              
            insert bil;   
               
            
            //opp.SyncedQuoteId = q.Id;
            //update opp;
/*          
            q.status = 'SentForApproval';
            update q;
*/
 
/*            q.IsSyncing = true;
                update q;
*/
                        
        }

}

-----------------------------------------------------------------------------------

Apex Trigger 
------------------------------------------------------------------------------------
trigger QuoteTrigger on Quote (before Update) 
{
    for (Quote Quote : Trigger.new)
    {
        //Bloquer l'avancement de la Quote suivant le statut des Schedule Item et Billing Schedule
        if (Trigger.oldMap.get(Quote.Id).Status != Quote.Status && Quote.Status == 'Sent For Approval')
        {
            //Selectionner toutes les lignes d'opp (hors produits offerts) avec leurs Revenues Schedule
            List<OpportunityLineItem> OppLineItem_1 = [    SELECT     id, (SELECT Id from OpportunityLineItemSchedules)                                                
                                                        FROM     OpportunityLineItem 
                                                        WHERE     OpportunityId =: Quote.OpportunityId AND
                                                        Discount != 100];
            
            //Selectionner toutes les lignes d'opp (hors produits offerts) avec leurs Revenues Schedule dont le Estimated Cost = Null
            List<OpportunityLineItem> OppLineItem_2 = [    SELECT     id, (SELECT Id, EstimatedCost__c from OpportunityLineItemSchedules where EstimatedCost__c = null)                                                
                                                       FROM     OpportunityLineItem 
                                                       WHERE     OpportunityId =: Quote.OpportunityId AND
                                                                Discount != 100];
            //Start Ticket 603 ,Praveen, October 6th,2020
            //Salesforce cosiders Organisation curency when we use Aggregate functions,in order to over come we are using this fix
            //Assumtions:since we ar using Dated Exchange rates, all Values in manage Currencies to be set to 1
            
            Opportunity opp = [SELECT CurrencyIsoCode,CloseDate FROM Opportunity WHERE Id =: Quote.OpportunityId];
            Decimal cts = [SELECT Id, ConversionRate FROM DatedConversionRate WHERE IsoCode = :opp.CurrencyIsoCode  AND  StartDate <= :opp.CloseDate AND   NextStartDate > :opp.CloseDate].ConversionRate;
            
            //End Ticket 603
            
            //Si ligne d'opp existe           
            if (OppLineItem_1 != null && OppLineItem_1.size() > 0)
            {
                for (OpportunityLineItem OppLine_1 : OppLineItem_1)
                {
                    List<OpportunityLineItemSchedule> LineItemSchedule_1 = OppLine_1.OpportunityLineItemSchedules;
                    
                    //Vérifier s'il y aucun Revenue Schedule crée
                    if (LineItemSchedule_1 == null || LineItemSchedule_1.size() == 0)
                    {
                        quote.adderror(System.Label.ScheduleErrorMsg3);
                        return;
                    }
                }
                
                for (OpportunityLineItem OppLine_2 : OppLineItem_2)
                {
                    List<OpportunityLineItemSchedule> LineItemSchedule_2 = OppLine_2.OpportunityLineItemSchedules;
                    
                    //Vérifier s'il y au moins un Revenue Schedule avec un Estimated Cost = null
                    if (LineItemSchedule_2.size() > 0)
                    {
                        quote.adderror(System.Label.ScheduleErrorMsg4);
                        return;
                    }
                }
                
            }

            //Vérifier si sur chaque ligne d'opportunité a au moins une ligne de Billing Schedule
            //Récuperer toutes lignes de billing schedule par rapport à l'opportunité de la quote
            Map<Id,AggregateResult> BillingSchedule = new Map<Id, AggregateResult>([    SELECT     SUM(Amount__c) Amounts, Opportunity_Product_Id__c Id  
                                                                                        FROM     Billing_Schedule__c                                             
                                                                                        WHERE     Opportunity__c =: Quote.OpportunityId
                                                                                        GROUP BY Opportunity_Product_Id__c
                                                                                    ]);
            
            //Récuperer toutes les lignes d'opportunité qui n'ont pas de billing schedule
            List <OpportunityLineItem> OppLineIds = [SELECT id, Discount FROM OpportunityLineItem WHERE OpportunityId =: Quote.OpportunityId and id NOT IN : BillingSchedule.KeySet() and Discount != 100];
          
            
            if (!OppLineIds.IsEmpty()) 
            {
                quote.adderror(System.Label.ScheduleErrorMsg5);
                return;
            }
            else
            {
                //Récupérer la somme de TotalPrice des lignes d'opp rattachées à l'opportunité
                Map<Id,AggregateResult> OppLineItem_3 = new Map<Id, AggregateResult>([    SELECT      OpportunityId Id, SUM(TotalPrice) Totals  
                                                                                           FROM      OpportunityLineItem 
                                                                                           WHERE      OpportunityId =: Quote.OpportunityId AND
                                                                                                   Discount != 100
                                                                                        GROUP BY OpportunityId
                                                                                         ]);
                
                
                decimal TotalBillingAmount = 0.00;
                               
                //Additionner les montants des Billing Schedule
                for (Id key : BillingSchedule.keySet()) 
                {
                    TotalBillingAmount = TotalBillingAmount + (Decimal)BillingSchedule.get(key).get('Amounts');
                    TotalBillingAmount = (TotalBillingAmount * 1/cts).setScale(2, RoundingMode.HALF_UP); //Ticket 603
                 
                }
                
              //Vérifier si le montant des TotalPrice est égal ou non à la somme des montants des Billings Schedule
                for (Id key : OppLineItem_3.keySet()) 
                {
                    if ( (Decimal)OppLineItem_3.get(key).get('Totals') != TotalBillingAmount)
                    {
                        quote.adderror(System.Label.ScheduleErrorMsg12);                    
                    }
                }
            }
            
            //Fin de vérification
        }
    }
}
------------------------------------------------------------------------------------
Hi ,
I am getting below Error when i try to drill down from Account, this is happening for all Accounts
Error ID: 460854949-25603 (504848161)
Any idea what is the issue here
Regards,
Praveen