• Jaymin Sutarwala 7
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 4
    Replies
Hi all,
Since day before yesterday our SAP Data Services team are facing an error while trying to fetch metadata from Salesforce. They are able to extract data from the objects but when they try to fetch the metadata from Salesforce they are getting the following error. Has anyone encountered this error before and can help?
User-added image

Below is the trace log from Salesforce adapter in SAP Data Services

10/11/17 4:40:18 PM        [SAX Parser Error] :1:23 : cvc-elt.1: Cannot find the declaration of element 'AdapterConfiguration'.
10/11/17 4:46:02 PM        Error browsing root nodes. Xml generated so far: []. java.lang.NullPointerException: while trying to invoke the method com.acta.adapter.salesforce.SForceMetadata.getTableMetadata(java.lang.String) of a null object loaded from field com.acta.adapter.salesforce.metadata.SForceBrowsing.sfdc of an object loaded from local variable 'this'
                at com.acta.adapter.salesforce.metadata.SForceBrowsing.getRootNodes(SForceBrowsing.java:79)
                at com.acta.adapter.sdk.AdapterRunnerImpl.processBrowseRoot(AdapterRunnerImpl.java:2532)
                at com.acta.adapter.sdk.AdapterServiceDataListener.handleBrokerMessage(AdapterServiceDataListener.java:106)
                at com.acta.brokerclient.BrokerClient.handleMessage(BrokerClient.java:406)
                at com.acta.brokerclient.BrokerClient.access$100(BrokerClient.java:53)
                at com.acta.brokerclient.BrokerClient$MessageHandler.run(BrokerClient.java:1559)
                at com.acta.brokerclient.ThreadPool$PoolThread.run(ThreadPool.java:100)

Regards,
Jaymin
I am trying to create a dynamic picklist component in my VF page. It is displaying the picklist but it is not rendering any values in the picklist. Can anyone take a look and see if they can figure out something?

User-added image
<apex:page standardController="Quote" standardStylesheets="true" extensions="TestDynamicTableExtension">
    <apex:form >
    	<apex:pageBlock id="tDTPageBlock">
            <apex:pageBlockSection >
                	<apex:commandButton value="Add a Site"/>
            		<apex:commandButton value="Add FY"/>
                    <apex:dynamicComponent componentValue="{!dynamicTable}" />
                    <!--apex:pageBlockTable value="" var="">
                    </apex:pageBlockTable-->
            </apex:pageBlockSection>
    	</apex:pageBlock>
	</apex:form>
</apex:page>
 
public class TestDynamicTableExtension {
	public List<dynamicTableRow> dynamicTRows = new List<dynamicTableRow>();
	public transient List<Schema.PicklistEntry> ple;
	public transient Schema.DescribeFieldResult fieldResult;
    public transient List<Component.Apex.SelectOption> options {get; set;}
    	
	public TestDynamicTableExtension(ApexPages.standardController stdController){
		initdynamicTRowsList();
		//createTableOnPageLoad();
	}
	
	/*public List<Component.Apex.SelectOption> getOptions(){
		fieldResult = Quote.Primary_Site__c.getDescribe();
		ple = fieldResult.getPicklistValues();
		for(Schema.PicklistEntry f : ple){
			options.add(new Component.Apex.SelectOption(itemlabel=f.getLabel(), itemvalue=f.getValue()));
			//Component.Apex.SelectOption so = new Component.Apex.SelectOption();
		}
		System.debug('Primary sites: ' + options);
		return options;
	}*/
	
	public void initdynamicTRowsList(){
		dynamicTableRow dtr = new dynamicTableRow();
		dtr.saveDeleteCheckbox = false;
		dtr.primarySite = null;
		dynamicTRows.add(dtr);
	}

	public Component.Apex.PageBlockTable getDynamicTable(){
		Component.Apex.PageblockTable dynamicTbl = new Component.Apex.PageblockTable();
		dynamicTbl.value = dynamicTRows;
		dynamicTbl.var = 'tRow';
		
		//Column 1 - Save Delete checkbox
		Component.Apex.Column tCol1 = new Component.Apex.Column();
		Component.Apex.InputCheckBox saveDelCB = new Component.Apex.InputCheckBox();
		tCol1.childComponents.add(saveDelCB);
		dynamicTbl.childComponents.add(tCol1);
		
		//Column 2 - Primary site picklist
		Component.Apex.Column tCol2 = new Component.Apex.Column();
		tCol2.headerValue = 'Primary site';
		Component.Apex.SelectList primarySite = new Component.Apex.SelectList(multiselect=false);
		//Component.Apex.SelectOptions primarySiteValues = new Component.Apex.SelectOptions();
		
		fieldResult = Quote.Primary_Site__c.getDescribe();
		ple = fieldResult.getPicklistValues();
		options = new List<Component.Apex.SelectOption>();
		for(Schema.PicklistEntry f : ple){
			options.add(new Component.Apex.SelectOption(itemlabel=f.getLabel(), itemvalue=f.getValue()));
		}

        primarySite.expressions.Value = '{!options}';
        tCol2.childComponents.add(primarySite);
        dynamicTbl.childComponents.add(tCol2);

		//Column 3 - Year 1
		Component.Apex.Column tCol3 = new Component.Apex.Column();
		tCol3.headerValue = 'Year 1';
		Component.Apex.InputText yr1 = new Component.Apex.InputText();
		yr1.style = 'width: 50px';
		tCol3.childComponents.add(yr1);
		dynamicTbl.childComponents.add(tCol3);
		
		return dynamicTbl;
	}
	
	public class dynamicTableRow{
		Boolean saveDeleteCheckbox {get; set;}
		String primarySite {get; set;}
		Map<String, Decimal> tcvMap = new Map<String, Decimal>();
	}
    
}

 
Hi all,
I am trying to render hyperlink in the one of the columns of datatable in visualforce component. My requirement is to render the first four row values (Primary, Secondary, Tertiary, Non-Target) as hyperlink but the last row (Total) should not be displayed as hyperlink.
User-added image
I tried using 'rendered' attribute in the <apex:outputLink> tag but on doing that it is not displaying any values in the column (shown below). Can anyone recommend a way to achieve this?

User-added image
<apex:dataTable value="{!DPSRandFValues}" var="DPSRandFData" cellpadding="5" border="1" headerClass="RFheaderStyle" styleClass="inlineTable">
        <apex:column headerValue="         " style="{!DPSRandFData.color}">
            <apex:outputLink rendered="NOT({!DPSRandFData.targetClassification} = 'Total')" value="javascript:window.open('https://cs40.salesforce.com/00O54000000Fuor?pv0={!TPOwnerFullName}&pv1={!TPOwnerFullName}&pv2={!FYStartDt}&pv3={!FYEndDt}&pv4={!DPSRandFData.targetClassification}')" > 
            	{!DPSRandFData.targetClassification}
            </apex:outputLink>
        </apex:column>
        <apex:column headerValue="{!$Label.TP_R_F_header_Clients}" value="{!DPSRandFData.totalClients}" style="{!DPSRandFData.color}"/> 
        <apex:column headerValue="{!$Label.TP_R_F_header_Reached}" value="{!DPSRandFData.clientsReached}"  style="{!DPSRandFData.color}"/> 
        <apex:column headerValue="{!$Label.TP_R_F_header_Activities}" value="{!DPSRandFData.totalActivities}" style="{!DPSRandFData.color}"/>
        <apex:column headerValue="{!$Label.TP_R_F_header_Frequency}" value="{!DPSRandFData.clientsFrequency}" style="{!DPSRandFData.color}"/>
    </apex:dataTable>

Regards,
Jaymin
I am displaying an iFrame on a standard page layout of a custom object. Within the iFrame is displaying a bunch of tables; when I resize the browser page the tables within the iFrame expands beyond the iFrame boundaries. Is there a way to resize the iframe when the webpage is resized?
Hi all,
I have written the following query in Opportunity Territory Assignment Apex Class. This query is not returning any result in the code. I tried execuring the query in Workbench but it is not returning any records.
SELECT Id, ObjectID, Territory2Id, Territory2.Territory2Type.MasterLabel, Territory2.ParentTerritory2Id FROM ObjectTerritory2Association WHERE SObjectType = 'Account' AND Territory2.Territory2ModelId = :activeModelId
However if I remove the condition SObjectType = 'Account' from the query and run it, it returns records. Any idea why the query is not working with the condition SObjectType = 'Account'

User-added image

 
Hi all,
We have a flow which is embedded in a visualforce page. The visualforce page allows the user to attach documents from the flow screen and will be rendered only during the end.
User-added image

We want to add pause functionality to the flow and for that I added the pause button on the flow. When I click the pause button it will pause the flow. When I try to resume the paused flow from my Home page; the visualforce page is not rendered only the flow screen is rendered. I would like to have the VF page display below the flow screeen like it was before the flow was paused. Any idea how to fix it?

User-added image
Hi all,
We added couple of validation rules on the Quote object which broke a couple of our test classes. I fixed those test classes and am now trying to deploy those classes into production through changesets. The issue I am facing is when i perform the validation salesforce picks the test classes that exists in production instead of the modified test classes in my changeset. How can I deploy my modified test classes into production?
Hi all,
I am trying to display a help text box on the flow screen using DIV attribute in the text template.
<div style="width:500px;height:20px;border:1px solid #ff8000;background-color:#ffffb3;font-family:arial;font-size:80%">This is the phase we are quoting proposal for</div>
When i run the HTML code in an editor it works fine.
User-added image

But when i use the same HTML in the text template in a 'Display text' element on Flow screen it doesn't display the orange border. Can anyone identify the issue here.
User-added image
Hi all,
A very strange issue is happening in the below apex code. I have return a batch job (Batch_Annual_Contract_Value_DER) to update Annual contract Value records with the latest Dated Exchange rates based on the Opportunity close date. The other class CurrencyUtil creates a yearExchngRateMap (Map<Integer, Map<String, Decimal>>) which holds the year as the key and another map with IsoCode as key and the Dated Exchange rate for that year as value. In the CurrencyUtil class when the getPrevYearCurrencyRate method is called from the Else at line 115 the values in the map yearExchngRateMap get overriden. I spent a lot of time on this but am not able to figure out why is this happening. Can anyone take a look at the code and see if they can figure out something.
 
public without sharing class CurrencyUtil {

    public static Map<String, Decimal> currencyExchangeRateMap = new Map<String, Decimal>();

    // Map that holds the Exchange Rates by Year
    Public static Map<Integer, Map<String, Decimal>> yearExchngRateMap = new Map<Integer, Map<String, Decimal>>();
    private static String CurrencyTypes = Label.Currency_Types;
    private static String[] currencies = CurrencyTypes.split(',');

    public static Decimal convertToOrgDefaultCurrency(Decimal amount, String isoCode) {
        Decimal convertedAmount = 0.0;
        if(amount != null && isoCode != null && !isoCode.equals('')) {
                convertedAmount = amount / currencyExchangeRateMap.get(isoCode);
        }
        return convertedAmount;
    }
    
    public static Decimal convertToOrgDefaultCurrency(Decimal amount, String isoCode, Integer fiscalYear) {
        Decimal convertedAmount = 0.0;
        if(amount != null && isoCode != null && !isoCode.equals('')) {
            convertedAmount = amount / yearExchngRateMap.get(fiscalYear).get(isoCode);
        }
        return convertedAmount;
    }

    public static void updateExchangeRatesMap() {
        currencyExchangeRateMap.clear();
        currencyExchangeRateMap.put('USD', 1.000000);
        List<DatedConversionRate> dtdExchngRates = [Select Id, ConversionRate, IsoCode, NextStartDate, StartDate 
                                                from DatedConversionRate
                                                where startdate = THIS_FISCAL_YEAR
                                                order by startdate desc];
        System.debug('dtdExchngRates : '+dtdExchngRates);
        for(DatedConversionRate dtdER : dtdExchngRates) {
            if(!currencyExchangeRateMap.containsKey(dtdER.IsoCode)) {
              currencyExchangeRateMap.put(dtdER.IsoCode, dtdER.ConversionRate);
            }
        }
        System.debug('currencyExchangeRateMap : '+currencyExchangeRateMap);
    }

    public static void updateConversionRatesMap() {
        System.debug('currencies : '+currencies);
        yearExchngRateMap.clear();
        String dteFormat = '-11-01';
        Integer lstFiveYr = System.today().Year() - 5;
        Date fiveYrAgo = Date.valueOf(String.valueOf(lstFiveYr) + dteFormat);
        System.debug('fiveYrAgo : '+fiveYrAgo);
        
        List<DatedConversionRate> dtdExchngRates = [SELECT Id, ConversionRate, IsoCode, NextStartDate, StartDate 
                                                      FROM DatedConversionRate
                                                     WHERE StartDate >=: fiveYrAgo
                                                    ORDER BY Startdate asc];
        System.debug('dtdExchngRates : '+dtdExchngRates);
        
        // Build the DatedConversionRateMap for the past five years - From DatedConversionRate Object
        if(!dtdExchngRates.isEmpty()) {
            Integer dcrYear = null;
            Map<String, Decimal> currRateMap = null;
            for(DatedConversionRate dcr : dtdExchngRates) {
                dcrYear = dcr.StartDate.Year();
                if(yearExchngRateMap != null && !yearExchngRateMap.containsKey(dcrYear)) {
                    yearExchngRateMap.put(dcrYear, new Map<String, Decimal> {'USD' => 1.000000});
                }
                if(yearExchngRateMap != null && yearExchngRateMap.containsKey(dcrYear)) {
                    currRateMap = yearExchngRateMap.get(dcrYear);
                    if(currRateMap != null && !currRateMap.containsKey(dcr.IsoCode)) {
                        currRateMap.put(dcr.IsoCode, null);
                        yearExchngRateMap.put(dcrYear, currRateMap);
                    }
                    if(currRateMap != null && currRateMap.containsKey(dcr.IsoCode)) {
                        currRateMap.put(dcr.IsoCode, dcr.ConversionRate);
                        yearExchngRateMap.put(dcrYear, currRateMap);
                    }
                }
            }
        }
        System.debug('yearExchngRateMap : '+yearExchngRateMap);
        
        /* Verify whether all the Currency Types are present for all the years, 
           If not add the missed out CurrencyRate from the Previous Fiscal Year
        */
        Decimal exchngRate = null;
        Map<String, Decimal> currencyRateMap = new Map<String, Decimal>();
        Date fiscalYrStartDate = Date.newInstance(Date.today().year(), 11, 1);
        Integer fiscalYear;
        if(yearExchngRateMap != null && !yearExchngRateMap.isEmpty()) {
        //    for(Integer fiscalYear : yearExchngRateMap.keyset()) {
            System.debug('Currencies: ' + currencies);
			if(Date.today() < fiscalYrStartDate)            
                fiscalYear = Date.today().year() - 1;
            else
                fiscalYear = Date.today().year();
            
            for(Integer iteration = 0; iteration<5; iteration++){
                System.debug('Inside iteration loop, iteration# ' + iteration);
                System.debug('Currency List size: ' + currencies.size());
                System.debug('fiscalYear: ' + fiscalYear);
                if(yearExchngRateMap.containsKey(fiscalYear)){
                	currencyRateMap = yearExchngRateMap.get(fiscalYear);   
                    System.debug('Currency Rate Map found for FY ' + fiscalYear);
                    System.debug('Currency Rate Map: (in IF) ' + currencyRateMap);
                    for(String curr : currencies) {
                        if(!currencyRateMap.containsKey(curr)) {
                    //      exchngRate = getPrevYearCurrencyRate(fiscalYear, curr, fiveYrAgo.year()-1);
                    		exchngRate = getPrevYearCurrencyRate(fiscalYear, curr);
                            System.debug('Currency (in IF): ' + curr);
                            System.debug('Exchange Rate (in IF): ' + exchngRate);
                            currencyRateMap.put(curr, exchngRate);
                        }
                    }
				 	yearExchngRateMap.put(fiscalYear, currencyRateMap);
                    System.debug('yearExchngRateMap (in IF): ' + yearExchngRateMap);
                }
                else{
					//currencyRateMap.clear();
                    System.debug('Currency Rate Map: (before) ' + currencyRateMap);
                    System.debug('yearExchngRateMap (before in ELSE): ' + yearExchngRateMap);
                    for(Integer key: yearExchngRateMap.keySet()){
            			System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        			}
                    for(String curr : currencies) {
                    //  exchngRate = getPrevYearCurrencyRate(fiscalYear, curr, fiveYrAgo.year()-1);
                        exchngRate = getPrevYearCurrencyRate(fiscalYear, curr);
                        System.debug('Currency: (in ELSE)' + curr);
                        System.debug('Exchange Rate: (in ELSE)' + exchngRate);
                        currencyRateMap.put(curr, exchngRate);
                    }
                    System.debug('Currency Rate Map: (after) ' + currencyRateMap );
                    System.debug('Fiscal Year: ' + fiscalYear);
                    yearExchngRateMap.put(fiscalYear, currencyRateMap);
                    System.debug('yearExchngRateMap (after in ELSE): ' + yearExchngRateMap);
                    for(Integer key: yearExchngRateMap.keySet()){
            			System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        			}
                }
                fiscalYear = fiscalYear - 1;
            }
        }
        System.debug('yearExchngRateMap : After Verification Logic : '+ yearExchngRateMap);
        //Display yearExchangRateMap
        for(Integer key: yearExchngRateMap.keySet()){
            System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        }
    }
                       
//  private static Decimal getPrevYearCurrencyRate(Integer fYear, String currencyIso, Integer fiveYrAgoYear) {
	private static Decimal getPrevYearCurrencyRate(Integer fYear, String currencyIso) {
		Decimal convRate;
        Integer prevFiscalYear = fYear - 1;
        //if(prevFiscalYear > fiveYrAgoYear){
        //
        	System.debug('yearExchngRateMap (in getPrevYearCurrencyRate): ' + yearExchngRateMap);
        	for(Integer key: yearExchngRateMap.keySet())
            	System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        //
            Map<String, Decimal> prevCurrRateMap = yearExchngRateMap.get(prevFiscalYear);
            convRate = null;
            System.debug('In getPrevYearCurrencyRate');
            if(prevCurrRateMap != null && prevCurrRateMap.containsKey(currencyIso)) {
                if(prevCurrRateMap.get(currencyIso) != null) {
                    convRate = prevCurrRateMap.get(currencyIso);
                } else {
                  //convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso, fiveYrAgoYear);
                    convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso);
                }
            }
            else{
                //convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso, fiveYrAgoYear);
                convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso);
            }
        /*}
        else{
            convRate = null;
        }*/
        return convRate;
    }
}
 
global class Batch_Annual_Contract_Value_DER implements Database.Batchable<sObject>, Database.Stateful {
    Map<Id,Annual_Contract_Value__c> MapquoteId = new Map<ID,Annual_Contract_Value__c>();
    Map<Id,String> MapIsoCode = new Map<ID,String>();
    Map<Id,Integer> MapCloseDate = new Map<ID,Integer>();
    final String[] oppStageToAvoid = new String[] {'Declined to Quote', 'Legacy'};  
    final String[] oppOpenStage = new String[] {'Fact Finding', 'Covering the Bases', 'Negotiating', 'Closing'};
    final String[] oppClosedStage = new String[] {'Closed/Lost', 'Closed/Won'};
        
    global List<Annual_Contract_Value__c> start(Database.BatchableContext BC) {     
        List<Annual_Contract_Value__c> acvList = [SELECT Id,Quote__r.Id,Dated_Exchange_Rate__c,Fiscal_Year__c,Quote__c,Expected_Revenue__c,Quote__r.CurrencyIsoCode,Opportunity_Stage__c,Opportunity_Close_Date__c, Batch_Error__c, Batch_Job_runtime__c, ACV_Currency__c
                                                    FROM Annual_Contract_Value__c
                                                   WHERE Opportunity_Stage__c !=: oppStageToAvoid
                                                     AND (Opportunity_Stage__c IN :oppOpenStage 
                                                         OR
                                                         (Opportunity_Stage__c IN :oppClosedStage
                                                          AND Opportunity_Last_Modified_Date__c = LAST_N_DAYS:31))
                                                  ORDER BY Id, Quote__c];        
        system.debug('acvList:'+acvList);
        system.debug('acvList size: ' + acvList.size());
        
        if(acvList.size() > 0){
            For(Annual_Contract_Value__c acvInstance:acvList){
                MapquoteId.put(acvInstance.Quote__c,acvInstance);
            }
        }
        
        List<Quote> qList = [select Id,CurrencyIsoCode,Opportunity.CloseDate from Quote where Id IN: MapquoteId.keyset()];        
        System.debug('qList size: ' + qList.size());
        if(qList.size() > 0){
            For(Quote qInstance:qList){
                MapIsoCode.put(qInstance.Id,qInstance.CurrencyIsoCode);
                Date fiscalYrStartDate = Date.newInstance(qInstance.Opportunity.CloseDate.year(), 11, 1);
                System.debug('Quote Id: ' + qInstance.Id);
                System.debug('fiscalYrStartDate: ' + fiscalYrStartDate);
                If(qInstance.Opportunity.CloseDate < fiscalYrStartDate)
                    MapCloseDate.put(qInstance.Id,qInstance.Opportunity.CloseDate.year() - 1);
                Else
                    MapCloseDate.put(qInstance.Id,qInstance.Opportunity.CloseDate.year());
            }
        }        
    //    system.debug('Map1Values:'+MapquoteId.values());
    //    system.debug('Map Values:'+MapIsoCode.values());
        return acvList;
    }
    
    global void execute(Database.BatchableContext BC, List<Annual_Contract_Value__c> scope) {
     //   CurrencyUtil.updateExchangeRatesMap();
        CurrencyUtil.updateConversionRatesMap();
        List<Annual_Contract_Value__c> updateACVList = new List<Annual_Contract_Value__c>();
        Decimal CUDER = 0.0;
        Integer currentFY;
        Date fiscalYrStartDate = Date.newInstance(Date.today().year(), 11, 1);
        System.debug('MapCloseDate size: ' + MapCloseDate.size());
        
        if(Date.today() > fiscalYrStartDate)
            currentFY=Date.today().year();
        else
            currentFY=Date.today().year() - 1;
        
        For(Annual_Contract_Value__c acvqList:scope){
            System.debug('Close date year: ' + MapCloseDate.get(acvqList.Quote__c));
            System.debug('Quote currency: ' + MapIsoCode.get(acvqList.Quote__c));
            System.debug('ACV record id: ' + acvqList.Id);
            
            if(CurrencyUtil.yearExchngRateMap.containsKey(MapCloseDate.get(acvqList.Quote__c)) == TRUE &&
               CurrencyUtil.yearExchngRateMap.get(MapCloseDate.get(acvqList.Quote__c)).containsKey(MapIsoCode.get(acvqList.Quote__c)) == TRUE)
            	CUDER = CurrencyUtil.yearExchngRateMap.get(MapCloseDate.get(acvqList.Quote__c))
                                                  .get(MapIsoCode.get(acvqList.Quote__c));
            else
                CUDER = NULL;
            
            if(CUDER == NULL && MapCloseDate.get(acvqList.Quote__c) >= currentFY)
                CUDER = CurrencyUtil.yearExchngRateMap.get(currentFY)
                                                  .get(MapIsoCode.get(acvqList.Quote__c));
            
            system.debug('CUDER from CurrencyUtil map: ' + CUDER);
            
            if(CUDER != NULL){
            	if(acvqList.Dated_Exchange_Rate__c != CUDER || acvqList.Dated_Exchange_Rate__c == NULL){
                	system.debug(acvqList);
                    acvqList.Dated_Exchange_Rate__c = CUDER; 
                    acvqList.Batch_Error__c = false;
                    acvqList.Batch_Job_runtime__c = DateTime.now();
                    updateACVList.add(acvqList);
                }
            }
            Else{
                if(acvqList.ACV_Currency__c == 'USD'){
                    system.debug(acvqList);
                    acvqList.Dated_Exchange_Rate__c = 1.0;
                    acvqList.Batch_Error__c = false;
                    acvqList.Batch_Job_runtime__c = DateTime.now();
                    updateACVList.add(acvqList);
                }
                else{                    
                    acvqList.Batch_Error__c = true;
                    acvqList.Batch_Job_runtime__c = DateTime.now();
                    updateACVList.add(acvqList);
                }
            }
        }
        
        if(updateACVList.size() > 0){
            Try{
                system.debug('updateACVList'+updateACVList);
                Update updateACVList;
            }Catch(DMLException DMLEx){
                System.debug('Exception While Updating ACV records.'+DMLEx);
            }
        }        
    }
    
    global void finish(Database.BatchableContext BC) {     
        
    }
}

Debug log
Hi all,
A very strange issue is happening in the below apex code. I have return a batch job (Batch_Annual_Contract_Value_DER) to update Annual contract Value records with the latest Dated Exchange rates based on the Opportunity close date. The other class CurrencyUtil creates a yearExchngRateMap (Map<Integer, Map<String, Decimal>>) which holds the year as the key and another map with IsoCode as key and the Dated Exchange rate for that year as value. In the CurrencyUtil class when the getPrevYearCurrencyRate method is called from the Else at line 115 the values in the map yearExchngRateMap get overriden. I spent a lot of time on this but am not able to figure out why is this happening. Can anyone take a look at the code and see if they can figure out something.
public without sharing class CurrencyUtil {

    public static Map<String, Decimal> currencyExchangeRateMap = new Map<String, Decimal>();

    // Map that holds the Exchange Rates by Year
    Public static Map<Integer, Map<String, Decimal>> yearExchngRateMap = new Map<Integer, Map<String, Decimal>>();
    private static String CurrencyTypes = Label.Currency_Types;
    private static String[] currencies = CurrencyTypes.split(',');

    public static Decimal convertToOrgDefaultCurrency(Decimal amount, String isoCode) {
        Decimal convertedAmount = 0.0;
        if(amount != null && isoCode != null && !isoCode.equals('')) {
                convertedAmount = amount / currencyExchangeRateMap.get(isoCode);
        }
        return convertedAmount;
    }
    
    public static Decimal convertToOrgDefaultCurrency(Decimal amount, String isoCode, Integer fiscalYear) {
        Decimal convertedAmount = 0.0;
        if(amount != null && isoCode != null && !isoCode.equals('')) {
            convertedAmount = amount / yearExchngRateMap.get(fiscalYear).get(isoCode);
        }
        return convertedAmount;
    }

    public static void updateExchangeRatesMap() {
        currencyExchangeRateMap.clear();
        currencyExchangeRateMap.put('USD', 1.000000);
        List<DatedConversionRate> dtdExchngRates = [Select Id, ConversionRate, IsoCode, NextStartDate, StartDate 
                                                from DatedConversionRate
                                                where startdate = THIS_FISCAL_YEAR
                                                order by startdate desc];
        System.debug('dtdExchngRates : '+dtdExchngRates);
        for(DatedConversionRate dtdER : dtdExchngRates) {
            if(!currencyExchangeRateMap.containsKey(dtdER.IsoCode)) {
              currencyExchangeRateMap.put(dtdER.IsoCode, dtdER.ConversionRate);
            }
        }
        System.debug('currencyExchangeRateMap : '+currencyExchangeRateMap);
    }

    public static void updateConversionRatesMap() {
        System.debug('currencies : '+currencies);
        yearExchngRateMap.clear();
        String dteFormat = '-11-01';
        Integer lstFiveYr = System.today().Year() - 5;
        Date fiveYrAgo = Date.valueOf(String.valueOf(lstFiveYr) + dteFormat);
        System.debug('fiveYrAgo : '+fiveYrAgo);
        
        List<DatedConversionRate> dtdExchngRates = [SELECT Id, ConversionRate, IsoCode, NextStartDate, StartDate 
                                                      FROM DatedConversionRate
                                                     WHERE StartDate >=: fiveYrAgo
                                                    ORDER BY Startdate asc];
        System.debug('dtdExchngRates : '+dtdExchngRates);
        
        // Build the DatedConversionRateMap for the past five years - From DatedConversionRate Object
        if(!dtdExchngRates.isEmpty()) {
            Integer dcrYear = null;
            Map<String, Decimal> currRateMap = null;
            for(DatedConversionRate dcr : dtdExchngRates) {
                dcrYear = dcr.StartDate.Year();
                if(yearExchngRateMap != null && !yearExchngRateMap.containsKey(dcrYear)) {
                    yearExchngRateMap.put(dcrYear, new Map<String, Decimal> {'USD' => 1.000000});
                }
                if(yearExchngRateMap != null && yearExchngRateMap.containsKey(dcrYear)) {
                    currRateMap = yearExchngRateMap.get(dcrYear);
                    if(currRateMap != null && !currRateMap.containsKey(dcr.IsoCode)) {
                        currRateMap.put(dcr.IsoCode, null);
                        yearExchngRateMap.put(dcrYear, currRateMap);
                    }
                    if(currRateMap != null && currRateMap.containsKey(dcr.IsoCode)) {
                        currRateMap.put(dcr.IsoCode, dcr.ConversionRate);
                        yearExchngRateMap.put(dcrYear, currRateMap);
                    }
                }
            }
        }
        System.debug('yearExchngRateMap : '+yearExchngRateMap);
        
        /* Verify whether all the Currency Types are present for all the years, 
           If not add the missed out CurrencyRate from the Previous Fiscal Year
        */
        Decimal exchngRate = null;
        Map<String, Decimal> currencyRateMap = new Map<String, Decimal>();
        Date fiscalYrStartDate = Date.newInstance(Date.today().year(), 11, 1);
        Integer fiscalYear;
        if(yearExchngRateMap != null && !yearExchngRateMap.isEmpty()) {
        //    for(Integer fiscalYear : yearExchngRateMap.keyset()) {
            System.debug('Currencies: ' + currencies);
			if(Date.today() < fiscalYrStartDate)            
                fiscalYear = Date.today().year() - 1;
            else
                fiscalYear = Date.today().year();
            
            for(Integer iteration = 0; iteration<5; iteration++){
                System.debug('Inside iteration loop, iteration# ' + iteration);
                System.debug('Currency List size: ' + currencies.size());
                System.debug('fiscalYear: ' + fiscalYear);
                if(yearExchngRateMap.containsKey(fiscalYear)){
                	currencyRateMap = yearExchngRateMap.get(fiscalYear);   
                    System.debug('Currency Rate Map found for FY ' + fiscalYear);
                    System.debug('Currency Rate Map: (in IF) ' + currencyRateMap);
                    for(String curr : currencies) {
                        if(!currencyRateMap.containsKey(curr)) {
                    //      exchngRate = getPrevYearCurrencyRate(fiscalYear, curr, fiveYrAgo.year()-1);
                    		exchngRate = getPrevYearCurrencyRate(fiscalYear, curr);
                            System.debug('Currency (in IF): ' + curr);
                            System.debug('Exchange Rate (in IF): ' + exchngRate);
                            currencyRateMap.put(curr, exchngRate);
                        }
                    }
				 	yearExchngRateMap.put(fiscalYear, currencyRateMap);
                    System.debug('yearExchngRateMap (in IF): ' + yearExchngRateMap);
                }
                else{
					//currencyRateMap.clear();
                    System.debug('Currency Rate Map: (before) ' + currencyRateMap);
                    System.debug('yearExchngRateMap (before in ELSE): ' + yearExchngRateMap);
                    for(Integer key: yearExchngRateMap.keySet()){
            			System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        			}
                    for(String curr : currencies) {
                    //  exchngRate = getPrevYearCurrencyRate(fiscalYear, curr, fiveYrAgo.year()-1);
                        exchngRate = getPrevYearCurrencyRate(fiscalYear, curr);
                        System.debug('Currency: (in ELSE)' + curr);
                        System.debug('Exchange Rate: (in ELSE)' + exchngRate);
                        currencyRateMap.put(curr, exchngRate);
                    }
                    System.debug('Currency Rate Map: (after) ' + currencyRateMap );
                    System.debug('Fiscal Year: ' + fiscalYear);
                    yearExchngRateMap.put(fiscalYear, currencyRateMap);
                    System.debug('yearExchngRateMap (after in ELSE): ' + yearExchngRateMap);
                    for(Integer key: yearExchngRateMap.keySet()){
            			System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        			}
                }
                fiscalYear = fiscalYear - 1;
            }
        }
        System.debug('yearExchngRateMap : After Verification Logic : '+ yearExchngRateMap);
        //Display yearExchangRateMap
        for(Integer key: yearExchngRateMap.keySet()){
            System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        }
    }
                       
//  private static Decimal getPrevYearCurrencyRate(Integer fYear, String currencyIso, Integer fiveYrAgoYear) {
	private static Decimal getPrevYearCurrencyRate(Integer fYear, String currencyIso) {
		Decimal convRate;
        Integer prevFiscalYear = fYear - 1;
        //if(prevFiscalYear > fiveYrAgoYear){
        //
        	System.debug('yearExchngRateMap (in getPrevYearCurrencyRate): ' + yearExchngRateMap);
        	for(Integer key: yearExchngRateMap.keySet())
            	System.debug('yearExchngRateMap(' + key + ')' + yearExchngRateMap.get(key));
        //
            Map<String, Decimal> prevCurrRateMap = yearExchngRateMap.get(prevFiscalYear);
            convRate = null;
            System.debug('In getPrevYearCurrencyRate');
            if(prevCurrRateMap != null && prevCurrRateMap.containsKey(currencyIso)) {
                if(prevCurrRateMap.get(currencyIso) != null) {
                    convRate = prevCurrRateMap.get(currencyIso);
                } else {
                  //convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso, fiveYrAgoYear);
                    convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso);
                }
            }
            else{
                //convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso, fiveYrAgoYear);
                convRate = getPrevYearCurrencyRate(prevFiscalYear, currencyIso);
            }
        /*}
        else{
            convRate = null;
        }*/
        return convRate;
    }
}
 
global class Batch_Annual_Contract_Value_DER implements Database.Batchable<sObject>, Database.Stateful {
    Map<Id,Annual_Contract_Value__c> MapquoteId = new Map<ID,Annual_Contract_Value__c>();
    Map<Id,String> MapIsoCode = new Map<ID,String>();
    Map<Id,Integer> MapCloseDate = new Map<ID,Integer>();
    final String[] oppStageToAvoid = new String[] {'Declined to Quote', 'Legacy'};  
    final String[] oppOpenStage = new String[] {'Fact Finding', 'Covering the Bases', 'Negotiating', 'Closing'};
    final String[] oppClosedStage = new String[] {'Closed/Lost', 'Closed/Won'};
        
    global List<Annual_Contract_Value__c> start(Database.BatchableContext BC) {     
        List<Annual_Contract_Value__c> acvList = [SELECT Id,Quote__r.Id,Dated_Exchange_Rate__c,Fiscal_Year__c,Quote__c,Expected_Revenue__c,Quote__r.CurrencyIsoCode,Opportunity_Stage__c,Opportunity_Close_Date__c, Batch_Error__c, Batch_Job_runtime__c, ACV_Currency__c
                                                    FROM Annual_Contract_Value__c
                                                   WHERE Opportunity_Stage__c !=: oppStageToAvoid
                                                     AND (Opportunity_Stage__c IN :oppOpenStage 
                                                         OR
                                                         (Opportunity_Stage__c IN :oppClosedStage
                                                          AND Opportunity_Last_Modified_Date__c = LAST_N_DAYS:31))
                                                  ORDER BY Id, Quote__c];        
        system.debug('acvList:'+acvList);
        system.debug('acvList size: ' + acvList.size());
        
        if(acvList.size() > 0){
            For(Annual_Contract_Value__c acvInstance:acvList){
                MapquoteId.put(acvInstance.Quote__c,acvInstance);
            }
        }
        
        List<Quote> qList = [select Id,CurrencyIsoCode,Opportunity.CloseDate from Quote where Id IN: MapquoteId.keyset()];        
        System.debug('qList size: ' + qList.size());
        if(qList.size() > 0){
            For(Quote qInstance:qList){
                MapIsoCode.put(qInstance.Id,qInstance.CurrencyIsoCode);
                Date fiscalYrStartDate = Date.newInstance(qInstance.Opportunity.CloseDate.year(), 11, 1);
                System.debug('Quote Id: ' + qInstance.Id);
                System.debug('fiscalYrStartDate: ' + fiscalYrStartDate);
                If(qInstance.Opportunity.CloseDate < fiscalYrStartDate)
                    MapCloseDate.put(qInstance.Id,qInstance.Opportunity.CloseDate.year() - 1);
                Else
                    MapCloseDate.put(qInstance.Id,qInstance.Opportunity.CloseDate.year());
            }
        }        
    //    system.debug('Map1Values:'+MapquoteId.values());
    //    system.debug('Map Values:'+MapIsoCode.values());
        return acvList;
    }
    
    global void execute(Database.BatchableContext BC, List<Annual_Contract_Value__c> scope) {
     //   CurrencyUtil.updateExchangeRatesMap();
        CurrencyUtil.updateConversionRatesMap();
        List<Annual_Contract_Value__c> updateACVList = new List<Annual_Contract_Value__c>();
        Decimal CUDER = 0.0;
        Integer currentFY;
        Date fiscalYrStartDate = Date.newInstance(Date.today().year(), 11, 1);
        System.debug('MapCloseDate size: ' + MapCloseDate.size());
        
        if(Date.today() > fiscalYrStartDate)
            currentFY=Date.today().year();
        else
            currentFY=Date.today().year() - 1;
        
        For(Annual_Contract_Value__c acvqList:scope){
            System.debug('Close date year: ' + MapCloseDate.get(acvqList.Quote__c));
            System.debug('Quote currency: ' + MapIsoCode.get(acvqList.Quote__c));
            System.debug('ACV record id: ' + acvqList.Id);
            
            if(CurrencyUtil.yearExchngRateMap.containsKey(MapCloseDate.get(acvqList.Quote__c)) == TRUE &&
               CurrencyUtil.yearExchngRateMap.get(MapCloseDate.get(acvqList.Quote__c)).containsKey(MapIsoCode.get(acvqList.Quote__c)) == TRUE)
            	CUDER = CurrencyUtil.yearExchngRateMap.get(MapCloseDate.get(acvqList.Quote__c))
                                                  .get(MapIsoCode.get(acvqList.Quote__c));
            else
                CUDER = NULL;
            
            if(CUDER == NULL && MapCloseDate.get(acvqList.Quote__c) >= currentFY)
                CUDER = CurrencyUtil.yearExchngRateMap.get(currentFY)
                                                  .get(MapIsoCode.get(acvqList.Quote__c));
            
            system.debug('CUDER from CurrencyUtil map: ' + CUDER);
            
            if(CUDER != NULL){
            	if(acvqList.Dated_Exchange_Rate__c != CUDER || acvqList.Dated_Exchange_Rate__c == NULL){
                	system.debug(acvqList);
                    acvqList.Dated_Exchange_Rate__c = CUDER; 
                    acvqList.Batch_Error__c = false;
                    acvqList.Batch_Job_runtime__c = DateTime.now();
                    updateACVList.add(acvqList);
                }
            }
            Else{
                if(acvqList.ACV_Currency__c == 'USD'){
                    system.debug(acvqList);
                    acvqList.Dated_Exchange_Rate__c = 1.0;
                    acvqList.Batch_Error__c = false;
                    acvqList.Batch_Job_runtime__c = DateTime.now();
                    updateACVList.add(acvqList);
                }
                else{                    
                    acvqList.Batch_Error__c = true;
                    acvqList.Batch_Job_runtime__c = DateTime.now();
                    updateACVList.add(acvqList);
                }
            }
        }
        
        if(updateACVList.size() > 0){
            Try{
                system.debug('updateACVList'+updateACVList);
                Update updateACVList;
            }Catch(DMLException DMLEx){
                System.debug('Exception While Updating ACV records.'+DMLEx);
            }
        }        
    }
    
    global void finish(Database.BatchableContext BC) {     
        
    }
}

Debug log

Thanks,
Jay
I am facing issues coming up with a SOQL query. We have a custom object 'Quote History' which has master detail relationship to Quote object. The Quote History object  store the field modified timestamp, field old value and field new value for some of the fields on the Quote object. 
User-added image

I want to write SOQL query that can give me the max(field modified timestamp), the most recent update made to the field] as well as the new value for a particular field for each Quote and Proposal number combination.
I have a written a trigger on Quote object which i am trying to test using a test class. I am using a static variable m_IsExecuting to make the trigger non-recursive; after the trigger runs the first time in a trasaction the static variable will be set to true so that the trigger won't run again in the same transaction. This is working fine when i test it using the SFDC user interface however it is causing a problem in my test class. I have written a @setup method in my test class where i am creating a Quote record which i am using in my testmethod. In my testmethod i have to update the quote record multiple time but after i perform the first update the static variable will be set to true and the trigger won't run for the subsequent updates. Is there any way where i can perform the update on the quote record in separate transactions in the same test method? 

trigger QuoteTracking on Quote (after insert, after update) {
    
    final string logTag = '[QuoteTracking]';
    List<Quote> newQTA = new List<Quote>();
    List<Quote> trackList = new List<Quote>();
    List<QTA__c> qtaUpdateList = new List<QTA__c>();
    Map<Id, QTA__c> recentQTAMap = new Map<Id,QTA__c>();
   
    if(QuoteTrackingHelper.getIsExecuting()){
        system.debug(logTag +'Currently executing. Exiting.');
        return;
    } 
    QuoteTrackingHelper.setIsExecuting(); 

   
While trying to compile the following test class I am getting a compilatio error Compilation error: Expecting a colon, found ',' at this particular line in the code 

ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc);

Can anyone help me to get rid of this.
 
@isTest(seeAllData=true)
private class TestLeadContactFeedTrigger {

    static testmethod void initTest(){
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
         
        User u = new User(Alias = 'TLCFT', 
                          Email='TLCFTest@test.com', 
                          EmailEncodingKey='UTF-8', 
                          LastName='Testing', 
                          LanguageLocaleKey='en_US', 
                          LocaleSidKey='en_US', 
                          ProfileId = p.Id, 
                          TimeZoneSidKey='America/Los_Angeles',
                          UserName='TLCFTest@test.com');
        insert u;
        System.debug('User created: ' + u.Id);
                          
        Lead TestLead1 = new Lead(FirstName = 'Test',
                                  LastName = 'Lead1',
                                  Company = 'Test Comp1',
                                  Status ='Working-Contacted',
                                  Email ='test.lead1@test.com',
                                  OwnerId = u.Id,
//                                OwnerId = '005K0000002N5GT',
                                  Lead_Info__c = 'This is the Lead Info for a test lead John Doe1');
        insert TestLead1;
        
        ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc);
                
         System.assertEquals('This is the Lead Info for a test lead John Doe1', TestLead1.Lead_Info__c);
    }
}


 
Hi all,
I have written the following query in Opportunity Territory Assignment Apex Class. This query is not returning any result in the code. I tried execuring the query in Workbench but it is not returning any records.
SELECT Id, ObjectID, Territory2Id, Territory2.Territory2Type.MasterLabel, Territory2.ParentTerritory2Id FROM ObjectTerritory2Association WHERE SObjectType = 'Account' AND Territory2.Territory2ModelId = :activeModelId
However if I remove the condition SObjectType = 'Account' from the query and run it, it returns records. Any idea why the query is not working with the condition SObjectType = 'Account'

User-added image

 
Hi all,
I am trying to display a help text box on the flow screen using DIV attribute in the text template.
<div style="width:500px;height:20px;border:1px solid #ff8000;background-color:#ffffb3;font-family:arial;font-size:80%">This is the phase we are quoting proposal for</div>
When i run the HTML code in an editor it works fine.
User-added image

But when i use the same HTML in the text template in a 'Display text' element on Flow screen it doesn't display the orange border. Can anyone identify the issue here.
User-added image
While trying to compile the following test class I am getting a compilatio error Compilation error: Expecting a colon, found ',' at this particular line in the code 

ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc);

Can anyone help me to get rid of this.
 
@isTest(seeAllData=true)
private class TestLeadContactFeedTrigger {

    static testmethod void initTest(){
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
         
        User u = new User(Alias = 'TLCFT', 
                          Email='TLCFTest@test.com', 
                          EmailEncodingKey='UTF-8', 
                          LastName='Testing', 
                          LanguageLocaleKey='en_US', 
                          LocaleSidKey='en_US', 
                          ProfileId = p.Id, 
                          TimeZoneSidKey='America/Los_Angeles',
                          UserName='TLCFTest@test.com');
        insert u;
        System.debug('User created: ' + u.Id);
                          
        Lead TestLead1 = new Lead(FirstName = 'Test',
                                  LastName = 'Lead1',
                                  Company = 'Test Comp1',
                                  Status ='Working-Contacted',
                                  Email ='test.lead1@test.com',
                                  OwnerId = u.Id,
//                                OwnerId = '005K0000002N5GT',
                                  Lead_Info__c = 'This is the Lead Info for a test lead John Doe1');
        insert TestLead1;
        
        ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc);
                
         System.assertEquals('This is the Lead Info for a test lead John Doe1', TestLead1.Lead_Info__c);
    }
}