• Ashish Takke
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 7
    Replies
We want to implement "Snap-ins chat" in Lightning service console. Please help or suggest required steps.

As an initial set up, we have created snap-ins deployment, mapped Live agent settings and copied "Snap-in code snippets" in VF page. But when we are opening VF page as preview, we are getting below error in Chrome browser console. We have added SF HTTPS domain url in CORS as well. How to resolve this error?

Error message:
Access to Font at 'https://a.sfdcstatic.com/content/dam/www/ocms-backup/system/shared/common/assets/fonts/SalesforceSans/SalesforceSans-Regular.ttf' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404.

 
We have implemented Live agent chat button in Lightning service console utility bar by embedding VF page (having button html code) as iFrame into Lightning component. And this functionality working fine in SF web application. But when we are trying to click 'Live Agent Chat' button from salesforce1 mobile, it is not popping up pre-chat form. Is there anyone who have implemented Live agent chat for Salesforce1 mobile app?
We want to implement "Snap-ins chat" in Lightning service console. Please help or suggest required steps.

As an initial set up, we have created snap-ins deployment, mapped Live agent settings and copied "Snap-in code snippets" in VF page. But when we are opening VF page as preview, we are getting below error in Chrome browser console. We have added SF HTTPS domain url in CORS as well. How to resolve this error?

Error message:
Access to Font at 'https://a.sfdcstatic.com/content/dam/www/ocms-backup/system/shared/common/assets/fonts/SalesforceSans/SalesforceSans-Regular.ttf' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404.

 
We have implemented Live agent chat button in Lightning service console utility bar by embedding VF page (having button html code) as iFrame into Lightning component. And this functionality working fine in SF web application. But when we are trying to click 'Live Agent Chat' button from salesforce1 mobile, it is not popping up pre-chat form. Is there anyone who have implemented Live agent chat for Salesforce1 mobile app?
I have developed code to over come limitation of print option for list view.
VF Page
<apex:page sidebar="false" standardStylesheets="false" cache="false" standardController="Account" recordSetVar="accounts" lightningStylesheets="true">
    <button id="upload-button" onclick="window.print();" style="margin-left: 50%;" Class="slds-button">Print</button>
    <apex:includeLightning />
    <div id="lightning" ></div> 
    <script>
        $Lightning.use("c:ListView", function() {
          $Lightning.createComponent("c:ListViewComponent",
          { label : "" },
          "lightning",
          function(cmp) {
             
          });
        });
    </script>
</apex:page>


Controller class
public with sharing class ListViewController {
    
    // Method to get all list view option available for the Account object 
    @AuraEnabled
    public static List<SelectOption> getListViews(){
        SelectOption  lstView=new SelectOption ('--None--','--None--');
        List<SelectOption> listviews = new List<SelectOption>();
        listviews.add(lstView);
        for(ListView lstObj : [SELECT Id, Name FROM ListView WHERE SobjectType = 'Account' order by name ASC]){
            listviews.add(new SelectOption (lstObj.id,lstObj.name));
        }
        return listviews; 
    }
    // Method to get the Account records based on the selected list view
    @AuraEnabled  
    public static DynamicTableMapping getFilteredAccounts(String filterId){
        list<string> headervalue =new list<string>();
        HttpRequest req = new HttpRequest();
        String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
        String endPoinURL = baseUrl+'/services/data/v32.0/sobjects/Account/listviews/'+filterId+'/describe';
        req.setEndpoint(endPoinURL);
        req.setMethod('GET');
        req.setHeader('Authorization',  'Bearer ' + UserInfo.getSessionId());
        Http http = new Http();
        HTTPResponse response = http.send(req);
        Map<String, Object> tokenResponse = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
        String query = (String) tokenResponse.get('query');
        system.debug('query--->'+query);
       for(string s:query.split(',')){
            s=s.trim();    
            if(s.startsWith('SELECT')){
                headervalue.add((s.removeStart('SELECT')).trim());        
            }else if(!s.startsWith('SYSTEMMODSTAMP') && !s.equalsIgnoreCase('SYSTEMMODSTAMP FROM ACCOUNT ORDER BY NAME ASC NULLS FIRST') && !s.contains('ASC')){
                headervalue.add(s.trim());
            }
        }
        
        List<ObjectValueMap> AccountList = new List<ObjectValueMap>();
        
        for(Account accountObj : database.query(query)){
            
            Map<String, Schema.SObjectField> objectFields = Account.getSObjectType().getDescribe().fields.getMap();
            list<FieldValues> fieldValue=new list<FieldValues>();
            for(string s:headervalue){
                Schema.DescribeFieldResult dr;
                if (objectFields.containsKey(s)) 
                      dr = objectFields.get(s).getDescribe();
                if(null!=dr)
                    fieldValue.add(new FieldValues(string.valueof(null==accountObj.get(dr.getName())?'':accountObj.get(dr.getName()))));            
                else
                    fieldValue.add(new FieldValues(string.valueof('')));
            }
            AccountList.add(new ObjectValueMap(accountObj,fieldValue));
        }
        
        return new DynamicTableMapping(headervalue,AccountList);        
    }
      
}



Lightning component
<aura:component controller="ListViewController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="AccountListViewList" type="SelectOption[]"/>
    <aura:attribute name="AccountList" type="DynamicTableMapping"/>
    <aura:attribute name="fieldList" type="string[]"/>
    <ui:inputSelect class="slds-select slds-size_small" aura:id="selectedViewId" label="Account View" change="{!c.getFilteredAccount}">
        <aura:iteration items="{!v.AccountListViewList}" var="listview">
            <ui:inputSelectOption text="{!listview.value}" label="{!listview.label}"/>
        </aura:iteration>
    </ui:inputSelect>
   
    <br/><br/>
    
    <table class="slds-table slds-table_bordered slds-table_cell-buffer">
        <thead>
            <tr class="slds-text-title_caps">
                <aura:iteration items="{!v.fieldList}" var="item">
                    <th scope="col">
                        <div class="slds-truncate" title="{!item}">{!item}</div>
                    </th>
                </aura:iteration>
            </tr>
        </thead>
        <tbody>
        <aura:iteration items="{!v.AccountList}" var="item" indexVar="index">
        <tr>
       
            <aura:iteration items="{!item.values}" var="item1">
                <td>
                     {!item1.value}   
                </td></aura:iteration>
        </tr>
        </aura:iteration>
        </tbody>
    </table>
</aura:component>


Component controller JS
({
    doInit : function(component, event, helper){
        var action = component.get("c.getListViews");
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.AccountListViewList",response.getReturnValue());
            }
        });
       
        $A.enqueueAction(action);
    },
    getFilteredAccount : function (component, event, helper) {
        var selected = component.find("selectedViewId").get("v.value");
        var action = component.get("c.getFilteredAccounts");
        action.setParams({filterId : selected});
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.AccountList",response.getReturnValue().value);
                component.set("v.fieldList",response.getReturnValue().headervalues);
            }
        });
        
        $A.enqueueAction(action); 
    },
    
})


Helper classes
public class DynamicTableMapping {
    
    @AuraEnabled
    public list<string> headervalues{get;set;}
    @AuraEnabled 
    public list<ObjectValueMap> value{get;set;}
    
    public DynamicTableMapping(list<string> headervalues,list<ObjectValueMap> value){
        this.headervalues=headervalues;
        this.value=value;
    }
}

--- Value map class--

public class ObjectValueMap {
	
    @AuraEnabled
    public account account{get;set;}
    @AuraEnabled
    public list<fieldValues> values{get;set;}
    
    public ObjectValueMap(account acc,list<fieldValues> values){
    	this.account=acc;
        this.values=values;
    }
}

-- Field values class--
public class FieldValues {
	@auraenabled
    public object value{get;set;}
    
    public FieldValues(object value){
        this.value=value;
    }
}

You can modify this code any other object you wish to implement.
Create listview button with the VF page.
Hi there, beginner VF/Apex coder here.

I have a VF email template where the relatedTo object is Asset. I would like to add a VF component that displays a table of all the sibling assets under the same account. Here is my code so far:

Constructor:
public class findSiblingAssets {
    private final List<Asset> assets;

    public Asset ast {get; set;}
    
    public findSiblingAssets() {
        
        assets = [select Id, AccountId, Name, UsageEndDate from Asset where AccountId = :ast.AccountId];
    }

    public List<Asset> getSiblingAssets() {
        return assets;
    }
}
Component (Named "FindSiblingAssets"):
<apex:component controller="findSiblingAssets" access="global">
    <apex:attribute type="Asset" name="originast" assignTo="{!ast}"/>
    <apex:dataTable value="{!SiblingAssets}" var="sib">
        <apex:column >
            <apex:facet name="header">Asset Name</apex:facet>
            {!sib.Name}
        </apex:column>
    </apex:dataTable>

</apex:component>

And here are relevant parts of the email template:
 
<messaging:emailTemplate relatedToType="Asset"
  subject="Subject Line here"
  replyTo="replyaddress@email.com">
  <messaging:htmlEmailBody >
  <html>
...
<c:FindSiblingAssets originast="{!relatedTo}"/>
...
</html>
</messaging:htmlEmailBody> 
</messaging:emailTemplate>


However, after I save the Email Template page, or try to to a test merge, I get the message: "Error occurred trying to load the template for preview: Attempt to de-reference a null object. Please try editing your markup to correct the problem."

I cannot figure out for the life of me what I'm doing wrong! Please help!

How we Hide the Recycle bin From Home page..Any Help.?

 

 

Thanks in Advance

  • April 09, 2012
  • Like
  • 0
I have developed code to over come limitation of print option for list view.
VF Page
<apex:page sidebar="false" standardStylesheets="false" cache="false" standardController="Account" recordSetVar="accounts" lightningStylesheets="true">
    <button id="upload-button" onclick="window.print();" style="margin-left: 50%;" Class="slds-button">Print</button>
    <apex:includeLightning />
    <div id="lightning" ></div> 
    <script>
        $Lightning.use("c:ListView", function() {
          $Lightning.createComponent("c:ListViewComponent",
          { label : "" },
          "lightning",
          function(cmp) {
             
          });
        });
    </script>
</apex:page>


Controller class
public with sharing class ListViewController {
    
    // Method to get all list view option available for the Account object 
    @AuraEnabled
    public static List<SelectOption> getListViews(){
        SelectOption  lstView=new SelectOption ('--None--','--None--');
        List<SelectOption> listviews = new List<SelectOption>();
        listviews.add(lstView);
        for(ListView lstObj : [SELECT Id, Name FROM ListView WHERE SobjectType = 'Account' order by name ASC]){
            listviews.add(new SelectOption (lstObj.id,lstObj.name));
        }
        return listviews; 
    }
    // Method to get the Account records based on the selected list view
    @AuraEnabled  
    public static DynamicTableMapping getFilteredAccounts(String filterId){
        list<string> headervalue =new list<string>();
        HttpRequest req = new HttpRequest();
        String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
        String endPoinURL = baseUrl+'/services/data/v32.0/sobjects/Account/listviews/'+filterId+'/describe';
        req.setEndpoint(endPoinURL);
        req.setMethod('GET');
        req.setHeader('Authorization',  'Bearer ' + UserInfo.getSessionId());
        Http http = new Http();
        HTTPResponse response = http.send(req);
        Map<String, Object> tokenResponse = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
        String query = (String) tokenResponse.get('query');
        system.debug('query--->'+query);
       for(string s:query.split(',')){
            s=s.trim();    
            if(s.startsWith('SELECT')){
                headervalue.add((s.removeStart('SELECT')).trim());        
            }else if(!s.startsWith('SYSTEMMODSTAMP') && !s.equalsIgnoreCase('SYSTEMMODSTAMP FROM ACCOUNT ORDER BY NAME ASC NULLS FIRST') && !s.contains('ASC')){
                headervalue.add(s.trim());
            }
        }
        
        List<ObjectValueMap> AccountList = new List<ObjectValueMap>();
        
        for(Account accountObj : database.query(query)){
            
            Map<String, Schema.SObjectField> objectFields = Account.getSObjectType().getDescribe().fields.getMap();
            list<FieldValues> fieldValue=new list<FieldValues>();
            for(string s:headervalue){
                Schema.DescribeFieldResult dr;
                if (objectFields.containsKey(s)) 
                      dr = objectFields.get(s).getDescribe();
                if(null!=dr)
                    fieldValue.add(new FieldValues(string.valueof(null==accountObj.get(dr.getName())?'':accountObj.get(dr.getName()))));            
                else
                    fieldValue.add(new FieldValues(string.valueof('')));
            }
            AccountList.add(new ObjectValueMap(accountObj,fieldValue));
        }
        
        return new DynamicTableMapping(headervalue,AccountList);        
    }
      
}



Lightning component
<aura:component controller="ListViewController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="AccountListViewList" type="SelectOption[]"/>
    <aura:attribute name="AccountList" type="DynamicTableMapping"/>
    <aura:attribute name="fieldList" type="string[]"/>
    <ui:inputSelect class="slds-select slds-size_small" aura:id="selectedViewId" label="Account View" change="{!c.getFilteredAccount}">
        <aura:iteration items="{!v.AccountListViewList}" var="listview">
            <ui:inputSelectOption text="{!listview.value}" label="{!listview.label}"/>
        </aura:iteration>
    </ui:inputSelect>
   
    <br/><br/>
    
    <table class="slds-table slds-table_bordered slds-table_cell-buffer">
        <thead>
            <tr class="slds-text-title_caps">
                <aura:iteration items="{!v.fieldList}" var="item">
                    <th scope="col">
                        <div class="slds-truncate" title="{!item}">{!item}</div>
                    </th>
                </aura:iteration>
            </tr>
        </thead>
        <tbody>
        <aura:iteration items="{!v.AccountList}" var="item" indexVar="index">
        <tr>
       
            <aura:iteration items="{!item.values}" var="item1">
                <td>
                     {!item1.value}   
                </td></aura:iteration>
        </tr>
        </aura:iteration>
        </tbody>
    </table>
</aura:component>


Component controller JS
({
    doInit : function(component, event, helper){
        var action = component.get("c.getListViews");
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.AccountListViewList",response.getReturnValue());
            }
        });
       
        $A.enqueueAction(action);
    },
    getFilteredAccount : function (component, event, helper) {
        var selected = component.find("selectedViewId").get("v.value");
        var action = component.get("c.getFilteredAccounts");
        action.setParams({filterId : selected});
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.AccountList",response.getReturnValue().value);
                component.set("v.fieldList",response.getReturnValue().headervalues);
            }
        });
        
        $A.enqueueAction(action); 
    },
    
})


Helper classes
public class DynamicTableMapping {
    
    @AuraEnabled
    public list<string> headervalues{get;set;}
    @AuraEnabled 
    public list<ObjectValueMap> value{get;set;}
    
    public DynamicTableMapping(list<string> headervalues,list<ObjectValueMap> value){
        this.headervalues=headervalues;
        this.value=value;
    }
}

--- Value map class--

public class ObjectValueMap {
	
    @AuraEnabled
    public account account{get;set;}
    @AuraEnabled
    public list<fieldValues> values{get;set;}
    
    public ObjectValueMap(account acc,list<fieldValues> values){
    	this.account=acc;
        this.values=values;
    }
}

-- Field values class--
public class FieldValues {
	@auraenabled
    public object value{get;set;}
    
    public FieldValues(object value){
        this.value=value;
    }
}

You can modify this code any other object you wish to implement.
Create listview button with the VF page.