• Ayyagari Ramesh
  • NEWBIE
  • 50 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 21
    Questions
  • 7
    Replies
To fix the exception: System.LimitException: Too many SOQL queries: 101 made changes to the apex class as below. Can anyone please highlight the issue in it? as i am getting another error while saving-Method does not exist or incorrect signature: void add(String) from the type List<Order>

Apex Class-
Public class QTB_CreateOrderItem {
    public static final string className = QTB_CreateOrderItem.class.getName();
    public static boolean throwExplicitException = false;
    // Calling this method from flow to create orderitems based on selected products.
    @InvocableMethod
   Public static void updateOrderItemDetails(list <flowInputs> request)
    {   
        List<OrderItem> OrderItemlst = new List<OrderItem>();
        List <PriceBookEntry> book = new  List <PriceBookEntry>();
        List<Order> NewCrOrder = new List<Order>();
        String errorIds = '';
        List<Order> NewCrOrder1 = new List<Order>();
       
        
        For(flowInputs flow:request)
        {
            NewCrOrder1.add(flow.newOrderCreated);
            
            book=[select id, name,Product2Id,Product2.SBQQ__ChargeType__c,Product2.SBQQ__BillingFrequency__c,Product2.SBQQ__BillingType__c,Product2.blng__BillingRule__c,Product2.blng__TaxRule__c,Product2.blng__RevenueRecognitionRule__c,Product2.SBQQ__SubscriptionTerm__c from PricebookEntry where ProductCode in :flow.productCodes and Pricebook2Id = :flow.oldOrderData.Pricebook2Id ];
            system.debug('Retrieved PRbentry ----------'+ book.size());      
        }
        
        NewCrOrder1 = [Select id,name,EffectiveDate,EndDate,QTB_Legal_Entity_Country__c,Account.QTB_Contract_Entity__c from order  where id IN :NewCrOrder];    
        

            
        
        try {
            if (throwExplicitException) {
                system.debug('NullPointer');
                throw new NullPointerException();
            } 
            
            List<blng__BillingTreatment__c> sgListBillingTreat=[Select id, name,blng__BillingRule__r.id from blng__BillingTreatment__c Where Name='No Invoice Billing Treatment' LIMIT 1];
            if(book.size()>0)  {  
                For(pricebookentry pr : book)
                  {  
                    OrderItem temporderitem = new OrderItem();
                    temporderitem.OrderId = NewCrOrder[0].id;
                    temporderitem.blng__BillableUnitPrice__c= 0;
                    temporderitem.Product2Id = pr.Product2.Id;
                    temporderitem.Quantity = 1;
                    temporderitem.UnitPrice = 0;    
                    temporderitem.blng__HoldBilling__c = 'No';   
                    temporderitem.blng__TaxCountry__c = NewCrOrder[0].QTB_Legal_Entity_Country__c;
                    temporderitem.ServiceDate = NewCrOrder[0].EffectiveDate;
                    temporderitem.EndDate = NewCrOrder[0].EndDate;
                    temporderitem.SBQQ__BillingFrequency__c = 'Monthly';
                    temporderitem.SBQQ__BillingType__c = 'Arrears';
                    temporderitem.SBQQ__ChargeType__c  = 'Recurring';  
                    temporderitem.SBQQ__ContractAction__c  = 'New'; 
                    temporderitem.SBQQ__ContractingMethod__c  = 'Inherit';
                    temporderitem.SBQQ__SubscriptionTerm__c= 1;    
                    temporderitem.SBQQ__DefaultSubscriptionTerm__c= 1;
                    temporderitem.SBQQ__OrderedQuantity__c= 1;
                    temporderitem.SBQQ__PricingMethod__c='List';
                    temporderitem.SBQQ__ProductSubscriptionType__c = 'One-Time'; 
                    temporderitem.SBQQ__SubscriptionType__c = 'One-Time';
                    temporderitem.SBQQ__Status__c = 'Draft';   
                    temporderitem.SBQQ__SubscriptionPricing__c='Fixed Price';
                    temporderitem.PricebookEntryId = pr.Id;
                    temporderitem.blng__BillingRule__c =pr.Product2.blng__BillingRule__c;
                    temporderitem.blng__BillingTreatment__c = sgListBillingTreat[0].id;
                    temporderitem.blng__LegalEntity__c = NewCrOrder[0].Account.QTB_Contract_Entity__c;
                    temporderitem.blng__RevenueRecognitionRule__c  = pr.Product2.blng__RevenueRecognitionRule__c;
                    temporderitem.blng__TaxRule__c = pr.Product2.blng__TaxRule__c;
                    OrderItemlst.add(temporderitem);    
                   }
            }
            Insert OrderItemlst;
            system.debug('Inserted Items ======' +OrderItemlst.size());
            List<Id> OrdidtoLoad = new List<Id>();
            OrdidtoLoad.add(NewCrOrder[0].id);
            //To update order item for seperate invoicing 
            list<OrderItem> lstupdate= new list<OrderItem>();
            list<OrderItem> itemlst = new list<OrderItem>();
            itemlst=[Select id,blng__InvoiceGrouping__c,blng__InvoiceGroupId__c,Order.OrderNumber from OrderItem where order.id IN :OrdidtoLoad];
            system.debug('Total Selected to update:'+ itemlst.size());
            for(OrderItem ls : itemlst)
            {
                ls.blng__InvoiceGrouping__c= 'Invoice Group ID';
                ls.blng__InvoiceGroupId__c= ls.Order.OrderNumber;
                lstupdate.add(ls);
                
            }
            system.debug('Total Selected to update:'+ lstupdate.size());  
            update lstupdate;
            //To Update matching attribute on usage summary related to newly created orderItems
            List<blng__UsageSummary__c  > Uslsttoupdate =new List<blng__UsageSummary__c>();
            List<blng__UsageSummary__c  > Uslst = new List<blng__UsageSummary__c  >();
            Uslst =[Select id,blng__MatchingAttribute__c,blng__Order__r.OrderNumber from blng__UsageSummary__c Where blng__Order__r.id IN :OrdidtoLoad];
            system.debug('Size+++++++++++++++:'+ Uslst.size());
            for (blng__UsageSummary__c us :Uslst)
            {
                us.blng__MatchingAttribute__c = us.blng__Order__r.OrderNumber;
                Uslsttoupdate.add(us);
            }
            Update Uslsttoupdate;
            System.debug('Updated count====='+Uslsttoupdate.size());
            // To activate Created Orders/OrderItems
            Database.executeBatch(new QTB_AddOrderProductCSCRBatch(OrdidtoLoad), 200);
            
        }
          catch (exception e) {
            errorIds = e.getMessage() + errorIds;
            if (errorIds.length() > 100000)
                errorIds = errorIds.substring(0, 100000);
            system.debug('In catch method of batch Finish>>>>>>>>>>');
            system.debug('Error inf::' + errorIds);
            QTB_ExceptionLogger.createLog(
                e.getLineNumber(),
                e.getStackTraceString(),
                errorIds,
                e.getTypeName(),
                className
            );
        }  
        
    }
  Public class flowInputs{
        @InvocableVariable
        public Order oldOrderData;
        @InvocableVariable    
        Public string newOrderCreated;
        @InvocableVariable
        Public list<String> productCodes;
      }
    
}
An email has to be triggered based on below code to but its not working. Something to do with last condition which I am going wrong.
Can anyone point out the approach to define multiple conditions
trigger CreditMemoTrigger on Credit_Memo__c (after update) 
{
    
    for(Credit_Memo__c SC : trigger.new)
    {
        Credit_Memo__c oldSC = Trigger.oldMap.get(SC.Id);
        if(SC.Send_Attachment__c == true &&
        (SC.Record_Approval__c == true || SC.Auto_Approved__c == true) &&
        (SC.Reason_Code_1__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_2__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_3__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_4__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_5__c == '1-Invoice Correction - Pricing Error - No impact on inventory'))
        {
            
            EmailTemplate et=[Select id,subject,body from EmailTemplate where name='KHI Credit Memo VF temp'];
            system.debug('et '+et);
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            
            //add template
            singlemail.setTargetObjectId(SC.Id);
            singlemail.setTemplateId(et.Id);
            singlemail.setWhatId(SC.Id);
         
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
             
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(Label.KHI_Pricing_Email);
            sendTo.add(owneremail);
            // Step 4. Set email contents - you can use variables!
            //singlemail.setSubject('Attachments of Service Complaint-'+SC.Name+' Request by ');
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
         List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
         // List<Attachment> attList = [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id];
         for (ContentDocumentLink a : [select Id, LinkedEntityId, ContentDocumentId from ContentDocumentLink where LinkedEntityId = : SC.Id])
          
     
         {
              for (ContentVersion b : [select id,FileType,FileExtension,contentBodyId,ContentLocation,PathOnClient,versionData, ContentUrl,Title from ContentVersion where ContentDocumentId= :a.ContentDocumentId])
              {
         // Add to attachment file list
         Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setFileName(b.Title+ '.' + b.FileExtension);
         blob WOCFbody = b.versiondata;
         efa.setBody(WOCFbody);
         // efa.setContentType(b.PathOnClient);
         fileAttachments.add(efa);
              system.debug('SC.Attachment '+fileAttachments);
         }
         }
         singlemail.setFileAttachments(fileAttachments);

         //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
        } 
        
        Else if(SC.Send_Attachment__c == true &&
        (SC.Record_Approval__c == true || SC.Auto_Approved__c == true) &&
        (SC.Reason_Code_1__c == '6-Other'||
        SC.Reason_Code_2__c == '6-Other'||
        SC.Reason_Code_3__c == '6-Other'||
        SC.Reason_Code_4__c == '6-Other'||
        SC.Reason_Code_5__c == '6-Other'))
        {
            
            EmailTemplate et=[Select id,subject,body from EmailTemplate where name='KHI Credit Memo VF temp'];
            system.debug('et '+et);
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            
            //add template
            singlemail.setTargetObjectId(SC.Id);
            singlemail.setTemplateId(et.Id);
            singlemail.setWhatId(SC.Id);
         
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
             
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(Label.KFI_Credit_Email);
            system.debug('KFI_Credit_Email ');
            sendTo.add(owneremail);
            // Step 4. Set email contents - you can use variables!
            //singlemail.setSubject('Attachments of Service Complaint-'+SC.Name+' Request by ');
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
         List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
         // List<Attachment> attList = [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id];
         for (ContentDocumentLink a : [select Id, LinkedEntityId, ContentDocumentId from ContentDocumentLink where LinkedEntityId = : SC.Id])
          
     
         {
              for (ContentVersion b : [select id,FileType,FileExtension,contentBodyId,ContentLocation,PathOnClient,versionData, ContentUrl,Title from ContentVersion where ContentDocumentId= :a.ContentDocumentId])
              {
         // Add to attachment file list
         Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setFileName(b.Title+ '.' + b.FileExtension);
         blob WOCFbody = b.versiondata;
         efa.setBody(WOCFbody);
         // efa.setContentType(b.PathOnClient);
         fileAttachments.add(efa);
              system.debug('SC.Attachment '+fileAttachments);
         }
         }
         singlemail.setFileAttachments(fileAttachments);

         //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
        }
        
        Else if(SC.Send_Attachment__c == true &&
        (SC.Record_Approval__c == true || SC.Auto_Approved__c == true) &&
        (SC.reason_check__c == true ))      
        {
            
            EmailTemplate et=[Select id,subject,body from EmailTemplate where name='KHI Credit Memo VF temp'];
            system.debug('et '+et);
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            
            //add template
            singlemail.setTargetObjectId(SC.Id);
            singlemail.setTemplateId(et.Id);
            singlemail.setWhatId(SC.Id);
         
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
             
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(Label.KHI_Claims_Email);
            sendTo.add(owneremail);
            // Step 4. Set email contents - you can use variables!
            //singlemail.setSubject('Attachments of Service Complaint-'+SC.Name+' Request by ');
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
         List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
         // List<Attachment> attList = [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id];
         for (ContentDocumentLink a : [select Id, LinkedEntityId, ContentDocumentId from ContentDocumentLink where LinkedEntityId = : SC.Id])
          
     
         {
              for (ContentVersion b : [select id,FileType,FileExtension,contentBodyId,ContentLocation,PathOnClient,versionData, ContentUrl,Title from ContentVersion where ContentDocumentId= :a.ContentDocumentId])
              {
         // Add to attachment file list
         Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setFileName(b.Title+ '.' + b.FileExtension);
         blob WOCFbody = b.versiondata;
         efa.setBody(WOCFbody);
         // efa.setContentType(b.PathOnClient);
         fileAttachments.add(efa);
              system.debug('SC.Attachment '+fileAttachments);
         }
         }
         singlemail.setFileAttachments(fileAttachments);

         //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
        }
    
    }
}
I have a picklist field  Z and its value are like A,B,C. I want to create formulae field and mark it true when the picklist field contains values A and B only. Tried multiple and unable to acheive it. please help
one example as below tried as well but not working:
IF(OR(TEXT(Z__c) = 'A',TEXT(Reason_Code_1__c) = 'B'),true,false)
In Salesforce CPQ I have updated the Ship To name,address,city,zip in quote detail page and saved and  got updated  and reflecting but when checking PDF document the Ship to name is showing the old name and and not updated to new name but the address, city, zip is showing the updated values. What must be reason can anyone share the path to troubleshoot the issue.
Class:
global class ContractRenewalBatchJob implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        Date endDateContract = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration);
        Date endDateContract1 = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration1);
        Date endDateContract2 = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration2);
        Date endDateContract3 = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration3);
        
        String query = 'select id,Account.Name,Owner.Email,Owner.Name,Ownerid,EndDate,ContractNumber,CustomerSigned.id from Contract where (enddate=:endDateContract OR enddate=:endDateContract1 OR enddate=:endDateContract2 OR enddate=:endDateContract3) and (SBQQ__RenewalForecast__c=false and SBQQ__RenewalQuoted__c=false)';
        List<sObject> sobjList = Database.query(query);
        system.debug('ttt'+sobjList);
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Contract> scope)
    {
        try
        {
            List<Messaging.SingleEmailMessage>  myEmails = new List<Messaging.SingleEmailMessage>();
            for(Contract c:scope)
            {
                system.debug('Contract : ' + c);
                String body;
                body = 'Hi ' + c.Owner.Name + ',<br/><br/>';
                body = body + 'Contract ' + c.ContractNumber + ' is expiring on ' + c.EndDate.month() + '/' + c.EndDate.day() + '/' + c.EndDate.year() + '.<br/>';
                body = body + '<br/>Please renew the Contract ASAP. You can access the contract in the URL below:<br/><br/>';
                body = body + Label.WebsiteURL + '/' + c.id + '<br/><br/>';
                body = body + 'Regards,<br/>AFH Sales Ops Team';
                
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setHTMLBody(body);
                mail.setToAddresses(new String[]{c.owner.email});
                mail.setSubject('ACTION REQUIRED: Your \"' + c.Account.Name + '\" Contract Requires Renewal');
                myEmails.add(mail);
            }
            if(myEmails.size() > 0)
            {
                Messaging.sendEmail(myEmails,false);
            }
        }
        catch(Exception ex)
        {
            system.debug('Exception : ' + ex.getMessage());
        }
    }
    global void finish(Database.BatchableContext BC)
    {
    }
}
test class:
@isTest
public class ContractRenewalBatchJobTest 
{
    static testMethod void testMethod1()
    {
        User us = [Select id from User where Id = :UserInfo.getUserId()];
        Date startDateWithinRange =  system.today();   
        Date endDateWithinRange = system.today() + 29;
        Date endDateWithinRange1 = system.today() + 59;
        Date endDateWithinRange2 = system.today() + 89;
        Date endDateWithinRange3 = system.today() + 119;
        Account acc1 = KHCPQ_Test_DataFactory.createAccount('Parent Account','Active','Street 1','123');
        Contract contract1 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange);
        Contract contract2 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange1);
        Contract contract3 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange2);
        Contract contract4 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange3);
        System.runAs(us)
        Test.startTest();
        ContractRenewalBatchJob obj = new ContractRenewalBatchJob();
        DataBase.executeBatch(obj);
        ContractRenewSchedule sch = new ContractRenewSchedule();
        String cronStr = '0 0 0,12 * * ?';
        system.schedule('testJob', cronStr, sch);
        Test.stopTest();
    }
}
Hi All,  
there is a integration happening into salesforce from SAP end and when the load happens the records created in custom object Product staging and from there using trigger the new record gets created in standard object product..Now the records are not getting created from source file when load is happening. when tried out through manual load by taking one records using workbench and set the debug logs and exception error got captured as below:
field_integrity_exception, product hierarchy: id value of incorrect type: a041h00000lj99fqas: [product_node_id__c]

note - product_node_id__c is a lookup field.
I have written an invocable apex class for process builder to update th owner change of accounts and related Opportunity, contracts and quotes on custom object and its working fine. Now i need to bulkify the code. what are the changes required in below code ?
below code :
public class RequestPortalRecords
{
    @InvocableMethod
    public static void ReqChange(List<Request_Portal__c> rp)
    {
        system.debug('entered raghav' +rp);
        Set<Id> accountIds=new Set<Id>();
        Id ownerid;
        list<Account> updateAccOwnerList = new list<Account>();
        list<Opportunity> updateoppList = new list<Opportunity>();
        list<SBQQ__Quote__c> updateqsList = new list<SBQQ__Quote__c>();
        list<contract> updatecrList=new list<contract>();
        
        
        for(Request_Portal__c r : rp)
        {
            accountIds.add(r.Account_Name__c);
            ownerid=r.New_Owner__c;
            system.debug('accountIds'+accountIds+' ownerid'+ ownerid);
            
        }
        
        //updaTE ACCOUNT
        List<Account> accList=[Select id,ownerid from account where id=:accountIds];
        system.debug('accList'+accList.size());
        
        for(Account acc:accList){
            acc.ownerid=ownerid;
            updateAccOwnerList.add(acc);
        }
        
        system.debug('updateAccOwnerList'+updateAccOwnerList.size());
        if(updateAccOwnerList.size()>0){
            update updateAccOwnerList;
        }
        
        //update opportunities
        List<Opportunity> oppList=[Select id,Ownerid,AccountId from Opportunity Where AccountId = :accountIds ];
        system.debug('opplist'+oppList.size());
        
        
        
        for(Opportunity op: opplist){
            op.ownerid=ownerid;
            updateoppList.add(op);
            
        }
        
        system.debug('updateoppList'+updateoppList);  
        
        if(!updateoppList.isEmpty())
            update updateoppList;  
    
    //update Quote
    List<SBQQ__Quote__c> qsList=[Select id,Ownerid from SBQQ__Quote__c where SBQQ__Account__c = :accountIds];
     for(SBQQ__Quote__c qs: qsList){
            qs.ownerid=ownerid;
           updateqsList.add(qs);
            
      }
        system.debug('updateqsList'+updateqsList);  
        
        if(!updateqsList.isEmpty())
            update updateqsList; 
        
        //contract
        List<Contract> crList=[Select id,Ownerid from Contract where AccountId = :accountIds];
     for(Contract qs: crList){
            qs.ownerid=ownerid;
           updatecrList.add(qs);
            
      }
        system.debug('updatecrList'+updatecrList);  
        
        if(!updatecrList.isEmpty())
            update updatecrList;  
    }    
}
Hi All, 

I have written a batch class and the scenerio is to delete the unused reports which are 6 months old. User-added imageI am getting repeated errors, not sure where i am going wrong
Please find the below code  and do let me know if  any changes required to be made.

Batch Class :

global class BatchMassDeleteReports implements Database.Batchable<sObject>{
    

    public Database.QueryLocator start(Database.BatchableContext context)
    {
        return Database.getQueryLocator('Select ID from Report where LastRunDate <= LAST_N_DAYS:180');
    }

    public void execute(Database.BatchableContext context, List<Report> records)
    {
        delete records;
    }
   public void finish(Database.BatchableContext){
        
    }
}  


Also find the schedule class below :


public DeleteReportSchedulerClass() {
    }
    
    global void execute(SchedulableContext sc){
        try{
            //Executing batch class (size:50).
            BatchMassDeleteReports batchApexSchd = new BatchMassDeleteReports();   
            database.executebatch(batchApexSchd, 50);
            
            }catch(exception ex){
             //Catching any exception that occurs.
            System.Debug('There was an error ' + ex.getMessage());
            }
    }




Thanks, 
Ramesh
Hi all,

I have written batch class  which will be sheduled to delete reports which were created 6 months and are not used. I am not sure if this is correct or is there anything required please need suggestion for this.
Global class BatchMassDeleteReports Implements Database.batchable<sobject>{
    
     global Database.QueryLocator start(Database.BatchableContext BC){
        
     return Database.getQueryLocator([SELECT Id from Report where CreatedDate <= LAST_N_DAYS:180 AND LastModifiedDate <= LAST_N_DAYS:180]);
     }
     global  void execute(Database.BatchableContext BC,List<Report> scope){
         list<Report> delReports = (list<Report>)scope;
         if(delReports.CreatedDate <= LAST_N_DAYS:180 && delReports.LastModifiedDate <= LAST_N_DAYS:180)
         {
         delete delReports;
         }   
    }
    global void finish(Database.BatchableContext BC){
        
    }

 } 
connected Application crashes when user login to Application through single sign on, after that Application logo wont appears  instead directed to salesforce login and unable to login using his federation id and password.what may be the reason? 
In VF page i have a picklist field contains 5 picklist values. and for all the 4 picklist values the placholder will be same but for one picklist value the placholder should be different, how to implement this 
As i want to make certain fields read only, and i am facing the issue when i m trying to genarate the pdf. As the values are not coming in pdf output, and when i am removing html-disable = true, the values are coming in pdf
To fix the exception: System.LimitException: Too many SOQL queries: 101 made changes to the apex class as below. Can anyone please highlight the issue in it? as i am getting another error while saving-Method does not exist or incorrect signature: void add(String) from the type List<Order>

Apex Class-
Public class QTB_CreateOrderItem {
    public static final string className = QTB_CreateOrderItem.class.getName();
    public static boolean throwExplicitException = false;
    // Calling this method from flow to create orderitems based on selected products.
    @InvocableMethod
   Public static void updateOrderItemDetails(list <flowInputs> request)
    {   
        List<OrderItem> OrderItemlst = new List<OrderItem>();
        List <PriceBookEntry> book = new  List <PriceBookEntry>();
        List<Order> NewCrOrder = new List<Order>();
        String errorIds = '';
        List<Order> NewCrOrder1 = new List<Order>();
       
        
        For(flowInputs flow:request)
        {
            NewCrOrder1.add(flow.newOrderCreated);
            
            book=[select id, name,Product2Id,Product2.SBQQ__ChargeType__c,Product2.SBQQ__BillingFrequency__c,Product2.SBQQ__BillingType__c,Product2.blng__BillingRule__c,Product2.blng__TaxRule__c,Product2.blng__RevenueRecognitionRule__c,Product2.SBQQ__SubscriptionTerm__c from PricebookEntry where ProductCode in :flow.productCodes and Pricebook2Id = :flow.oldOrderData.Pricebook2Id ];
            system.debug('Retrieved PRbentry ----------'+ book.size());      
        }
        
        NewCrOrder1 = [Select id,name,EffectiveDate,EndDate,QTB_Legal_Entity_Country__c,Account.QTB_Contract_Entity__c from order  where id IN :NewCrOrder];    
        

            
        
        try {
            if (throwExplicitException) {
                system.debug('NullPointer');
                throw new NullPointerException();
            } 
            
            List<blng__BillingTreatment__c> sgListBillingTreat=[Select id, name,blng__BillingRule__r.id from blng__BillingTreatment__c Where Name='No Invoice Billing Treatment' LIMIT 1];
            if(book.size()>0)  {  
                For(pricebookentry pr : book)
                  {  
                    OrderItem temporderitem = new OrderItem();
                    temporderitem.OrderId = NewCrOrder[0].id;
                    temporderitem.blng__BillableUnitPrice__c= 0;
                    temporderitem.Product2Id = pr.Product2.Id;
                    temporderitem.Quantity = 1;
                    temporderitem.UnitPrice = 0;    
                    temporderitem.blng__HoldBilling__c = 'No';   
                    temporderitem.blng__TaxCountry__c = NewCrOrder[0].QTB_Legal_Entity_Country__c;
                    temporderitem.ServiceDate = NewCrOrder[0].EffectiveDate;
                    temporderitem.EndDate = NewCrOrder[0].EndDate;
                    temporderitem.SBQQ__BillingFrequency__c = 'Monthly';
                    temporderitem.SBQQ__BillingType__c = 'Arrears';
                    temporderitem.SBQQ__ChargeType__c  = 'Recurring';  
                    temporderitem.SBQQ__ContractAction__c  = 'New'; 
                    temporderitem.SBQQ__ContractingMethod__c  = 'Inherit';
                    temporderitem.SBQQ__SubscriptionTerm__c= 1;    
                    temporderitem.SBQQ__DefaultSubscriptionTerm__c= 1;
                    temporderitem.SBQQ__OrderedQuantity__c= 1;
                    temporderitem.SBQQ__PricingMethod__c='List';
                    temporderitem.SBQQ__ProductSubscriptionType__c = 'One-Time'; 
                    temporderitem.SBQQ__SubscriptionType__c = 'One-Time';
                    temporderitem.SBQQ__Status__c = 'Draft';   
                    temporderitem.SBQQ__SubscriptionPricing__c='Fixed Price';
                    temporderitem.PricebookEntryId = pr.Id;
                    temporderitem.blng__BillingRule__c =pr.Product2.blng__BillingRule__c;
                    temporderitem.blng__BillingTreatment__c = sgListBillingTreat[0].id;
                    temporderitem.blng__LegalEntity__c = NewCrOrder[0].Account.QTB_Contract_Entity__c;
                    temporderitem.blng__RevenueRecognitionRule__c  = pr.Product2.blng__RevenueRecognitionRule__c;
                    temporderitem.blng__TaxRule__c = pr.Product2.blng__TaxRule__c;
                    OrderItemlst.add(temporderitem);    
                   }
            }
            Insert OrderItemlst;
            system.debug('Inserted Items ======' +OrderItemlst.size());
            List<Id> OrdidtoLoad = new List<Id>();
            OrdidtoLoad.add(NewCrOrder[0].id);
            //To update order item for seperate invoicing 
            list<OrderItem> lstupdate= new list<OrderItem>();
            list<OrderItem> itemlst = new list<OrderItem>();
            itemlst=[Select id,blng__InvoiceGrouping__c,blng__InvoiceGroupId__c,Order.OrderNumber from OrderItem where order.id IN :OrdidtoLoad];
            system.debug('Total Selected to update:'+ itemlst.size());
            for(OrderItem ls : itemlst)
            {
                ls.blng__InvoiceGrouping__c= 'Invoice Group ID';
                ls.blng__InvoiceGroupId__c= ls.Order.OrderNumber;
                lstupdate.add(ls);
                
            }
            system.debug('Total Selected to update:'+ lstupdate.size());  
            update lstupdate;
            //To Update matching attribute on usage summary related to newly created orderItems
            List<blng__UsageSummary__c  > Uslsttoupdate =new List<blng__UsageSummary__c>();
            List<blng__UsageSummary__c  > Uslst = new List<blng__UsageSummary__c  >();
            Uslst =[Select id,blng__MatchingAttribute__c,blng__Order__r.OrderNumber from blng__UsageSummary__c Where blng__Order__r.id IN :OrdidtoLoad];
            system.debug('Size+++++++++++++++:'+ Uslst.size());
            for (blng__UsageSummary__c us :Uslst)
            {
                us.blng__MatchingAttribute__c = us.blng__Order__r.OrderNumber;
                Uslsttoupdate.add(us);
            }
            Update Uslsttoupdate;
            System.debug('Updated count====='+Uslsttoupdate.size());
            // To activate Created Orders/OrderItems
            Database.executeBatch(new QTB_AddOrderProductCSCRBatch(OrdidtoLoad), 200);
            
        }
          catch (exception e) {
            errorIds = e.getMessage() + errorIds;
            if (errorIds.length() > 100000)
                errorIds = errorIds.substring(0, 100000);
            system.debug('In catch method of batch Finish>>>>>>>>>>');
            system.debug('Error inf::' + errorIds);
            QTB_ExceptionLogger.createLog(
                e.getLineNumber(),
                e.getStackTraceString(),
                errorIds,
                e.getTypeName(),
                className
            );
        }  
        
    }
  Public class flowInputs{
        @InvocableVariable
        public Order oldOrderData;
        @InvocableVariable    
        Public string newOrderCreated;
        @InvocableVariable
        Public list<String> productCodes;
      }
    
}
I have a picklist field  Z and its value are like A,B,C. I want to create formulae field and mark it true when the picklist field contains values A and B only. Tried multiple and unable to acheive it. please help
one example as below tried as well but not working:
IF(OR(TEXT(Z__c) = 'A',TEXT(Reason_Code_1__c) = 'B'),true,false)
In Salesforce CPQ I have updated the Ship To name,address,city,zip in quote detail page and saved and  got updated  and reflecting but when checking PDF document the Ship to name is showing the old name and and not updated to new name but the address, city, zip is showing the updated values. What must be reason can anyone share the path to troubleshoot the issue.
I have written an invocable apex class for process builder to update th owner change of accounts and related Opportunity, contracts and quotes on custom object and its working fine. Now i need to bulkify the code. what are the changes required in below code ?
below code :
public class RequestPortalRecords
{
    @InvocableMethod
    public static void ReqChange(List<Request_Portal__c> rp)
    {
        system.debug('entered raghav' +rp);
        Set<Id> accountIds=new Set<Id>();
        Id ownerid;
        list<Account> updateAccOwnerList = new list<Account>();
        list<Opportunity> updateoppList = new list<Opportunity>();
        list<SBQQ__Quote__c> updateqsList = new list<SBQQ__Quote__c>();
        list<contract> updatecrList=new list<contract>();
        
        
        for(Request_Portal__c r : rp)
        {
            accountIds.add(r.Account_Name__c);
            ownerid=r.New_Owner__c;
            system.debug('accountIds'+accountIds+' ownerid'+ ownerid);
            
        }
        
        //updaTE ACCOUNT
        List<Account> accList=[Select id,ownerid from account where id=:accountIds];
        system.debug('accList'+accList.size());
        
        for(Account acc:accList){
            acc.ownerid=ownerid;
            updateAccOwnerList.add(acc);
        }
        
        system.debug('updateAccOwnerList'+updateAccOwnerList.size());
        if(updateAccOwnerList.size()>0){
            update updateAccOwnerList;
        }
        
        //update opportunities
        List<Opportunity> oppList=[Select id,Ownerid,AccountId from Opportunity Where AccountId = :accountIds ];
        system.debug('opplist'+oppList.size());
        
        
        
        for(Opportunity op: opplist){
            op.ownerid=ownerid;
            updateoppList.add(op);
            
        }
        
        system.debug('updateoppList'+updateoppList);  
        
        if(!updateoppList.isEmpty())
            update updateoppList;  
    
    //update Quote
    List<SBQQ__Quote__c> qsList=[Select id,Ownerid from SBQQ__Quote__c where SBQQ__Account__c = :accountIds];
     for(SBQQ__Quote__c qs: qsList){
            qs.ownerid=ownerid;
           updateqsList.add(qs);
            
      }
        system.debug('updateqsList'+updateqsList);  
        
        if(!updateqsList.isEmpty())
            update updateqsList; 
        
        //contract
        List<Contract> crList=[Select id,Ownerid from Contract where AccountId = :accountIds];
     for(Contract qs: crList){
            qs.ownerid=ownerid;
           updatecrList.add(qs);
            
      }
        system.debug('updatecrList'+updatecrList);  
        
        if(!updatecrList.isEmpty())
            update updatecrList;  
    }    
}
Hi all,

I have written batch class  which will be sheduled to delete reports which were created 6 months and are not used. I am not sure if this is correct or is there anything required please need suggestion for this.
Global class BatchMassDeleteReports Implements Database.batchable<sobject>{
    
     global Database.QueryLocator start(Database.BatchableContext BC){
        
     return Database.getQueryLocator([SELECT Id from Report where CreatedDate <= LAST_N_DAYS:180 AND LastModifiedDate <= LAST_N_DAYS:180]);
     }
     global  void execute(Database.BatchableContext BC,List<Report> scope){
         list<Report> delReports = (list<Report>)scope;
         if(delReports.CreatedDate <= LAST_N_DAYS:180 && delReports.LastModifiedDate <= LAST_N_DAYS:180)
         {
         delete delReports;
         }   
    }
    global void finish(Database.BatchableContext BC){
        
    }

 }