Posts

Showing posts from June, 2018

Get Id from current page in Lightning Component

Image
1. Get Id from current page 1.1 Add 'force:hasRecordId' to implements <aura:component implements="force:hasRecordId"> 1.2 Create attribute to receive Id <aura:attribute name="recordId" type="Id" /> 1.3 In controller js component.get("v.recordId");

How to render Visualforce page to PDF then Download it.

7. How to render Visualforce page to PDF then Download it. 1. You need to have two page first page is main page <apex:page id="MainPage" showHeader="false" cache="true" contentType="application/x-pdf#PDF_Name.pdf" <apex:include pageName="SecondpageName"/> </apex:page> 2. your second page <apex:page renderAs="pdf" >//your code</apex:page>

Dynamic SOQL

Image
url source : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm

Query in Loop problem: ( we do not need to to select query in loop )

4. Query in Loop problem: ( we do not need to to select query in loop ) resolved: In Apex Class: public class UpdateAccTriggerHandler { public void handleBeforeCreateUpdate( List<Account> newAccList ){ Set<Id> accountGroupIds = new Set<Id>();       for( Account iAccount : newAccList ) {             if(iAccount.Group__c != null ) {                 accountGroupIds.add( iAccount.Group__c );             }         } List<Account> accountGroups = [ SELECT Id, Name, OwnerId                                   From Account                                   WHERE Id in: accountGroupIds                                 ];         Map<Id,Account> groupIdMap = new Map<Id,Account>();         for( Account oneGroup: accountGroups ) {             groupIdMap.put(oneGroup.Id,oneGroup);         }       for( Account iAccount : newAccList ) {             if( iAccount.Group__c != null ) {                 iAccount.OwnerId = groupIdMap.get(iAccount.Group__c).Own

Call Method from trigger to apex

3. Call Method from trigger to apex and with list<Account> and Map<Id,Account> In Apex class: public class UpdateAccTriggerHandler { public void updateAccountTest(List<Account> newAccList, Map<Id,Account> oldMap){ for(Account acc:newAccList){ //your code... } } } In Trigger : UpdateAccTriggerHandler updateAcc = new UpdateAccTriggerHandler (); updateAcc .updateAccountTest(Trigger.New, Trigger.oldMap);

How to call method in Apex without @RemoteAction

2. Call Method in salcesforce apex class without @RemoteAction In Apex Class: public void saveRanking() { // you code here} In salesforce Page: // call method from apex class by clicking on button <apex:commandButton styleClass="slds-button slds-button--neutral btn-refresh" reRender="mainForm" status="loadingStatus" action="{!saveRanking}" value="Save"> </apex:commandButton>

How to call method in Apex With @RemoteAction

1. @RemoteAction : use to call method from page to class by js In Apex class: @RemoteAction global static List<Account> getAccounts() { //your code } In JS method: function getAllAccount(){ // call method from saleforce class Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.OfficeLocatorController.getAccounts}', function(responseAccounts, event){ initialize(responseAccounts) },{escape: true} ); }