Vikas Kumar
IndividualForum Replies Created
-
Vikas Kumar
MemberJanuary 23, 2017 at 10:22 am in reply to: How can I make my own debug using Visualforce page / javascript in salesforce?Hi Mohit,
Visualforce pages work like this. The browser makes a request and Salesforce uses Visualforce tags to generate HTML/CSS/JavaScript that is sent back to the browser. Most communication is in a simple text format so can be looked at. The browser builds a DOM (Document Object Model - an in-memory tree) from the response and renders that onto the screen guided by the CSS (for colors, positioning, size etc). Any JavaScript included can then respond to user actions such as mouse clicks to modify the DOM or call back to Salesforce (e.g. to get more data).
The first few debugging techniques to use are:
When you right-click over a point in a page and select Inspect Element, you get the DOM Element shown and the CSS styles that apply shown. This lets you see what HTML/CSS/JavaScript has resulted from your Visualforce.
If you then click on the Network tab, and click on a link or button in the current page, you will see the list of requests made to build the new page. If you click on any one of the listed requests, you will see details of the request and response header and body text. This is helpful when debugging rerender problems.
If you then click on the Console tab, and click on a link or button in the current page, you will see any errors in the execution of any JavaScript. If the new page has JavaScript that responds to user interactions such as clicks, when you do the click you will see any errors in that click handling JavaScript. You can add debug statements to your JavaScript that appear in this console with e.g. console.log('index is ' + i). If you are adding your own JavaScript, this tab is a huge help.
The full set of debugging features in current browsers is very powerful and includes things like JavaScript breakpoints. So if your page doesn't work there is a lot you can do to get hold of the information you need to figure out the problem. -
Vikas Kumar
MemberJanuary 23, 2017 at 10:19 am in reply to: How to create a salesforce partner community user in test class?Hi Tanu,
Below is the code for creating user in the test Method for the Partner Community
Id p = [select id from profile where name='Partner Community User'].id;
Account ac = new Account(name ='Grazitti') ;
insert ac;Contact con = new Contact(LastName ='testCon',AccountId = ac.Id);
insert con;User user = new User(alias = 'test123', email='[email protected]',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p, country='United States',IsActive =true,
ContactId = con.Id,
timezonesidkey='America/Los_Angeles', username='[email protected]');insert user;
system.runAs(user) {
// statements to be executed by this test user.
} -
Vikas Kumar
MemberJanuary 23, 2017 at 10:18 am in reply to: How can we get the static resources dynamically in visualforce page in salesforce?Hi Mohit,
You can get the URL using the following util class.
public class StaticResourceURL
{
// Pass the resource name
public static String GetResourceURL(String resourceName){// Fetching the resource
List<StaticResource> resourceList= [SELECT Name, NamespacePrefix, SystemModStamp FROM StaticResource WHERE Name = :resourceName];// Checking if the result is returned or not
if(resourceList.size() == 1){// Getting namespace
String namespace = resourceList[0].NamespacePrefix;
// Resource URL
return '/resource/' + resourceList[0].SystemModStamp.getTime() + '/' + (namespace != null && namespace != '' ? namespace + '__' : '') + resourceName;
}
else return '';
}
}for more info Go through
http://forceguru.blogspot.in/2012/05/static-resource-url-in-apex.html
-
Vikas Kumar
MemberJanuary 23, 2017 at 10:12 am in reply to: In Salesforce, how is URI used in REST API?Hi sushant,
URL mapping is used to expose your APEX class as a REST resource.
These are some considerations when using this annotation:
The URL mapping is relative to https://instance.salesforce.com/services/apexrest/.
A wildcard character (*) may be used.
The URL mapping is case-sensitive. A URL mapping for my_url will only match a REST resource containing my_url and not My_Url.
To use this annotation, your Apex class must be defined as global.
For more info regarding path mapping guidelines and what happens when the request URI is not the same, go to this link.- This reply was modified 7 years, 11 months ago by Vikas Kumar.
-
Vikas Kumar
MemberJanuary 23, 2017 at 8:10 am in reply to: Lightning Connect: Is it possible to create activities for external object?Hi Tanu,
.Only Meta data is stored and not the data. Data will be fetched in real time from external data source.
2. Activities are not available.
3. Currently reporting is not available and data is Read-only, read/write capability is not available in this release.
4. please contact your Account executive (AE) for licensing.Thanks
-
Vikas Kumar
MemberJanuary 23, 2017 at 8:07 am in reply to: What are bucket fields in Salesforce reports and how can we use it?Hi Pranav,
Bucketing lets you quickly group report records without creating a formula or a custom field. For example, say you also want to group by quantity into ranges. To do this, create a bucket field on Quantity and define the ranges.First, create a bucket field based on Quantity with ranges for small, medium, and large. You'll use the bucket field to create the grouping.
For more details
Go through:- https://developer.salesforce.com/docs/atlas.en-us.workbook.meta/workbook/reports_3.htm
-
Vikas Kumar
MemberJanuary 23, 2017 at 8:02 am in reply to: In Salesforce, When to use {#v.attrib} vs {!v.attrib}?Hi Tanu,
If you want to show a value dynamically based on a aura:attribute, generally we tend to use: {!v.attrib}
Eg: <ui:button label="{!v.attrib}" />
So if you do cmp.set('v.attrib','test'), then aura:framework automagically does an dirty checking and changes the value accordingly.(Two-way binding)
So the label of the <ui:button> is set to test, just think of this as special expression that directly point to the live reference of the attribute in the component(JS perspective), which is quiet similar to {{v.attrib}} expression in Angularjs which eventually does the same thing.
What if you want to show a value dynamically based on a aura:attribute but it needs to work only once,when it is rendered in the view initially.
So you should go with : {#v.attrib} expression, which might improve the performance if there large no.of such expression(where you don't need such bindings), because it won't be taken into account during dirty checking.AngularJS also has the same one-way binding stuff in its armour : {{::v.attrib}}
-
Vikas Kumar
MemberJanuary 23, 2017 at 7:56 am in reply to: Why am I facing Internal Salesforce.com Error in Salesforce?Hi Chinna Sfdc,
Can you share your batch then only we can able to rectify the error?
Thanks
-
Vikas Kumar
MemberJanuary 23, 2017 at 7:52 am in reply to: In Salesforce, How to use "force:inputField" and "force:outputField" inside an "aura:iteration"?Hi Tanu,
force:inputField and force:outputField have always been provided the metadata definition of what the sObject was by their containing component
The way to do this is to provide a default value object to the Account attribute, like this:
<aura:attribute name="account" type="Account" default="{ sobjectType: 'Account' }"/>
-
Vikas Kumar
MemberJanuary 23, 2017 at 7:49 am in reply to: How can we stop the refire of the same trigger in salesforce?Hi Mohit,
In this scenario you can use a Boolean Flag put a check condition to fire trigger By default make it false Once the trigger is fired change it to true .
but if you elaborate your problem then it will much easier to provide better solution
thanks
-
Vikas Kumar
MemberJanuary 23, 2017 at 7:38 am in reply to: Why we not allowed to use the DML operation inside a constructor in Salesforce apex class?Hi Mohit,
Constructor is mainly used to initialization of variables. It is not used for doing DML operations.
Salesforce has blocked this due to security issues.
If you want to do DML operation during VF page loading, use action attrirbute in <apex:page>. Call a method from the action in which DML operation is allowed.
-
Vikas Kumar
MemberJanuary 23, 2017 at 7:34 am in reply to: How can I delete activities related to lead through salesforce apex code?Hi pranav ,
you can try something like this
List<Lead> leadList = [SELECT Id FROM Lead ];
for(Task objTask:[Select Id, Subject, WhoId FROM Task WHERE WhoId IN: leadList )
{----Delete related task here-----
----or save it in list and delete at last ----
}
Hope it may Helps
Thanks
-
Vikas Kumar
MemberJanuary 20, 2017 at 2:33 pm in reply to: Using controller methods via Javscript without Action tags in a salesforce visualforce pageHi kumar,
Try the following code
Try the following code
CONTROLLER
public with sharing class SearchJavascriptController {
public list<Account>accountlist { get; set; }
public SearchJavascriptController()
{
accountList = new list<Account>();
accountList =[Select Name,Id,AnnualRevenue From Account];
}}
VF Page
<apex:page controller=”SearchJavascriptController”>
<html>
<head>
<style>* {
box-sizing: border-box;
}#myInput {
background-image: url(‘/css/searchicon.png’);
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}#myTable th, #myTable td {
text-align: left;
padding: 12px;
}#myTable tr {
border-bottom: 1px solid #ddd;
}#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body><apex:form id=”theForm”>
<apex:pageBlock >
<h2>My Account</h2>
<input type=”text” id=”myInput” onkeyup=”myFunction()” placeholder=”Search for names..” title=”Type in a name”>
</input>
</apex:pageBlock>
<table id=”myTable”>
<tr>
<th><h1> ACCOUNT NAME</h1></th>
<th><h1> ACCOUNT ID</h1></th>
<th><h1>ANNUAL REVENUE</h1></th>
</tr>
<apex:repeat value=”{!accountList}” var=”acc” id=”theRepeat”>
<tr>
<td>{!acc.name}</td>
<td>{!acc.id}</td>
<td>{!acc.AnnualRevenue}</td>
</tr>
</apex:repeat>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById(“myInput”);
console.log(input);
filter = input.value.toUpperCase();table = document.getElementById(“myTable”);
tr = table.getElementsByTagName(“tr”);
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName(“td”)[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {tr[i].style.display = “”;
} else {
tr[i].style.display = “none”;
}
}
}
}
</script>
</apex:form>
</body>
</html></apex:page>
-
Vikas Kumar
MemberJanuary 20, 2017 at 2:30 pm in reply to: How can we fetch data without using Controller functions on salesforce VisualForce page?Hi sushant,
Try the following code
CONTROLLER
public with sharing class SearchJavascriptController {
public list<Account>accountlist { get; set; }
public SearchJavascriptController()
{
accountList = new list<Account>();
accountList =[Select Name,Id,AnnualRevenue From Account];
}}
VF Page
<apex:page controller="SearchJavascriptController">
<html>
<head>
<style>* {
box-sizing: border-box;
}#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}#myTable th, #myTable td {
text-align: left;
padding: 12px;
}#myTable tr {
border-bottom: 1px solid #ddd;
}#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body><apex:form id="theForm">
<apex:pageBlock >
<h2>My Account</h2>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name">
</input>
</apex:pageBlock>
<table id="myTable">
<tr>
<th><h1> ACCOUNT NAME</h1></th>
<th><h1> ACCOUNT ID</h1></th>
<th><h1>ANNUAL REVENUE</h1></th>
</tr>
<apex:repeat value="{!accountList}" var="acc" id="theRepeat">
<tr>
<td>{!acc.name}</td>
<td>{!acc.id}</td>
<td>{!acc.AnnualRevenue}</td>
</tr>
</apex:repeat>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
console.log(input);
filter = input.value.toUpperCase();table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</apex:form>
</body>
</html></apex:page>
-
Vikas Kumar
MemberJanuary 20, 2017 at 2:22 pm in reply to: Sharing Javascript between salesforce lightning componentsHi Kumar,
Currently the recommended mechanism for this is to use a Static Resource and include it in any components that need to share the same JavaScript via ltng:require (loads the library once and only once similar to requirejs).
-
Vikas Kumar
MemberJanuary 18, 2017 at 1:53 pm in reply to: Dependent Picklist Values in Salesforce?Hi Kumar,
Define Field Dependencies from your Object Page For that Particular Object
Thanks
-
Vikas Kumar
MemberJanuary 18, 2017 at 1:49 pm in reply to: Fetch Account Records Using Rest Api in Salesforce -
Vikas Kumar
MemberJanuary 18, 2017 at 1:44 pm in reply to: How can I get the custom setting in the salesforce apex test class?Hi Mohit,
Declare your method with the @isTest(SeeAllData=true) that way your testmethod has visility over the data in your database, outside of the test context.
-
Vikas Kumar
MemberJanuary 18, 2017 at 1:34 pm in reply to: Are we at risk of Salesforce race condition in future method?Hi Mohit,
@Future's are queued transactionally along with other DB changes in the trigger transaction, so the future can't be executed until the enqueuing transaction commits. (and conversely, if the trigger transaction never commits due to errors etc, the @future is never executed)
-
Vikas Kumar
MemberJanuary 18, 2017 at 1:29 pm in reply to: How can we schedule class such that it will excute after every 50 mintues?what is the cron expression for every 50 minutes scheduler?Hi Mohit,
Cron expression for scheduling batch in Salesforce
Cron expressionEvery 30 minutes - '0 30 * * * ?'
Every hourly - '0 0 * * * ?'
Every 5 min - '0 5 * * * ?'
Every 10 min - '0 10 * * * ?'
Every 15 min - '0 15 * * * ?'
Every 20 min - '0 20 * * * ?'
Every 25 min - '0 25 * * * ?'
Every 30 min - '0 30 * * * ?'
like upto 55 or 59 your wish
Note: If you schedule your batch for every 5 min '0 5 * * * ?'. It means it will run every hours 5th minute.
It will not run every 5 minutes
If you want to run for every 5 min then you need to schedule 12 times with different different cron expression like for 5 min, 10 min, 15min like upto 60 min..
but you can use below code to schedule your batch for every 5o minutes
global class SelfSchedule implements schedulable
{
global void execute( SchedulableContext SC )
{// do whatever it is you want to do here
SelfSchedule.start();
// abort me and start again
System.abortJob( SC.getTriggerId() );
}public static void start()
{
// start keepalive again in 5 mins
Datetime sysTime = System.now().addSeconds( 3000);
String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
System.schedule( 'SelfSchedule ' + sysTime, chronExpression, new SelfSchedule() );
}}
Hope it may Helps you
thanks
-
Vikas Kumar
MemberJanuary 18, 2017 at 1:14 pm in reply to: Can we enhance the accessibility of our subordinates Roles using Permission Sets in Salesforce?Hi sushant,
yes we can enhance the accessibility of our subordinates Roles using Permission set.Users can have only one profile but, depending on the Salesforce edition, they can have multiple permission sets. You can assign permission sets to various types of users, regardless of their profiles.
Create permission sets to grant access among logical groupings of users, regardless of their primary job function. For example, let’s say you have several users with a profile called Sales User. This profile allows assignees to read, create, and edit leads. Some, but not all, of these users also need to delete and transfer leads. Instead of creating another profile, create a permission set.
-
Vikas Kumar
MemberJanuary 18, 2017 at 1:11 pm in reply to: Testing Outbound messages in Salesforce WorkflowsHi kumar,
In order to check the outbound message just go to endpoint url of your workflow rule, you can able to view your output as SOAP message.
-
Vikas Kumar
MemberJanuary 18, 2017 at 12:06 pm in reply to: 'UseStandardPrice' field of 'PriceBookEntry' object not visible in salesforceHi Kumar,
For the 'UseStandardPrice' checkbox to be visible, you must be adding the product to a custom pricebook .
-
Vikas Kumar
MemberJanuary 16, 2017 at 7:25 am in reply to: Using generic sObject to change fields of different Object types.Hi kumar,
I know this approach is strange because you are still working with a List<SObject>, but when you assign it you can make it more specific (e.g. List<Account>) by using Type.forName and Type.newInstance methods.
public static void dynamicUpsert(List<SObject> records)
{
Schema.SObjectType sObjectType = records.getSObjectType();
if (sObjectType != null)
{
String listType = 'List<' + sObjectType + '>';
List<SObject> castRecords = (List<SObject>)Type.forName(listType).newInstance();
castRecords.addAll(records);
upsert castRecords;
}
}The getSObjectType call may not be completely reliable, especially since some of these records are being inserted and hence won't have ids. For that reason, it is probably better to accept sObjectTypeas an additional parameter instead of trying to determine it on the fly.
public static void dynamicUpsert(List<SObject> records, SObjectType sObjectType)
{
String listType = 'List<' + sObjectType + '>';
List<SObject> castRecords = (List<SObject>)Type.forName(listType).newInstance();
castRecords.addAll(records);
upsert castRecords;
} -
Vikas Kumar
MemberJanuary 16, 2017 at 7:19 am in reply to: How to update multiple sObjects field in a Salesforce Apex batch class?Hi sushant,
you can do something like this
global class TestBatch implements Database.Batchable<sobject>{
global String query;
global String field;
global String value;
global List<id>allObjIds ;
global TestBatch(List<id>allObjectIds){
allObjIds=allObjectIds;
field='Name';
value='ModSEARCHAccount';
}
global Database.QueryLocator Start(Database.BatchableContext BC){
query='SELECT Id,Name FROM Account WHERE Id in:allObjIds';
return Database.getQueryLocator(query);
}
global void execute (Database.BatchableContext BC,List<Sobject>scope){
for(Account obj:scope){obj.put(field,value);
}
update scope;
}
global void finish (Database.BatchableContext BC){//call another batch from here to to update another object says lead or opportunity
}
}Thanks