Formula field to find the last day of the month in Salesforce
Sample Code:
IF( MONTH( TODAY() ) = 12,
DATE( YEAR( TODAY() ), 12, 31 ),
DATE( YEAR( TODAY() ), MONTH( TODAY() ) + 1, 1) – 1)
Sample Code:
IF( MONTH( TODAY() ) = 12,
DATE( YEAR( TODAY() ), 12, 31 ),
DATE( YEAR( TODAY() ), MONTH( TODAY() ) + 1, 1) – 1)
Feature | Custom Objects | External Objects |
---|---|---|
Data is stored in your Salesforce org | Yes | No |
Read | Yes | Yes |
Write | Yes | Yes (limited) |
Tabs, layouts | Yes | Yes |
Visualforce | Yes | Yes |
Field-level security | Yes | Yes |
Sharing | Yes | No |
REST and SOAP API | Yes | Yes |
SOQL | Yes | Yes (limited) |
Search and SOSL | Yes | Yes (pass-through) |
Formula fields | Yes | Not Yet |
Workflow, triggers | Yes | Not Yet |
Reports and analytics | Yes | Not Yet |
Chatter | Yes | Yes (no field tracking) |
Controller:
public with sharing class Sample { public string selectedValue {get; set;} public List<SelectOption> industry {get; set;} public void getIndustry() { Schema.DescribeFieldResult industryDescription = Account.Industry.getDescribe(); industry = new List<SelectOption>(); for (Schema.Picklistentry pl : industryDescription.getPicklistValues()) { industry.add(new SelectOption(pl.getValue(),pl.getLabel())); } } public void checkValue() { System.debug('Selected Industry Type - ' + selectedValue); } }
Visualforce Page:
<apex:page controller="Sample" action="{!getIndustry}" sidebar="false" showHeader="false"> <apex:form > <apex:pageblock> <apex:pageBlockSection columns="1" > <apex:outputLabel value="Industry Type" /> <apex:selectList size="1" value="{!SelectedValue}" > <apex:selectOptions value="{!industry}"/> <apex:actionSupport event="onchange" action="{!checkValue}" /> </apex:selectList> </apex:pageBlockSection> </apex:pageblock> </apex:form> </apex:page>
IF(
AND(
YEAR(End_Date__c) = YEAR(Begin_Date__c),
MONTH(End_Date__c) = MONTH(Begin_Date__c)),
1,
IF(ISBLANK(End_Date__c),
(YEAR(TODAY())*12+MONTH(TODAY())) –
(YEAR(Begin_Date__c)*12+MONTH(Begin_Date__c)),
(YEAR(End_Date__c)*12+MONTH(End_Date__c)) –
(YEAR(Begin_Date__c)*12+MONTH(Begin_Date__c))
)
)
Clone | Deep Clone |
---|---|
Generally clone the list of object and keep the reference. | Generally it clone the list of object but don’t hold any reference. |
A Clone doesn’t keep the Ids. | A Deep Clone keeps the Id. |
Supports primitive data type. | Doesn’t support primitive datatype. |
Parameters are not applicable. | Parameter are applicable. |
Here is a an example to understand difference between Clone and DeepClone:
I am creating a New Account with some fields.
Account acc = new account(Name = 'Salesforce', Billingcity = 'San Francisco', Type = 'Customer - Direct', Phone = '9999999999'); insert acc;
This creates a record in the Account as shown below:
Now, I am cloning it and inserting again.
Account acc = new account(Name = 'Salesforce', Billingcity = 'San Francisco', Type = 'Customer - Direct', Phone = '9999999999'); insert acc; //Cloning the above Account Record acc Account accCloneCopy = acc.clone(false, false, false, false); insert accCloneCopy;
It creates a new copy of the record with same values, since it keeps the reference, new record ID is generated for cloned record.
Now, when I try to deepclone the record: (Deepclone is done by keeping true in the parameters) like,
clone(preserveId, isDeepClone, preserveReadonlyTimestamps, preserveAutonumber)
Account acc = new account(Name = 'Salesforce', Billingcity = 'San Francisco', Type = 'Customer - Direct', Phone = '9999999999'); insert acc; //Deep cloning the above record Account accDeepCloneCopy = acc.clone(true, true, false, false); insert accDeepCloneCopy;
It shows an error, because the Id is also considered and cannot insert the deppcloned record: