• RajandraS
  • 5 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 6
global class ItalyPriceBookIntegrationBatch implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC){
        Datetime lastOneHour = Datetime.now().addMinutes(-60);
        string finalQuery = 'Select Id, Sales_Org__c, Product_SKU_Calculated__c from Product2 where (NOT Material_Master_ID__c like \'' +'%SEP%' + '\')' 
            +' and LastModifiedDate >= ' +string.valueOf(lastOneHour.Date())+'T'+string.valueOf(lastOneHour.Time());
        system.debug('Final Query --> ' +finalQuery);
        return Database.getQueryLocator(finalQuery);
    global void execute(Database.BatchableContext BC,List<Product2> scope){
        set<Id> prodIdSet = new set<Id>();
        List<PriceBookEntry> newPBEList = new List<PriceBookEntry>();
        List<PriceBookEntry> updatePBEList = new List<PriceBookEntry>();
        map<Id,PriceBookEntry> pbeProdMap = new map<Id,PriceBookEntry>();
        string it01PBid = System.Label.IT01_PriceBookId;
        for(Product2 prod : scope){
        System.debug('the Price Book Entries are -->'+prodIdSet);
        for(PriceBookEntry pbeList : [Select Id,Name,Product2Id,IsActive from PriceBookEntry where Pricebook2Id =:it01PBid and Product2Id In :prodIdSet]){
        System.debug('the Price Book Entries are -->'+pbeProdMap);
        for(Product2 prodIT : scope){
            if(prodIT.Sales_Org__c == 'IT01'){
                if(pbeProdMap.get(prodIT.Id)!= Null){
                    PriceBookEntry oldPBE = pbeProdMap.get(prodIT.Id);
                    System.debug('the PBE is -->'+oldPBE.Id+oldPBE.Name);
                        oldPBE.IsActive = True;
                }else {
                    PriceBookEntry newPBE = new PriceBookEntry();
                    newPBE.Pricebook2Id = System.Label.IT01_PriceBookId;
                    newPBE.Product2Id = prodIT.Id;
                    newPBE.IsActive = True;
                    newPBE.PBE_External_Id__c = 'EPC-IT01-'+prodIT.Product_SKU_Calculated__c;
                    newPBE.UnitPrice = 0.00;
                    newPBE.CurrencyIsoCode = 'EUR';
            }else {
                if(pbeProdMap.get(prodIT.Id)!= Null){
                    PriceBookEntry oldPBE = pbeProdMap.get(prodIT.Id);
                    System.debug('the PBE is -->'+oldPBE.Id+oldPBE.Name);
                        oldPBE.IsActive = False;
        system.debug('The update list is -->'+updatePBEList.size());
        if(updatePBEList.size() > 0){
            Database.SaveResult[] oldPBE = Database.update(updatePBEList,false);
            for(Database.SaveResult opbe:oldPBE){
                    system.debug(' Error-->'+opbe.getErrors());        
        system.debug('The new list is -->'+newPBEList.size());
        if(newPBEList.size() > 0){
            Database.SaveResult[] newPBE = Database.insert(newPBEList,false);
            for(Database.SaveResult npbe:newPBE){
                    system.debug(' Error -->'+npbe.getErrors());        
    global void finish(Database.BatchableContext BC){

Test Class--

public class ItalyPriceBookIntegrationBatch_Test {
    static void setup(){
        Product2 prodOne =  DivAC_00_TestFactory.getProduct('Test Product');
        prodOne.Sales_Org__c = 'IT01';
        prodOne.Material_Master_ID__c = '12345_EPC';
        insert prodOne;
        Pricebook2 standardPricebook = DivAC_00_TestFactory.getStdPriceBookId();
        Map<id,PricebookEntry> pbeProdMap = new Map<id,PricebookEntry>();
        PricebookEntry pbe = DivAC_00_TestFactory.getPriceBookEntry(String.ValueOf(standardPricebook.Id),String.ValueOf(prodOne.Id),2);
        pbe.Product2Id = prodOne.id;
        pbe.IsActive = true;
        insert pbe;
        System.debug('the Price Book Entries are -->'+pbeProdMap);
        PriceBookEntry oldPBE = pbeProdMap.get(prodOne.Id);
    static testmethod void test(){
        ItalyPriceBookIntegrationBatch ipb = new ItalyPriceBookIntegrationBatch();
        ID batchId = Database.executeBatch(ipb);

Hi there,
I wondering when I tried to check to find out my current date then it gives me 2 hours back time.

User-added image    Datetime cDT = System.now();
    system.debug('Date Time: '+cDT);
    String LongDate = cDT.format('EEEE, MMMM d, yyyy');
    system.debug('long Date: '+LongDate);
   datetime d = Datetime.now();
   system.debug('d: '+d);
why my current time is not showing. I have checked the company information which is the exact my location but still the time showing 2 hours back. Please guide me.
I am trying to use PGP encryption in apex, Is there any library or native support for that in apex.
So, I'm trying to get product related to opportunity to show up in the same page, but even with an extended controller I can't seem to get it working. 

<apex:page standardController="Opportunity" extensions="PositionsExtends">
    <apex:form >
        <apex:pageBlock title="Edit Opportunity" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            <apex:pageBlockSection title="Opportunity Fields" Columns="1">
                <apex:outputText value="{!Opportunity.Amount}"/>
                <apex:inputField value="{!Opportunity.AccountId}"/>
                <apex:inputField value="{!Opportunity.LeadSource}"/>
                <apex:inputField value="{!Opportunity.CloseDate}"/>
                <apex:inputField value="{!Opportunity.StageName}"/>
                <apex:outputField value="{!ProductList.Name}"/>
                <apex:outputField value="{!ProductList.Opportunity__c}"/>
                <apex:outputField value="{!ProductList.StockKeepingUnit}"/>
                <apex:outputField value="{!ProductList.IsActive}"/>

public class PositionsExtends {
    public List<Product2> ProductList {get;set;}
    public PositionsExtends(apexpages.StandardController stdcontroller) {
        ProductList= [SELECT Name, Opportunity__c, StockKeepingUnit, IsActive FROM Product2 Limit 100];

What am I doing wrong here I am just getting an error saying Unknown property 'OpportunityStandardController.Product2'

Hi, I am a newbie to Salesforce (literally a newbie) but I do have experience in SPA Web Development with Angular & React.  As a newbie in SF, I am struggling with not knowing what schema or directive to import when working on the Lightning Web Component in VS Code.

I have already installed the Salesforce Extension Pack but it does not appear to have the "auto-import" feature.  With Angular, I can select the yellow lightbulb and the VS Code will insert the correct import schema or directive.  I am curious if there is something like that with Salesforce LWC development?

A couple of questions on the Salesforce to Dropbox Integration. My client installed this a while back and is having issues. 
1) Why does Dropbox not appear as a tab in App Launcher? If I do view all I can see Dropbox Options.
2) Do you have to reconnect to Dropbox under the Dropbox Options every time that you want to add a Dropbox file to a Salesforce folder?