Showing posts with label Salesforce. Show all posts
Showing posts with label Salesforce. Show all posts

Wednesday, November 2, 2016

How to get site user in debug logs Winter17

So after winter17 we cannot see site user debug as a salesforce update.

To enable that we have to set cookies in user browser.

In chrome open inspect element>console and paste this.
Document.cookie="debug_logs;domain=.force.com";

Thursday, July 28, 2016

Apex inputField issue with dataTable,pageBlockTable and repeat

When working with <apex:inputField> inside dataTable,pageBlockTable with wrapper objects you have to use <apex:column> if you donot use it visualforce pahe will result inot an error saying

"<apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable."

To over come this you have to use <apex:inputField> inside <apex:column> or you can use <apex:repeat> instead, when you use <apex:repeat> you have to design the table structure yourself.

Monday, July 18, 2016

Using Salesforce SOAP API in Ajax

Just a small post(its a very old functionality but I just posted it now) for how to create record using /soap/ajax/ in Salesforce. The code can be written in Visualforce page as well as Custom button as javascript.

Reference: SOAP API

Usage:
  1. Can be used to create record like logs or attachments from javascript hence reducing server processing time.
  2. Can query record to check values in page layout buttons.

Friday, July 1, 2016

How to have a image crop functionality in salesforce

Many time there is a custom requirement(generally in community) that a user can upload images, and when they do so there should be a functionality to crop or rotate it. We can achive it by using "corpper.js" Link.

Note: This page will through a viewstate error, due to base64 string size, try using transient variable to solve this.


Friday, June 10, 2016

How to "break" pass by reference in Lightning attributes

Hi,
I resently came by the problem in Lightning Aura development. I was developing a page to show some components on the page, the requirment was that user can deselect some of the rows and then data has to be rearranged accordingly simple right!.

I also thought so the approch I took was to have two list one for the values to display and another to hold the cloned values, so if the user rests all I can replace it with clone values and done. What happen in auro if the two variable are seprate but you filled them using a single source of reference then they are pointing to the same memory and hence if one changes other implecitly chnages. To eleminate this proble I simply used "JSON.stringify".

What this will do is when you have your values from controller to JS component then convert it into a well formated structure and then using "eval" convert it back to object. This will break the pass by  reference problem and two values can be independent.

Sunday, March 27, 2016

How to automate your salesforce deployment using Ant

Recently I was thinking to make automatic deployment mechanism to save time that was invested in weekly deployments. So after scratching the surface of Ant Migration Tool I cam up with this script to automatically extract and deployment class and trigger from one org to another.

Option 1-
Step 1. Must have JDK 1.6 or higher
Step 2. Install Ant to your machine use this "http://ant.apache.org".
Step 3. Download Salesforce Ant Migration ZTool Jar package.
Step 4. Create/Clone two folder using the sample folder in the zip.
Step 5. Provide Username password to both the Build.property files.
Step 6. Use this code and save it to Auto.bat in any location
ECHO Retrieve and Deployment auto script started..
cd\
cd <Path to>\Retrieve Meta
start /W ant retrieveUnpackaged ^&^& exit
Xcopy  /S /I /E /Y "<Path to>\Retrieve Meta\retrieveUnpackaged"  "<Path to>\Deploy Meta\codepkg"
ECHO Retrieve file copied to Deployment folder..
cd\
cd <Path to>\Deploy Meta
start /W ant deployCode ^&^& exit
ECHO Retrieve and Deployment auto script stoped..
PAUSE Press Enter to close

Where <Path to> is the path where you extracted the Ant Migration Tool and cloned folders.

Option 2-
Have a ant build.xml configured with two targets first for retrieve and second for deployment and link them inside another target like <target name="all" depends="retrieve, deploy">
</target> then open cmd and run this
ant -f build.xml all

Tuesday, October 7, 2014

How to get all property of a javascript [object object]

Ok so sometime when usings others code in javascript me might not be knowning the property that returning object has. So to get the property just use this code after initilizing and record all the available property and values and then use accourdingly.

Option 1:
for(var key in conn) {

    var value = key +" : "+ conn[key]; console.log("***"+value); 
} 
Option 2:
console.log(conn);  

Hope this helps you!!

Tuesday, September 23, 2014

How to display a image if you have Bas64 sting on a visualforcfe page

Ok so recently I got a requirement that the image is saved in a Base64 format and when it is displayed it should be displayed as image.

What? Right and here is a small trick to do the job.

<img alt="<image_Name>" src="data:image/<image_File_Extension>;base64, <base64_Image_String>"></img>
http://developer.force.com/cookbook/recipe/converting-a-rich-text-area-fields-image-for-api-upload

Hope this helps!!

Wednesday, August 27, 2014

How to bootstrap with Visualforce

Ok so today I am going to show you a small and simple example of how to get started with bootstrap in visualforce. Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web. So now first thing first:

  1. Download bootstrap lib zip file from "http://getbootstrap.com/" and upload it to your custom setting by name "Bootstrap".
  2. Now create a visualforce page name "Bootstrap_Mobile_CreateAccount".
  3. And include the bootstrap scripts as :

<!-- Load script here -->
    <apex:stylesheet value="{!URLFOR($Resource.Bootstrap, 'bootstrap-3.2.0-dist/css/bootstrap-theme.min.css')}"/>
    <apex:stylesheet value="{!URLFOR($Resource.Bootstrap, 'bootstrap-3.2.0-dist/css/bootstrap.min.css')}"/>
    <apex:includeScript value="https://code.jquery.com/jquery.js"/>
    <apex:includeScript value="{!URLFOR($Resource.Bootstrap, 'bootstrap-3.2.0-dist/js/bootstrap.min.js')}"/>
    4.   Now create div and give the class of bootstrap as shown here
<div class="container">
 <br/>
 <div class="panel panel-primary">
  <div class="panel-heading">
   <h3 class="panel-title">Create Account</h3>
  </div>
  
  <div class="panel-body">
   Details:
   <div class="row">
    <div class="col-md-4"><input id="inp1" type="text" placeholder="Account Name" class="form-control"/></div>
    <div class="col-md-4"><input id="inp2" type="text" placeholder="Description" class="form-control"/></div>
    <div class="col-md-4"><input id="inp3" type="text" placeholder="Phone" class="form-control"/></div>
   </div>
   <br/>
   <br/>
   <button class="btn btn-lg btn-primary btn-block" type="submit" onclick="createAcc();">Save</button>
  </div>
 </div>
</div>
     5.   Now provide this <javaScript> to the page to we can save the records.
<script>
 Visualforce.remoting.timeout = 120000; // Set timeout at page level
 var $j = jQuery.noConflict();        

 function createAcc(){
  $j('#basicModal2').modal('show');
  var accName= $j('#inp1').val();
  var accDes= $j('#inp2').val();  
  var accPhn= $j('#inp3').val();          
  Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Bootstrap_Mobile_CreateAccountCon.createAccount}',accName,accDes,accPhn,handleResult);  
 } 
 function handleResult(result, event){
  if (event.status) {
   alert(result);
  } 
      
 }             
</script>  
6. Now create a controller and in that create this javascriptRemoting method
@RemoteAction
global static string createAccount(String accName, String accDes, String accPhn){
 Account acc = new Account();
 acc.name = accName;
 acc.Description = accDes;
 acc.Phone = accPhn;
 insert acc;
 return 'Success';
}
That is it, You have created a visualforce page that is using bootstrap css for view and apex controller for saving the records.

PS: For different type of element you can use different class as:
CheckBox:
<div class="checkbox col-md-4">
 <label>
   <input type="checkbox"> Check Box</input>
 </label>
</div>
//get the checkbox values as this or you can also get a array of objects and use .each
//for multiple checkboxes id starting with inp4
function checkId(){
   var inpVal= $j('#inp4').prop('checked');
   alert(inpVal);
}

Hope this helps you!!

Thursday, August 7, 2014

How to play video in visualforce from attachment

So we have developed many data driven pages but when it comes to multimedia then many of us didn't worked on it much. We are thing "Ok its just a video or a image I will display it by getting its path" but the problem arise when its(the MIME file) is an attachment. Attachments are stored in database unlikely if compared from static resource which has a direct access URL. So how can I display a multimedia file if its type is BLOB.

The answer is here, we can use <object> tag or we can have <video> tag of HTML5.
for <object> tag, here the {!crwAtt.id} is Attachment object.
hor <video> tag, remember to add "docType="html-5.0"" to page.