• kris chit
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 6
    Replies
Hi,

I am sending an email notification if a field is changed on Content Version object through Apex as we cannot create Workflows/processbuilder on Contentversion object. In my Apex code, I am referring to a email template which I created for this purpose.  In the body of email I am trying to include few ContentVersion fields, but there is no option to select merge fields for Content Version object. 

Is there a way I can use ContentVersion fields in my email template ?
Hi,
I am stuck at Step 3 of Advanced Apex Specialist. Below is my code.  I am adding below 3 code samples. I have tried overcoming this multiple this but without any results. Please guide me.
 
public  class Product2Extension {
    public List<ProductWrapper> productsToInsert {get;set;}
    public Product2Extension(ApexPages.StandardController controller){
        productsToInsert = new List<ProductWrapper>();
        addRows();
    }

    public void AddRows(){
        for ( Integer i=0; i<Constants.DEFAULT_ROWS; i++ ){
            ProductWrapper prodWrapper = new ProductWrapper();
            productsToInsert.add( prodWrapper );
        }
    }
    public List<ChartHelper.ChartData> GetInventory(){
        return ChartHelper.GetInventory();
    }

    public PageReference Save(){
        SavePoint sp1 = Database.setSavepoint();
        try {
            Map<Integer, Product2> products = new Map<Integer, Product2>();
			Map<Integer, PriceBookEntry> priceBookEntries = new Map<Integer, PriceBookEntry>();    
            Integer index = 0;
            for(ProductWrapper prdWrapper : productsToInsert) {
                if(String.isNotBlank(prdWrapper.productRecord.Name) && prdWrapper.pricebookEntryRecord.UnitPrice!=null && 
                   prdWrapper.productRecord.Initial_Inventory__c!=null && prdWrapper.productRecord.isActive && 
                   prdWrapper.productRecord.Initial_Inventory__c != 0 && prdWrapper.pricebookEntryRecord.UnitPrice!=0){
                          
                	products.put(index,prdWrapper.productRecord);
                    priceBookEntries.put(index,prdWrapper.pricebookEntryRecord);
                    index ++;
                }
            }
            
            insert products.values();
            
            List<PriceBookEntry> pbList = new List<PriceBookEntry>();
            for(Integer mapIndex : products.keySet()) {
            	PriceBookEntry currentPBEntry = priceBookEntries.get(mapIndex);
                if(products.get(mapIndex).Id!=null) {
                    currentPBEntry.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
                	System.debug('' + products.get(mapIndex).Id);
                	currentPBEntry.Product2Id = products.get(mapIndex).Id;
                	currentPBEntry.IsActive = true;
                    pbList.add(currentPBEntry);
                }
                
            }
            
            insert pbList;

            //If successful clear the list and display an informational message
            apexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,pbList.size()+' Inserted'));
            productsToInsert.clear();   //Do not remove
            addRows();  //Do not remove
        } catch (Exception e){
			apexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,Constants.ERROR_MESSAGE));
            Database.rollback(sp1);
        }
        return null;
    }
    
    public List<SelectOption> GetFamilyOptions(){
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption(Constants.SELECT_ONE,Constants.SELECT_ONE));
        for(Schema.PicklistEntry entry : Constants.PRODUCT_FAMILY){
			options.add(new SelectOption(entry.getLabel(),entry.getValue()));
        }
		return options;
    }
    
    
    public class ProductWrapper{
        public Product2 productRecord {get;set;}
        public PriceBookEntry pricebookEntryRecord {get;set;}
        
        public ProductWrapper() {
            productRecord = new Product2(Initial_Inventory__c =0);
            pricebookEntryRecord = new PricebookEntry(Unitprice=0.0);
        }
    }

}
public without sharing class ChartHelper {

  @AuraEnabled
  public static List<chartData> GetInventory(){
    List<chartData> cht = new List<chartData>();

    for(AggregateResult ar : [SELECT Family, SUM(Quantity_Remaining__c) FROM Product2 WHERE Quantity_Remaining__c > 0 AND IsActive = true GROUP BY Family]) {
      cht.add(new ChartData(String.ValueOf(ar.get('Family')), Integer.ValueOf(ar.get('expr0'))));
    }

    return cht;
  }


  public class ChartData {
    public String name {get; set;}
    public Decimal val {get; set;}

    public ChartData(String name, Decimal val){
      this.name = name;
      this.val = val;
    }
  }

}
<apex:page standardController="Product2" extensions="Product2Extension" >
    <apex:sectionHeader title="New Product" subtitle="Add Inventory" />
    <apex:pageMessages id="pageMessages" />
    <apex:form id="form" >
        <apex:actionRegion >
            <apex:pageBlock title="Existing Inventory" id="chart-section">
                <apex:chart height="350" width="450" data="{!inventory}">
                    <apex:axis type="Numeric" position="bottom" title="Quantity Remaining" grid="true"
                               fields="val" dashSize="2">
                        <apex:chartLabel />
                    </apex:axis>
                    <apex:axis type="Category" position="left" fields="name" title="Product Family">
                        <apex:chartLabel rotate="315"/>
                    </apex:axis>
                    <apex:barSeries orientation="horizontal" axis="left" 
                                    xField="val" yField="name"/>
                    <apex:legend position="right"/>
                </apex:chart>
            </apex:pageBlock>
            <apex:pageBlock title="New Products" >
                <apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!save}" value="Save" reRender="chart-section"/>
                </apex:pageBlockButtons>
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton action="{!addRows}" value="Add" reRender="pageMessages,orderItemTable"/>
                </apex:pageBlockButtons>
                
                <apex:pageBlockTable value="{!productsToInsert}" var="p" id="orderItemTable" >
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}" >
                        <apex:inputText value="{!p.productRecord.Name}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}" >
                        <apex:selectList value="{!p.productRecord.Family}" size="1" multiselect="false" >
                            <apex:selectOptions value="{!FamilyOptions}"/>
                        </apex:selectList>
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.isActive.Label}" >
                        <apex:inputField value="{!p.productRecord.isActive}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.PriceBookEntry.Fields.UnitPrice.Label}" >
                        <apex:inputText value="{!p.pricebookEntryRecord.UnitPrice}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Initial_Inventory__c.Label}" >
                        <apex:inputField value="{!p.productRecord.Initial_Inventory__c}" />
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:actionRegion>
    </apex:form>
</apex:page>



 
Hi All,

I am trying to implement User Provisioning for a Community User. Upon clicking of Submit button, a new Contact and User is created and it should land user on Community home page. But I am seeing Mixed DML Error as I am trying to update a Setup object after updating a non-setup object.

So I tried to make the User Creation into a future call. But the problem is as it is a asynchronous call, it takes time and by that time if it is trying to login and land him on Community Home page, it is throwing error.

So I am planning to make the user creation in the synchronous transaction and create a contact in async call. Just wanted to know are there any limitations in doing that ??

Appreciate your response.
Hi,

I am trying to create a validation rule where  "Frequency" picklist field should be made required when user enters any value in "Min Rate" and "Max Rate" currency fields.  Could someone  please guide me.

 
Hi,

I am trying to use values of formula fields to perform some logic in my before trigger. Would the formula fields be available for me in before trigger ?

Thanks
Hi,

We have been using "PageReference" method in controller to re-direct url's in Classic, Salesforce 1 and Lighnting. But Salesforce no longer supports "PageReference" for Salesforce 1 and Lighting. So which method or how do I re-direct URL's in Salesforce 1 and Lightningt ?

Please guide me.

Thanks

 
Hi,

I am trying to run a test class on via Apex Test Execution ans am seeing the below error. Do not know the reason behind it. Could someone help me on how to resolve it.  Thanks


User-added image
Hi,

There is a linkedin url field on Contact. I want to write a validation rule to allow only url's that starts with "https://www.linkedin.com". So when a user enters any junk like data like "facebook.com", it should throw a validation rule.

Please guide me.
Hi,

I have 2 linkedin url's, one on Account(Company Search) and another on Contact(People Search URL). But for some reason both the url's seem to be not working and when I click on it the linkedin page is loading continuously.

Account with name 'Wells Fargo":
Account with name Wells Fargo

Contact with name "test" "

Contact with name "test"

Please guide me on what Linkedin URL's to use for both Account(Company Search) and  Contact(People Search URL). Thanks
 
Hi,

There is a field called "Display_LastModifiedDate" on Orders. I am trying to retrieve orders with "Display_LastModifiedDate" between 175th -185th days back from today dynamically. I cannot hardcode 175th and 185th dates because if I query it after a week the 175th and 185th dates change. Please guide me.

Thanks
Hi,

I am trying to use values of formula fields to perform some logic in my before trigger. Would the formula fields be available for me in before trigger ?

Thanks
Hi,

I am trying to create a validation rule where  "Frequency" picklist field should be made required when user enters any value in "Min Rate" and "Max Rate" currency fields.  Could someone  please guide me.

 
Hi,

There is a field called "Display_LastModifiedDate" on Orders. I am trying to retrieve orders with "Display_LastModifiedDate" between 175th -185th days back from today dynamically. I cannot hardcode 175th and 185th dates because if I query it after a week the 175th and 185th dates change. Please guide me.

Thanks