Browse Author: kalpesh.surana

Lightning Pages vs VF Pages

Lightning is available in GA from this release .You can ofcourse approach via lightning .Some of the things you need to be extra careful are here

1)No router support in lightning yet and hence its extremely difficult designing navigation at this point .You will end up writing lot of code just to achieve navigations

2)Custom lookups you can get from developerforce blogs

3)Toggling visibility is not so difficult

4)Supporting jquery in lightning is possible but you need to be careful when using this and would recommend to use less as possible

5)Spinning a list is not so difficult with excellent repeater .

6)Currently to make experience seamless lightning expereince also needs to be turned on for all your users .

Since there will be additional learning and experimenting take decision based on budget and time lines .

Building in lightning is like giving awesome quality work with lot of resusable at cost of little more time .

‘Immediate’ attribute for commandbutton and commandlink in VF page

This is basically used when we don’t want our validation rules to be fired during any server request.
It is a Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.
We generally use it to make functionality of ‘Cancel’ button or ‘Back to Page’ button, where we don’t want validation rule to get executed. If we don’t use immediate=true then on click of cancel button also, validation rules will get executed.

—————————————— VF Page ————————————————-

<apex:form >
      <apex:pageBlock >
      <apex:pageBlockButtons location="both">
                  <apex:commandButton value="Save" action="{!saveAccount}"/>
                  <apex:commandButton value="Cancel" immediate="true" action="{!cancelPage}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection >
             <apex:inputField value="{!account.name}"/>
             <apex:inputfield value="{!account.Type}" required="true"/>
      </apex:pageBlockSection>
      <apex:outputText value="Account Added" rendered="{!isAdded}"/>
      <apex:outputText value="Account Not Added" rendered="{!isCancel}"/>
      </apex:pageBlock>
 </apex:form>

—————————————– Controller ———————————

public with sharing class AccountExtension {
public Boolean isAdded{get;set;}
public Boolean isCancel{get;set;}
public AccountExtension(ApexPages.StandardController controller) {
isAdded = false;
isCancel = false;
}
public pagereference cancelPage(){
isAdded = false;
isCancel = true;
return null;
}

public pagereference saveAccount(){
isAdded = true;
isCancel = false;
return null;
}
}

Showing Google Maps on Standard & Custom Visualforce Pages in Salesforce

//Write this code under VF page

<img src=”{!mapImage}” class=”mapimg”/>

 

//Write this code under Apex Class

public string mapImage {get; private set;}

http://maps.googleapis.com/maps/api/staticmap?center=’+Address__c+’&zoom=15&size=250×250&maptype=roadmap&markers=color:Red%7Clabel:A%7C’+Address__c+’&sensor=false

——————————————————————–

Where Address__c => Field which hold Address in Text type

Why pay more for paper-writing services than you get to? BestEssay.com understands that students get special budgets to exercise with. research paper note taking based Be deliberate of binge that you receive on the ordinary WWW. Finally you will towards sure turn garbled

How to generate dynamic queries in apex for sObjects & fields

//return a dynamic Query string that includes all the direct sObject fields and the related Name fields from the parent objects
//dependent method of getSobjects
//TODO: move this into platform wide sobject utils class as it is not domain specific
public static String getBaseQuery(String objName, List<String> customFields)
{
// get the describe info for the org, object and its fields
Map<String,Schema.SObjectType> orgMap = Schema.getGlobalDescribe();
Schema.SObjectType sObjType = orgMap.get(objName);
Schema.DescribeSObjectResult sObjDescribe = sObjType.getDescribe();
Map<String, Schema.SObjectField> sObjFieldMap = sObjDescribe.fields.getMap();
List<Schema.SObjectField> sObjFieldList = sObjFieldMap.values();
//build out the base soql query using the describe info
String soqlQuery = ‘SELECT ‘;
for(Schema.SObjectField sObjField : sObjFieldList)
{
String fieldLabel = sObjField.getDescribe().getLabel();
String fieldName = sObjField.getDescribe().getName();
String fieldType = String.valueOf(sObjField.getDescribe().getType());
String relationshipName = sObjField.getDescribe().getRelationshipName();
System.debug(‘>>>>>>>>>>>>>>>>>>>> Label = ‘ + fieldLabel + ‘ Name = ‘ + fieldName + ‘ Type = ‘ +
fieldType + ‘ relationshipName = ‘ + relationshipName);
// add each field to the base soql query
soqlQuery += ‘ ‘ + fieldName + ‘,’;
// if this is a lookup field, also include the name field of the parent
if((‘REFERENCE’.equalsIgnoreCase(fieldType) == true) && ((relationshipName != null) && (relationshipName.length() > 0)))
{
// add the name field from the parent object to the base soql query
soqlQuery += ‘ ‘ + relationshipName + ‘.Name,’;
}
}
// add additional custom fields specified in the call to the base soql query
if((customFields != null) && (customFields.size() > 0))
{
for(String customField : customFields)
{
soqlQuery += ‘ ‘ + String.escapeSingleQuotes(customField) + ‘,’;
}
}
// remove the last comma from the base query
soqlQuery = soqlQuery.subString(0, soqlQuery.length() – 1);
// add the from clause to the base query
soqlQuery += ‘ FROM ‘ + objName + ‘ ‘;
//return the dynamic base soql query string
return soqlQuery;
}

How to get picklist values for fields in apex salesforce

//get all picklist option values using the type of sobject and specific picklist field
//TODO: move this into platform wide sobject utils class as it is not domain specific
public static List<String> getPickListValues(String objectName, String fieldName)
{
try
{
List<String> pickListValuesList = new List<String>();
sObject sObj = Schema.getGlobalDescribe().get(objectName).newSObject();
Schema.sObjectType sObjType = sObj.getSObjectType();
Schema.DescribeSObjectResult sObjDescribe = sObjType.getDescribe();
Map<String, Schema.SObjectField> sObjFieldMap = sObjDescribe.fields.getMap();
List<Schema.PicklistEntry> sObjPickListEntryList = sObjFieldMap.get(fieldName).getDescribe().getPickListValues();
System.debug(‘>>>>>>>>>>>>>>>>>>>> sObjPickListEntryList for ‘ + objectName + ‘:’ + fieldName + ‘ = ‘ + sObjPickListEntryList);
for(Schema.PicklistEntry sObjPickListEntry : sObjPickListEntryList)
{
pickListValuesList.add(sObjPickListEntry.getLabel());
}
return pickListValuesList;
}
catch(exception e)
{
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,
‘Unable to find setup information for the field ‘ + objectName + ‘.’ + fieldName +
‘. Please contact your system administrator.’);
ApexPages.addMessage(msg);
System.Debug(‘>>>>>>>>>>>>>>>>>>>> Exception in IPA_Utils.class:’ + msg + ‘(‘ + e.getMessage() + ‘)’);
return null;
}
}

How to read & check permissions of profiles in apex salesforce

public with sharing class IPA_MyAppsComponentController
{
//Member Var
public list myApps {get; private set;}
private static ID userId;
private static ID profileId;
private List myPermSetAsgmnts = new List();
private List profilePermSetAsgmnt = new List();
private Set permSetIds = new Set();
private List appList = new List();
private Set appIds = new Set();
public IPA_Page_Widget__c pageWidgetObj {get; set;}
public String Widget_title {get; set;}

//Constructor
public IPA_MyAppsComponentController() {

USERID = UserInfo.getUserID();
myPermSetAsgmnts = [SELECT PermissionSetId
FROM PermissionSetAssignment
WHERE AssigneeId = : userId];
PROFILEID = UserInfo.getProfileId();
if(!myPermSetAsgmnts.isEmpty()){
for(PermissionSetAssignment permSetAsgmnt : myPermSetAsgmnts){
permSetIds.add(permSetAsgmnt.PermissionSetId);
}
}
profilePermSetAsgmnt = [Select Id
FROM PermissionSet
WHERE ProfileId = : PROFILEID];
if(!profilePermSetAsgmnt.isEmpty()){
for(PermissionSet permSet : profilePermSetAsgmnt){
permSetIds.add(permSet.Id);
}
}
if(!permSetIds.isEmpty()){
appList = [SELECT SetupEntityId
FROM SetupEntityAccess
WHERE SetupEntityType in (‘TabSet’,’ConnectedApplication’) AND ParentId = : permSetIds];
if(!appList.isEmpty()){
for(SetupEntityAccess app : appList){
appIds.add(app.SetupEntityId);
}
}
}
}
}

How to get your Salesforce Apps List in Apex

// To get list of apps assigned to logged in user

public with sharing class IPA_MyAppsComponentController
{
//Member Var
public list<AppMenuItem> myApps {get; private set;}
private static ID userId;
private static ID profileId;
private List<PermissionSetAssignment> myPermSetAsgmnts = new List<PermissionSetAssignment>();
private List<PermissionSet> profilePermSetAsgmnt = new List<PermissionSet>();
private Set<ID> permSetIds = new Set<ID>();
private List<SetupEntityAccess> appList = new List<SetupEntityAccess>();
private Set<ID> appIds = new Set<ID>();
public IPA_Page_Widget__c pageWidgetObj {get; set;}
public String Widget_title {get; set;}

//Constructor
public IPA_MyAppsComponentController() {

USERID = UserInfo.getUserID();
myPermSetAsgmnts = [SELECT PermissionSetId
FROM PermissionSetAssignment
WHERE AssigneeId = : userId];
PROFILEID = UserInfo.getProfileId();
if(!myPermSetAsgmnts.isEmpty()){
for(PermissionSetAssignment permSetAsgmnt : myPermSetAsgmnts){
permSetIds.add(permSetAsgmnt.PermissionSetId);
}
}
profilePermSetAsgmnt = [Select Id
FROM PermissionSet
WHERE ProfileId = : PROFILEID];
if(!profilePermSetAsgmnt.isEmpty()){
for(PermissionSet permSet : profilePermSetAsgmnt){
permSetIds.add(permSet.Id);
}
}
if(!permSetIds.isEmpty()){
appList = [SELECT SetupEntityId
FROM SetupEntityAccess
WHERE SetupEntityType in (‘TabSet’,’ConnectedApplication’) AND ParentId = : permSetIds];
if(!appList.isEmpty()){
for(SetupEntityAccess app : appList){
appIds.add(app.SetupEntityId);
}
}
}
myApps = [SELECT Id, Label, Description, StartUrl, LogoUrl, IconUrl
FROM AppMenuItem
WHERE IsDeleted = false AND Id = : appIds
ORDER BY SortOrder];
}

public void getfetchContents()
{
Widget_title = pageWidgetObj.Display_Label__c;
}
}

How to add/remove member to Chatter Group in Apex Salesforce

public pagereference addMembersInGroup()
{

public Map<String,String> options = new Map<String,String>();

public Map<String,Id> groupsNmembers = new Map<String,Id>();

try{
ConnectApi.ChatterGroupPage groupPage = ConnectApi.ChatterGroups.getGroups(communityId);
for (ConnectApi.ChatterGroupDetail grp : groupPage.groups) {
options.put(grp.Name,String.valueOf(grp.myRole));
groupsNmembers.put(grp.Name,grp.Id);
}
}catch(Exception ex){}
ID userId = UserInfo.getUserId();

if(options.get(ChatterGroupName) == ‘NotAMember’)
{
// Add member
CollaborationGroupMember groupMember = new CollaborationGroupMember();
groupMember.memberid = userId;  //id of User you wish to add
groupMember.CollaborationGroupId = chatterGroupId;
insert groupMember;
}

if(options.get(ChatterGroupName)==’StandardMember’)
{
// Remove member
CollaborationGroupMember groupMemberDel = [select Id, MemberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroupId AND MemberId =: UserInfo.getUserId() limit 1];
delete groupMemberDel;
}
}

 

————————————————

Where communityId => Use either the ID for a community, internal, or null.

chatterGroupId => ID of the associated CollaborationGroup.

How to get Chatter Feeds using ConnectApi in Apex Salesforce

public List<ConnectApi.FeedItem> getFeedItems()
{
List<ConnectApi.FeedItem> lst = new List<ConnectApi.FeedItem>();

if(!istest)
{
try
{
lst = ConnectApi.ChatterFeeds.getFeedItemsFromFeed(communityId, ConnectApi.FeedType.Record, chatterGroupId).items;
}
catch(Exception ex) { }
}

return lst;
}

 

———————————————–

Where communityId => Use either the ID for a community, internal, or null.

chatterGroupId => ID of the associated CollaborationGroup.

How to get members of Chatter Group in Apex Salesforce

public list<CollaborationGroupMember> returnChatterGroupMember(String chatterGroupId)
{
list<CollaborationGroupMember> groupMemberDel;
groupMemberDel = [select Id, MemberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroupId];
return groupMemberDel;
}

——————————————————————————

Where chatterGroupId => ID of the associated CollaborationGroup.

  • 1
  • 2

Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box