Saturday, 8 June 2019

Salesforce - Mass update records with onclick javascript




{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} 
 var records = {!GETRECORDIDS($ObjectType.Account)}; 
 var updateRecords = []; 
 if (records[0] == null) 
 { 
  alert("Please select at least one Account") 
 } 
 else 
 { 
  for (var i=0; i<records.length; i++) 
  { 
   var acc = new sforce.SObject("Account"); 
   acc.id = records[i]; 
   acc.Type = "Customer"; 
   updateRecords.push(acc); 
  } 
  result = sforce.connection.update(updateRecords); 
  window.location.href = "/001"; 
 }  

Wednesday, 29 May 2019

Salesforce - Mass delete records on list view

{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')} 
try 

var selectedRecords = {!GETRECORDIDS( $ObjectType.Lead )}; 
if(selectedRecords.length<1) 
alert('Please Select at Least One Row !'); 
else 

userConsent = confirm( 
selectedRecords.length + 
' Record(s) will be Deleted. Continue ? ' 
); 
if(userConsent == true) 

delResult = sforce.connection.deleteIds(selectedRecords); 
if (delResult[0].getBoolean("success")) 

alert('The Record(s) were Deleted Successfully.'); 
window.location.reload(); 

else 
alert( 
'The Record(s) Could Not be Deleted. Error Message: ' + 
delResult[0].errors.message 
); 



catch(e) 

alert('The Action Could not be Completed. Error Message: ' + e); 
}

Monday, 6 May 2019

Salesforce - SLDS Grid System



If you want one column, below code is helpful

 <div class="slds-grid slds-wrap">                                                 
                        <div class="slds-col slds-size_1-of-1 slds-small-size_1-of-1 slds-medium-size_1-of-1" style="padding:0px 2px">   
                            </div>
</div>






If you want two columns below code is helpful


<div class="slds-grid slds-wrap">                                                 
                        <div class="slds-col slds-size_1-of-1 slds-small-size_1-of-1 slds-medium-size_1-of-2" style="padding:0px 2px">   
                       //content goes here
</div>
  <div class="slds-col slds-size_1-of-1 slds-small-size_1-of-1 slds-medium-size_1-of-2" style="padding:0px 2px">   
                   //content goes here
                            </div>
</div>

Monday, 29 April 2019

Salesforce - ContentDocumentLink in test class

Account acct = new Account(Name='TEST_ACCT');
insert acct;

ContentVersion contentVersion = new ContentVersion(
  Title = 'Penguins',
  PathOnClient = 'Penguins.jpg',
  VersionData = Blob.valueOf('Test Content'),
  IsMajorVersion = true
);
insert contentVersion;    
List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

//create ContentDocumentLink  record 
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = acct.id;
cdl.ContentDocumentId = documents[0].Id;
cdl.shareType = 'V';
insert cdl;

Salesforce - Close Quick Action




$A.get("e.force:closeQuickAction").fire();





example:

({
    accept : function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})

Monday, 1 April 2019

Mysql trigger to auto generate 18 digit Id String on before insert table record






CREATE TRIGGER `AutoGenerateIdOnTestTaker` BEFORE INSERT ON `TestTaker`
 FOR EACH ROW SET New.Id = (SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 18))