Skip to content

Instantly share code, notes, and snippets.

View msrivastav13's full-sized avatar
🎯
Focusing

Mohith Shrivastava msrivastav13

🎯
Focusing
View GitHub Profile
@msrivastav13
msrivastav13 / OdataApp
Created January 3, 2015 10:56
WCF Data Services make it easy to create an OData service using an ADO.NET Entity Data Model by providing a generic DataService class that is constructed using an ADO.NET Entity Data Model.
//------------------------------------------------------------------------------
// <copyright file="WebDataService.svc.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
/*
@Name : RatingDemoCtrl
@description : The following class consists of logic to upsert the rating for Parent record.This plugin assumes Account has a Junction record where user rating is inserted
*/
public with sharing class RatingDemoCtrl{
public RatingDemoCtrl(){
lstacc=new List<Account>();
lstacc=[Select Id,Name,(Select RatingScore__c from Account_Ratings__r where User__c=:userinfo.getuserID() limit 1) from Account Limit 10];
}
<!--*!
* @version 1.0
*
* A simple yet powerful JQuery star rating plugin that allows rendering
* fractional star ratings
*
* This pulgin is customized from JQuery plugins at http://plugins.krajee.com/star-rating
*
*-->
<apex:page sidebar="false" showHeader="false" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" controller="RatingDemoCtrl">
public class WeatherInfo {
public class Current_observation {
public Image image;
public Display_location display_location;
public Observation_location observation_location;
public Estimated estimated;
public String station_id;
public String observation_time;
public String observation_time_rfc822;
global class WeatherApp implements Process.Plugin {
// The main method to be implemented. The Flow calls this at runtime.
global Process.PluginResult invoke(Process.PluginRequest request) {
// Get the State and City From Flow
String State = (String) request.inputParameters.get('state');
String City = (String) request.inputParameters.get('city');
// Use the API to call and fetch Weather Info
WeatherInfo weatherinformation=new WeatherInfo();
Map<String,List<Contact>> mapIdByList=(Map<String,List<Contact>>)ParentChildMapHelper.buildGeneralisedMap('AccountId',lstsobject);
system.debug('My new Map '+mapIdByList);
trigger ContactTrigger on Contact (after delete, after insert, after undelete,
after update, before delete, before insert, before update) {
if(trigger.isAfter && trigger.isInsert){
Map<String,List<Contact>> mapIdByList=ParentChildMapHelper.buildGeneralisedMap('AccountId',trigger.new);
system.debug(mapIdByList);
}
}
public class ParentChildMapHelper{
public static Map<String,List<sobject>> buildGeneralisedMap(String fieldname,List<Sobject> lstsobject){
Map<String,List<sobject>> mapIdbySobject=new Map<String,List<sobject>>();
for(Sobject s:lstsobject){
if (mapIdbySobject.containsKey((String)s.get(fieldname))){
mapIdbySobject.get((String)s.get(fieldname)).add(s); //tricky part .Here map.get(key) is returning list and we are adding contacts to the list
} else{
List <sobject> lstsobjects = new List <sobject> (); //Initialize list as no key is found before and first time we get key
lstsobjects.add(s);
mapIdbySobject.put((String)s.get(fieldname), lstsobjects);
public class CommunityHelper{
public static String communityId=Network.getNetworkId();
public static ConnectApi.Community getCommunityInfo(){
if(communityId!=null){
return connectapi.Communities.getCommunity(communityId);
}else {
return null;
}
$(function() {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MobileHomeCtrl.fetchallUsers}',
function(result, event){
if (event.status) {
var availableTags = [];
$.each(result,function(){
var obj = new Object();
//match the passed label and returned value to populate the label and value
obj.label = this['FirstName']+' '+this['LastName'];