Lightning Connect: How to display related records from one Salesforce instance to another

The place of cloud learners

Lightning connect is a nice way to integrate other systems. For instance SAP, oracle etc., which are providing support of Open Data Protocol (OData). Right now this feature is limited as we can view records from other systems in Salesforce but in later releases it is going to be a full fledge integration feature.

The best thing is that, it can be configured without writing a code.

In below example, I have explained how we can associate related records of Invoice & Line Item from one organization to another.

Below are the records which I have already created in my source organisation for this demonstration.
Invoice&LineItem

Step 1: Create an external Data Source connection on the destination org, which will point to the source org as explained below:
Lightening_External Data Source
Ligtening_External Data Source Save
Step 2: Select objects which is required to be displayed, in my case it is Invoice, Invoice Line Item and Account.
Select objects

Step 3:…

View original post 110 more words

Advertisements

Identify Cloned Record in Salesforce Trigger

Hey Foce.com peeps! Let’s see ‘how to identify the cloned record in trigger?’

To fully understand the logic, you must be familiar with the apex trigger order of executionWhenever a new record is inserted, our trigger is executed before the workflow rule does.

Lets consider Opportunity cloning. To identify a record which is being cloned:

  1. First create a custom text field on Opportunity record, lets name is Record_Id. 
  2. Create a workflow rule that on create, populates Record_Id with SFDC record Id.
  3. In our create trigger, we will check for the Record_Id.
  4. If Record_Id == ”, then the record is new.
  5. If Record_Id != ”, then the record is being cloned.

Explanation:

As trigger is executed before the workflow rule, so whenever a new record is created this Record_Id will not contain any value.

But when a record will be cloned this field Record_Id will contain the SFDC record Id of the original object from where it is being cloned. Hence we can perform our logic what ever we need to do with the cloned object.

Salesforce Scripted Data Loader updated to Rename the Status Log Files

While using scripted data loader, you can use the following code to rename the status log files generated by the Apex Data Loader.

My code renames the Order Success and Error file to OrderSuccess_[month][day][year]

@echo off
REM Directory variables
setlocal EnableDelayedExpansion

set BASEDIR=”C:\Client-Sakonent\NACorp\SDLv04\SDL”
set CONFDIR=%BASEDIR%\conf
set ERRORDIR=%BASEDIR%\status
set DLBINDIR=%BASEDIR%\bin

for %%i in ( OrderUpsert ) do (
echo Processing %%i

cd %BASEDIR%
type NUL > ERROR.LOG

cd %DLBINDIR%
call process %CONFDIR% %%i
cd %ERRORDIR%

if exist OrdersSuccess.csv ( RENAME “OrdersSuccess.csv” “OrdersSuccess_%date:~4,2%%date:~7,2%%date:~10,4%.csv” )

if exist OrdersError.csv ( RENAME “OrdersError.csv” “OrdersError_%date:~4,2%%date:~7,2%%date:~10,4%.csv” )

cd %BASEDIR%

)

endlocal

Salesforce Scripted Data Loader Windows batch to delete empty CSV files in a folder

To delete all the empty csv files with the header column only in a specific folder. I used it in a Scripted Data Loader implementation to delete the empty log files created by the Apex Data Loader.

Create a .bat file with the following code:

@echo off
setlocal
echo Processing StatusLogCleaner
for /f “usebackq delims=;” %%A in (`dir /b *.csv`) do for /f %%a in (‘type %%A^|find “” /v /c’) do If %%a LSS 2 del “%%A”
echo End Process StatusLogCleaner
endlocal

Place the file in the Status folder and execute the batch after the SDL batch process.

To execute it from the SDL batch process append the following code in the batch:

set BASEDIR=”C:\Client-Sakonent\NACorp\SDLv04\SDL”

set ERRORDIR=%BASEDIR%\status

echo cleaner call %ERRORDIR%
cd %ERRORDIR%
call StatusLogCleaner.bat

Salesforce: Using Visualforce Page Contenttype as CSV

To show view the records in a CSV file we can use the following code:

<apex:page standardController="Account" contenttype="application/vnd.ms-excel">
 <apex:pageBlock title="Contacts">
  <apex:pageBlockTable value="{!account.Contacts}" var="contact">
   <apex:column value="{!contact.Name}"/>
    <apex:column value="{!contact.MailingCity}"/>
   <apex:column value="{!contact.Phone}"/>
  </apex:pageBlockTable>
 </apex:pageBlock>
</apex:page>

Salesforce: Validation rule for valid US States

Validation rule for Billing State to be of two characters and valid US state
OR(
LEN(BillingState) < 2,
NOT(
CONTAINS(
“AL:AK:AZ:AR:CA:CO:CT:DE:DC:FL:GA:HI:ID:” &
“IL:IN:IA:KS:KY:LA:ME:MD:MA:MI:MN:MS:MO:MT:NE:NV:NH:” &
“NJ:NM:NY:NC:ND:OH:OK:OR:PA:RI:SC:SD:TN:TX:UT:VT:VA:” &
“WA:WV:WI:WY”,
BillingState)))

Salesforce – Multi select Delete Button for List Views

Topic: Delete Selected Opportunities from List view

Problem: In out of the box List views we don’t have option to multi select and delete the records. If we want to give users the right to delete few records from the list views then user will have to delete each record one by one.

Solution: I have created this Javascript button to delete multiple records from the list views.

This example is implemented on the Opportunities Tab. To implement it you need to follow the following steps:

  1. Create a custom Opportunity button.
  2. Add the button to the Opportunities tab.

Create a custom Opportunity button:

To do so, Go to Setup> Customize> Opportunities> Buttons & Links and create a new custom button. Type the label, name, description. Select the rest of the options as presented in the image below. Then save.

Code:

// Include and initialize the AJAX Toolkit javascript library//{!REQUIRESCRIPT(“/soap/ajax/10.0/connection.js”)}// Get the list of accounts that should be deleted.// Use the $ObjectType merge field to indicate the type of// record Ids that are expected.//

var idsToDelete = {!GETRECORDIDS( $ObjectType.Opportunity )};

var deleteWarning = ‘Are you sure you wish to delete ‘ +idsToDelete.length + ‘ records?’;

if (idsToDelete.length && (window.confirm(deleteWarning)))

{

// Delete the records, and pass a function into the call// so that the toolkit refreshes the current page// asynchronously when the call succeeds.//

sforce.connection.deleteIds(idsToDelete,function() {navigateToUrl(window.location.href);});}

else if (idsToDelete.length == 0) {alert(“Please select the records you wish to delete.”);}

Add the button to the Opportunities tab:

The second part is to add this button to the Opportunities list views. Go to the Setup> Customize> Opportunities> Search layouts. Click edit on the Opportunities list view and add the new custom delete button to the selected buttons list and save.