Gourav Verma
IndividualForum Replies Created
-
Hi Vicky,
For Paypal Salesforce Integration, there are 2 links I could find, please see below:
https://developer.paypal.com/docs/integration/direct/rest-payments-overview/
http://techsahre.blogspot.in/2011/01/simple-paypal-integration-with.html
Hope it helps.
-
Gourav
MemberOctober 3, 2016 at 2:12 pm in reply to: In Salesforce, How to call parametrized function from Visualforce?Hi Tanu,
The <apex:param> standard component allows parameters to be defined for a parent component, which can be assigned to a controller property.
VF Page:-
<apex:commandButton value="Del" action="{!delCont}" rerender="all">
<apex:param name="contIdParam" value="{!cont.id}" assignTo="{!contIdChosen}"/>
</apex:commandButton>Controller:-
public String contIdChosen {get; set;}
...
...
public PageReference delCont()
{
Contact toDel=new Contact(id=contIdChosen);
delete todel;
setupContacts();
return null;
}Hope this will help you.
Thanks.
-
Gourav
MemberOctober 3, 2016 at 1:55 pm in reply to: How can we get the Salesforce apex:repeat variable in the Javascript method?Hi Mohit,
Add a styleclass="" to your components, then use jQuery's selectors. You can't use Id because it has to be set to a static item.
<apex:pageBlockSection columns="1">
<apex:outputPanel id="relatedListSelect">
<apex:repeat value="{!relatedListNames}" var="relList" id="theRelLists">
<apex:inputCheckbox styleClass="{!relList.relListName} inputIsChecked" value="{!relList.selected}"/>
<apex:outputText value="{!relList.relListName}"/><br/>
</apex:repeat>
</apex:outputPanel>
</apex:pageBlockSection>Then in jQuery you can do:
<script type="text/javascript">
$('.inputIsChecked').each(function(i,o){
$(o).is(':checked');
//can get the name of the element here in a variety of ways,
//split the classes and take the one that is the name of the list-element.
});
</script>Thanks.
-
Gourav
MemberOctober 3, 2016 at 1:52 pm in reply to: How to enable Person Accounts in Salesforce Dev edition?Hi Tanu,
You need to log a ticket to salesforce to enable Person Accounts in Dev Edition.
To log a ticket -> Login into your Dev Edition -> Click on "Help" at the Top -> Click on "My Cases" -> Click On "Log A Case" -> Select the Case Reason as "Feature Activation Request" -> Select "Feature Activation" in "General Activation Area" and ask for the Person Account Enablement.
Hope this helps.
Thanks
-
Gourav
MemberOctober 3, 2016 at 1:48 pm in reply to: How to check debug log for the installed Salesforce app?Hi Mohit,
Could you please provide some more details regarding your requirement? like what type of app you are using?
If you are using MANAGED package then we can't do much regarding logs. But if you are using UN-MANAGED then you can put some debug according to your understanding to check the flow of the code and the values you are getting during various stages in code.
Hope this will help you.
Thanks.
-
Gourav
MemberOctober 3, 2016 at 1:27 pm in reply to: How to Import Contacts from Excel Sheet Using Salesforce visualforce Page?Hi Tanu,
You can use CSV parser for this..plese refer the below example code where I have created one Visualforce page from where I am uplaoding the excel file .csv and extracting the records data and mapping with object columns
please check and let me know if it helps you
page:
<apex:page sidebar="false" controller="UploadOpportunityScheduleLineItem">
<apex:form >
<apex:sectionHeader title="Upload data from CSV file"/>
<apex:pagemessages />
<apex:pageBlock >
<center>
<apex:inputFile value="{!contentFile}" filename="{!nameFile}" />
<apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;"/>
<br/> <br/>
</center><apex:pageBlocktable value="{!mapUnmatchedSchedules}" var="mapID" title="Unmathed Lines of CSV file">
<apex:column headervalue="Opportunity Id">
{!mapUnmatchedSchedules[mapID][0]}
</apex:column>
<apex:column headervalue="Oportunnity Name">
{!mapUnmatchedSchedules[mapID][1]}
</apex:column>
<apex:column headervalue="Month">
{!mapUnmatchedSchedules[mapID][2]}
</apex:column>
<apex:column headervalue="Year">
{!mapUnmatchedSchedules[mapID][3]}
</apex:column>
<apex:column headervalue="Actualized Amount">
{!mapUnmatchedSchedules[mapID][4]}
</apex:column>
</apex:pageBlocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
classpublic with sharing class UploadOpportunityScheduleLineItem
{// Global variables
public string nameFile{get;set;}
public Blob contentFile{get;set;}
List<Schedule__c> lstScheduleToUpdate = new List<Schedule__c>();
public Schedule__C objSchedule{get;set;}
//String array for taking csv data by line.
String[] filelines = new String[]{};
//string array for taking csv columns.
String[] fileColumns = new String[]{};//set for storing all id's from csv.
set<String> opptoupload{get;set;}
//map for storing data from csv.
public map<String,String> mapOppIDMonthYearToAccAmount{get;set;}
public map<String, List<String>> mapUnmatchedSchedules{get;set;}//Main constructor
public UploadOpportunityScheduleLineItem()
{
//Initalizing required objects.
objSchedule = new Schedule__c();
opptoupload = new set<String>();
mapOppIDMonthYearToAccAmount = new map<String,String>();
mapUnmatchedSchedules = new map<String, List<String>>();
}
//Method to read file content and check extension and file format.
public Pagereference ReadFile()
{
//If without selecting csv file you clicked on upload it will give error message.
if(nameFile == null)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'You should select csv file to upload');
ApexPages.addMessage(errormsg);
return null;
}
//Taking file extension.
String extension = nameFile.substring(nameFile.lastIndexOf('.')+1);
//Checking if file extension is .csv.
if(extension == 'csv' ||extension == 'CSV')
{
nameFile=contentFile.toString();
//Spliting by new line
filelines = nameFile.split('\n');
//Spliting values by (,) for checking coloumn size
fileColumns = filelines[0].split(',');
//If column size is 5 then only it will proceed.
if(fileColumns.size() ==5)
{
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
opptoupload.add(inputvalues[0]);mapOppIDMonthYearToAccAmount.put(inputvalues[0]+inputvalues[2]+inputvalues[3],inputvalues[4]);
mapUnmatchedSchedules.put(inputvalues[0]+inputvalues[2]+inputvalues[3],inputvalues);
lstScheduleToUpdate = new List<Schedule__c>();
}
for(Schedule__c objSchedule : [select Opportunity__r.Id ,Month__c,Year__c,
Actualized_Amount__c from Schedule__c where
Opportunity__c IN :opptoupload])
{
String str = objSchedule.Opportunity__r.Id;
String str1;
str1 = str.substring(0, 15);
if(mapOppIDMonthYearToAccAmount.containsKey(str1 + objSchedule.Month__c +objSchedule.Year__c))
{objSchedule.Actualized_Amount__c = decimal.valueOf(mapOppIDMonthYearToAccAmount.get(str1 + objSchedule.Month__c +objSchedule.Year__c).trim());
mapUnmatchedSchedules.remove(str1 + objSchedule.Month__c +objSchedule.Year__c);
lstScheduleToUpdate.add(objSchedule);
}
}
//Checking if list is not empty then updating.
if(lstScheduleToUpdate.Size()>0)
{
update lstScheduleToUpdate;
}
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.info,'File uploaded successfully');
ApexPages.addMessage(errormsg);return null;
}
else
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'There should be 5 columns in csv file');
ApexPages.addMessage(errormsg);
return null;
}
return null;
}
//If file is not csv type then it will give error message.
else
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'File type should be csv type');
ApexPages.addMessage(errormsg);
return null;
}
}
} -
Gourav
MemberOctober 3, 2016 at 1:20 pm in reply to: Why we use the Test.setCurrentPage(...) method in Salesforce and why should we in our apex controller unit test?Hi Mohit,
The Test.setCurrentPage method sets the page context for your unit test method. Good example can be below code:-
public PageReference save() {
PageReference p = null;if (this.qp == null || !'yyyy'.equals(this.qp)) {
p = Page.failure;
p.getParameters().put('error', 'noParam');
} else {
try {
Lead newlead = new Lead(LastName=this.lastName,
FirstName=this.firstName,
Company=this.company,
Email=this.email);
insert newlead;
} catch (Exception e) {
p = Page.failure;
p.getParameters().put('error', 'noInsert');
}
}if (p == null) {
p = Page.success;
}p.setRedirect(true);
return p;
}
The above code is taken from the VF guidehttps://www.salesforce.com/docs/developer/pages/Content/pages_controller_error_handling.htm
Now there are multiple scenarios to assert the logic .One common use case is veryfying the URL after save action has happened .Unit test is below for above code
@isTest
public class thecontrollerTests {
public static testMethod void testMyController() {
PageReference pageRef = Page.success;//Observe how we set the Page here
Test.setCurrentPage(pageRef);//Applying page context herethecontroller controller = new thecontroller();
String nextPage = controller.save().getUrl();// Verify that page fails without parameters
System.assertEquals('/apex/failure?error=noParam', nextPage);// Add parameters to page URL
ApexPages.currentPage().getParameters().put('qp', 'yyyy');//Observe how helpful it was to set the parameters in your page from Unit test// Instantiate a new controller with all parameters in the page
controller = new thecontroller();
controller.setLastName('lastname');
controller.setFirstName('firstname');
controller.setCompany('acme');
controller.setEmail('[email protected]');
nextPage = controller.save().getUrl();// Verify that the success page displays
System.assertEquals('/apex/success', nextPage);
Lead[] leads = [select id, email from lead where Company = 'acme'];
System.assertEquals('[email protected]', leads[0].email);
}
}In short once you set context of the Page using method described, your controller is executing with parameters referred from the page context.
You basically indicate to your Unit test class the page you are testing your controller logic for. Your controller can be binded to multiple page and setting page context for unit test makes it crystal clear you are testing for specific page behaviour.
-
Gourav
MemberOctober 3, 2016 at 1:04 pm in reply to: How to pass the security review when we use the "without sharing" in apex class in salesforce?Hi Mohit,
I would strongly suggest reading this recent post by Dan Appleman.
He outlines the various ways in which factors like sharing and CRUD/FLS play into security, and ends with the comment, which tells me you can pass security review with classes not marked as sharing so long that is clear to the users administering the system which uses that construct:
But if you implement one of the architectures described here, it’s virtually guaranteed that your first attempt to pass security review will fail. That’s the bad news. The good news is that the security review team actually understands security – the individuals I’ve dealt with have been consistently very competent. So they understand that real applications often need classes that are defined without sharing, and DML operations that do not test for field accessibility. What they want to see from you is that you aren’t just ignoring security out of laziness, but that those decisions were intentional. They don’t care so much where the security boundary is, as much as that you have one, and that it respects and enforces the configuration on the platform. You’ll need to document exactly what you are doing and why as part of your security review application, but once you’ve done so, assuming your security architecture is sound, you should be able to pass security review, at least with regards to field, object and record level security, without further trouble.
Thanks.
-
Gourav
MemberOctober 3, 2016 at 1:01 pm in reply to: How can we implement the spell checker in visualforce page for some text area in Salesforce ?Hi Mohit,
You can enable a spell checker...along with many many more options in ckeditor using some javascript on your page. Its the same editor that the regular rich text editor they normally use but you'll just be adding other options including a spell check button.
simply add the following code to any visualforce page. the only setting you need to update is where is says CKEDITOR replace('...'
us the $Component global to target your text area
{!$Component.blogForm.blogBlock.blogSection.blogBody}
this should be the selector of the textarea you want to use... full documentation on how to use the $Component global to find the selector of your text field here
http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_component.htm
it should work both with rich text area fields or even just regular text area fields
// The rich text field itself
<apex:inputTextArea value="{!Post__c.Body__c}" id="blogBody" richText="false" />/*
The rest of the form
*/// at the bottom of the page add the script to update CK editor
<script src="/ckeditor/ckeditor-3.6.2/ckeditor.js?t=3.6.2.3" type="text/javascript"/>// ckeditor replace with options
<script>CKEDITOR.timestamp = '3.6.2.1';
var prototocolAndHost = window.location.protocol + '//' + window.location.host;
var editor = CKEDITOR.replace('{!$Component.blogForm.blogBlock.blogSection.blogBody}', {baseHref : prototocolAndHost + '/ckeditor/ckeditor-3.6.2/', customConfig : '/ckeditor/ckeditor-3.6.2/ckeditor.config.js', height : '425', bodyId : 'articleEdit:createDocumentForm:sectionRepeat:0:fieldRepeat:0:fieldName:textAreaDelegate_00NG0000009Thtt_rta_body', toolbar : 'Full', sharedSpaces : { top : 'cke_topSpace', bottom : ' cke_bottomSpace' }, filebrowserImageUploadUrl : '/_ui/common/request/servlet/RtaImageUploadServlet', contentsCss : ['/sCSS/27.0/sprites/1362621144000/Theme3/default/gc/ArticleHtmlDetailElem.css'], disableNativeSpellChecker : false,language : 'en-us',sfdcLabels : { CkeMediaEmbed : { title : 'Embed Multimedia Content', description : 'Use <iframe> code from DailyMotion, Vimeo, and Youtube.', subtitle : 'Paste &lt;iframe&gt; code here:', exampleTitle : 'Example:', example : '\n \n <iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/KcOm0TNvKBA\" frameborder=\"0\" allowfullscreen></iframe>\n \n ', iframeMissing : 'Invalid <iframe> element. Please use valid code from the approved sites.'}, sfdcSwitchToText : { sfdcSwitchToTextAlt : 'Use plain text'}, CkeImageDialog : { uploadTab : 'Upload Image', infoTab_url : 'URL', error : 'Error:', uploadTab_desc_info : 'Enter a description of the image for visually impaired users', uploadTab_desc : 'Description', infoTab_url_info : 'Example: http://www.mysite.com/myimage.jpg', btn_insert : 'Insert', missingUrlError : 'You must enter a URL', uploadTab_file : 'Select Image', infoTab_desc : 'Description', btn_upadte : 'Update', wrongFileTypeError : 'You can insert only .gif .jpeg and .png files.', infoTab : 'Web Address', title : 'Insert Image', infoTab_desc_info : 'Enter a description of the image for visually impaired users', uploadTab_file_info : 'Maximum size 1 MB. Only png, gif or jpeg'}, CkeImagePaste : { CkeImagePasteWarning : 'Pasting an image is not working properly with Firefox, please use [Copy Image location] instead.'}}});
</script>Thanks.
-
Gourav
MemberOctober 3, 2016 at 12:59 pm in reply to: Which criteria is used to calculate cross object field in salesforce?Hi Tanu,
Cross-object formulas are formulas that span two related objects and reference merge fields on those objects. Cross-object formulas can reference merge fields from a master (“parent”) object if an object is on the detail side of a master-detail relationship. Cross-object formulas also work with lookup relationships.
Thanks.
-
Gourav
MemberOctober 3, 2016 at 12:56 pm in reply to: How to upload multiple attachments from Salesforce apex? please provide me some sample codeHi Tanu,
You can create an VF page to insert multiple attachments. Try this link to get more information according your requirement.
http://forceguru.blogspot.in/2012/12/uploading-multiple-attachments-into.html
Hope this will help you.
Thanks.
-
Gourav
MemberOctober 3, 2016 at 12:51 pm in reply to: How to open up sharing for old/exising records in system using Salesforce apex code?Hi Tanu,
You can use batch class to share old records with other users e.g if your are try to share Accounts records then you can use AccountShare object which is a standard salesforce object. By this you can share Accounts records with any users who is available in salesforce.
Hope this will help you.
Thanks.
-
Gourav
MemberOctober 3, 2016 at 12:42 pm in reply to: How can we create the dynamic number column in Salesforce visualforce page?Hi Mohit,
What I understand by your question is that you are trying to insert the number in a page block table like Sr.No. If I am understanding it correctly then may this will help you. Try to use apex:variable and then increment that variable in the apex:repeat like below:-
<apex:variable var="rowNum" value="{!0}"/>
<apex:pageBlockTable>
<apex:column headerValue="No">
<apex:variable var="rowNum" value="{!rowNum + 1}"/>
{!rowNum}
</apex:column>
</apex:pageBlockTable>If this is not your requirement then please provide some more details and we can work on that accordingly.
Thanks.
-
Gourav
MemberOctober 3, 2016 at 12:28 pm in reply to: Upto how many changes does track field history kept in salesforce?Hi Pranav,
Hope this will help you.
You can select certain fields(up-to 20 fields) to track and display the field history in the History related list of an object. The field history data is retained for up to 18 months.
There is no limit for changes to record by Field History Tracking.
You can track the field history of custom objects and the following standard objects.
- Accounts
- Articles
- Assets
- Cases
- Contacts
- Contracts
- Contract line items
- Entitlements
- Leads
- Opportunities
- Orders
- Order Products
- Products
- Service Contracts
- Solutions
For more information please go to below mentioned link:-
https://help.salesforce.com/HTViewHelpDoc?id=tracking_field_history.htm
Thanks
-
Gourav
MemberAugust 31, 2016 at 1:06 pm in reply to: How to change background color based on value ?Hi,
Try this code-
<apex:outputText value="{!o.Textfield}" style="color:{!Case(o.Textfield, 'closed', 'red', 'open ', 'green ','Existing','grey','None')};"/>
-
Gourav
MemberAugust 31, 2016 at 1:05 pm in reply to: How can we know the client IP Address who is accessing a landing page?I'd suggest using an external service to retrieve the client IP address. There are plenty of them out there but ipify.org looks suitable as it's super lightweight, it doesn't have any rate limiting and supports both IPv4 and IPv6 addresses.
Simply use:
<p>Your IP address is: %%=HTTPGet('https://api.ipify.org')=%%</p>
Which displays:
Your IP address is: 136.147.128.12
CloudPages
While this should work on a landing page, it doesn't appear to work on a CloudPage as it appears that the CloudPage CDN is making a reverse proxy request and displays an IP address used by the data center hosting the CloudPage, and not the client IP.If you are using landing pages (available on earlier accounts) then you should be fine, but CloudPages won't work and I can't come up with a solution for this. I've tried using SSJS, and:
HTTPHeader.GetValue("Host");
Will return the Host value in the HTTP header, but the following HTTP headers return the same empty value as its HTTPRequestHeader() AMPscript counterpart:
HTTPHeader.GetValue("Forwarded");
HTTPHeader.GetValue("X-Forwarded-For");Solution
As we seem to have exhausted our server-side options for CloudPages, the simplest/only solution would be to:Make a client-side request to retrieve the IP address from ipify.org and display it on your page
Store the IP address in a cookie
Retrieve the cookie using AMPscript.
For purposes of my example, I'm just printing the IP address on the page, but you can use it to update a Data Extension, etc. I'm assuming that you are not adding any other cookies on your page. If you are, then you will need to update the Replace() function accordingly.<script type="text/javascript">
var url = 'https://api.ipify.org';
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState === 4) {
if (request.status === 200) {
document.body.className = 'ok';
document.cookie = 'ipAddress=' + request.responseText;
} else {
document.body.className = 'error';
}
}
};
request.open("GET", url , true);
request.send(null);
</script>%%[
var @ipAddress
set @ipAddress = Replace(HTTPRequestHeader('Cookie'),'ipAddress=','')
]%%<p>IP Address: %%=v(@ipAddress)=%%</p>
-
Gourav
MemberAugust 31, 2016 at 12:56 pm in reply to: How can we make bulk update of record in parallel?@future (valid for triggers and visualforce)
From trigger or VF context you can have up to 10 calls to @future & each of them has a separate context that allows 10 callouts. So you can get up to 100 callouts from a trigger (that itself you're guaranteed will not contain more than 200 records if it's saved with API > 20.0, capped at 100 otherwise) or 10+100 in VF. Not bad. Before you decide to abuse it - consider the fact that there's a 24 hour rolling limit on @future invocations and that multiple callouts to same endpoint might also throw an error. From governor limits page:
A callout request is limited to a maximum of 20 simultaneous requests to URLs with the same host. The host is defined by the unique subdomain for the URL, for example, http://www.mysite.com and extra.mysite.com are two different hosts. This limit is calculated across all organizations that access the same host. If this limit is exceeded, a CalloutException will be thrown.
Batch JobsBatch jobs let you process many records (up to 50 M) with whatever granularity you wish (if you don't specify it, granularity will be 200). Essentially you decide which records you want to work on, you get a fresh context & governor limits for each chunk of data you're processing and then at the end of the batch job you can send an email, kick-off another batch etc. They're great for background processing tasks.
In batch jobs you can specify an optional scope parameter. If you really need this, the batch job may even be instructed to process 1 record at a time (and again - each execute() will let you make 10 callouts). That is - if you'll make sure that the batch class implements Database.AllowsCallouts 😉 Read more about Database.executeBatch if you want to take this path.
Essentially:
public class MyBatchableClass implements Database.Batchable<sObject>, Database.AllowsCallouts{
// definitions of start(), execute() and finish() as in any batch
}// and then in code that fires it (scheduled class? something that happens
// after user clicks a button? you use
Database.executeBatch(new MyBatchableClass(), 1);// instead of
// Database.executeBatch(new MyBatchableClass());
Javascript-related solutionsYou can jump back and forth in the context. Build a Visualforce page that would process N records at a time, return to the browser, issue a next call that processes another N...
You know your data best - N can be a fixed number or maybe you'll just want to compare output ofLimits methods:
if(Limits.getCallouts() == Limits.getLimitCallouts()){
return 'I\'m not done yet';
}
This is best suited in environment where user expects some kind of progress report like "X out of Y records processed". If you're after a fully automated background solution that can't be interrupted by user closing the tab for example - go for one of previous two."The call" can be Javascript that hits Apex code in form of webservice call (in ajax toolkit - for example a button on list view that processes selected records), @RemoteAction , actionFunction etc.
-
Gourav
MemberAugust 31, 2016 at 12:52 pm in reply to: How to change label on custom button based on value in the record being displayed?This can be pulled off, but you need to get crafty here’s one I prepared with pink candy polka dots:
- go to Setup > Create > Objects > [Your Object] > Custom Buttons and Links, and hit New,
- create a Detail Page Button whose behaviour is to Execute JavaScript,
- modify the following JavaScript, using your lowercased button name in lieu of your_button:
(function() {
var button = document.getElementsByName(‘your_button’)[0];
button.style.background = ‘url(“https://addons.mozilla.org/_files/311357/preview_small.jpg”)’;
}()); - use a base64 encoder to format your JavaScript, which we’ll load and execute as a Data URI,
- paste it into the formula, noting the data:application/javascript;base64, prefix:
{!REQUIRESCRIPT(“data:application/javascript;base64,KGZ1bmN0aW9…wZyIpJzsKfSgpKTs=”)}
window.location = ‘/apex/ns__PageName’; //button action when clicked
The usual caveat applies: using a Data URI here may be subject to future validation, but rest assured for now Salesforce support the use of REQUIRESCRIPT in a Custom Button. Your use is only cosmetic.
Further, if you wanted to separate the button click outcome from the pink candy polka dots, you could put the cosmetic JavaScript in a separate Custom Link which you place somewhere on the page layout. It’s one novel way of running JavaScript in the scope of a standard page without needing to configure the sidebar or use a narrow Home Page Component.
Use this approach and made changes accordingly:-
Applying the same trick find the name of the button and the ID of the field that you want to copy over to the button and just replace the name = and j$('#') part in the below jquery 🙂
var j$ = jQuery.noConflict();
j$(document).ready(function(){
//newb = name of the button and #acc2_ileiner = id of the custom field
j$('[name="newb"]').val( j$('#acc2_ileinner').text().replace('[View Hierarchy]', ''));
});I encoded this to base64 and pasted it in my button code:
Note: To use this hack, create a custom detail page button and choose 'Execute JavaScript' for Behavior and 'OnClick JavaScript' for Content Source. In the formula editor for your new button we first need to load some jQuery resources with the following REQUIRESCRIPT lines
Refrence: http://blog.scottmcclung.com/2014/01/hack-together-jquery-modal-popup-in.html
-
Gourav
MemberAugust 31, 2016 at 12:47 pm in reply to: How can we change the color of a custom button?(See description)This can be pulled off, but you need to get crafty 🙂 here's one I prepared with pink candy polka dots:
- go to Setup > Create > Objects > [Your Object] > Custom Buttons and Links, and hit New,
- create a Detail Page Button whose behaviour is to Execute JavaScript,
- modify the following JavaScript, using your lowercased button name in lieu of your_button:
(function() {
var button = document.getElementsByName('your_button')[0];
button.style.background = 'url("https://addons.mozilla.org/_files/311357/preview_small.jpg")';
}()); - use a base64 encoder to format your JavaScript, which we'll load and execute as a Data URI,
- paste it into the formula, noting the data:application/javascript;base64, prefix:
{!REQUIRESCRIPT("data:application/javascript;base64,KGZ1bmN0aW9...wZyIpJzsKfSgpKTs=")}
window.location = '/apex/ns__PageName'; //button action when clickedThe usual caveat applies: using a Data URI here may be subject to future validation, but rest assured for now Salesforce support the use of REQUIRESCRIPT in a Custom Button. Your use is only cosmetic.
Further, if you wanted to separate the button click outcome from the pink candy polka dots, you could put the cosmetic JavaScript in a separate Custom Link which you place somewhere on the page layout. It's one novel way of running JavaScript in the scope of a standard page without needing to configure the sidebar or use a narrow Home Page Component.
-
Gourav
MemberAugust 26, 2016 at 11:17 am in reply to: How can we create a Time Based Assignment Rule by alternative way?Hi Mohit,
Create one custom formula field and populate the value in formula field based on your requirement.Use this field in assignment rule and fire the assignment rule.
I think it may be helpful.
-
Gourav
MemberAugust 26, 2016 at 11:12 am in reply to: How to enable service contract object in salesforce?Hi Pranav,
These are the steps to enable service contract sObject.
Steps:-
- Give permission to user
- Manage Entitlements
- Customize Application
- Customize service contract fields. (This lets you control what information users add to service contracts. You can create custom service contract fields that are specific to your industry or support process.)
- Customize service contract page layouts. (This lets you specify which fields and related lists users see on service contracts. Consider making the following customizations:
1. Add the Status Icon field so users can easily see whether the service contract is active, expired, or inactive.
2. To let users make one service contract the parent of another, add the Parent Service Contract field and Child Service Contracts related list. You can also add the read-only Root Service Contract field so users can see the top-level service contract in a service contract hierarchy.) - Set field-level security on service contract fields. (This lets you choose which service contract fields users can access.)
- Set field history tracking on service contracts. (This lets you see when field values were changed. Changes are listed in the Service Contract History related list on service contracts. From the object management settings for service contracts, go to the fields section, and then click Set History Tracking.)
- Make the Service Contracts tab visible in Salesforce and any custom apps. (The Service Contracts tab is where users create and edit service contracts and contract line items. Add the tab to an app or instruct your users to add it to an existing tab set in Salesforce. Users need the “Read” permission on service contracts to see the Service Contracts tab.)
- Add the Service Contracts related list to account and contact page layouts. (This lets users create, update, and verify service contracts from accounts and contacts.)
Hope this will help you.
- This reply was modified 8 years, 2 months ago by Gourav.
- Give permission to user
-
Gourav
MemberAugust 26, 2016 at 10:25 am in reply to: How to hide standard field when it has a particular value?Hi Pranav,
You can do this by configuration. Create one record type for each possible phase, and restrict picklist values based on the record type. You can then use workflow rules to change record types when the value changes.
-
Gourav
MemberAugust 26, 2016 at 10:17 am in reply to: How can we delete an user from org ? Is unchecking active box is the only way to manage the user limit in developer org ?Hi Pranav,
Yes, we cann't remove Users from salesforce org. We just Active or Inactive the User as per our need. Salesforce only count the active user to check the limit of user. So inactive Users doesn't affect org user limits.
-
Gourav
MemberAugust 26, 2016 at 10:14 am in reply to: How can we write a trigger for before and after DML operation?Apex can be invoked by using triggers. Apex triggers enable you to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions.
A trigger is Apex code that executes before or after the following types of operations:- insert
- update
- delete
- merge
- upsert
- undelete
For example, you can have a trigger run before an object's records are inserted into the database, after records have been deleted, or even after a record is restored from the Recycle Bin.
You can define triggers for top-level standard objects that support triggers, such as a Contact or an Account, some standard child objects, such as a CaseComment, and custom objects. To define a trigger, from the object management settings for the object whose triggers you want to access, go to Triggers.
There are two types of triggers:
- Before triggers are used to update or validate record values before they’re saved to the database.
- After triggers are used to access field values that are set by the system (such as a record's Id or LastModifiedDatefield), and to affect changes in other records, such as logging into an audit table or firing asynchronous events with a queue. The records that fire the after trigger are read-only.
Sample Trigger:-
trigger <Trigger Name> on <sobject> (<events>) {
if(Trigger.<event>){
//Your code logic
}else if(Trigger.<event>){
//Your code logic
}
} -
Gourav
MemberAugust 26, 2016 at 10:06 am in reply to: What will happen if trigger which causes a workflow rule to fire and then goes in a loop. Will it terminate after some update or events ?Hi Mohit,
One workaround is to set a private static variable in a global class so it works as a flag, not avoiding the trigger fires twice instead it avoids overpassing the limits.
Something like this. Create a Validator Class:
global class Validator_cls{ private static boolean blnAlreadyDone = false; public static boolean hasAlreadyDone(){ return blnAlreadyDone; }
public static void setAlreadyDone() {
blnAlreadyDone = true;
} }In the trigger include a line like this one:
trigger OpportunityTrigger_tgr on Opportunity (before insert, before update) { if(!Validator_cls.hasAlreadyDone()){ // Your trigger code here Validator_cls.setAlreadyDone(); } }
So, when the trigger is fired by the first time it sets the flag in true and at the second time it won't pass again over the executed code.