Tuesday, December 29, 2015

Change your life

Hello Friends,

MMM global is a community of common people where we help each other to make all our feature better to build a better world for our family & children .

I have found MMM Global is the easiest way for my financial freedom with lots of hesitation & thought I started MMM when I saw one my known friend is doing good .

I have a brief discussion with my friend Raju understand what MMM is how it work how I will be benefited.

Please note MMM is a helping community it is not a earning machinery or stock market or bank where you should join with your spare money as you might loose .

With MMM extra your money can grow up to  1005 per month .

If you want to join us click here  if the link does not  work go to https://mmmglobal.org/?i=sfon  #MMMGlobal #MMMExtra #Bitcoin #news

Friday, December 11, 2015

Dealing with multiple JQUERY load and avoiding conflict with bootstrap

Hello Everyone.

Today I faced CSS and JQUERY confident issue very badly. I have to use JQUERY week calender which run under jquery 1.4 and have to use bootstrap3 now the catch is bootstrap need a higher version of jquery to run .

How i resoled the above problem . after doing lots of research and search in stack overflow I found the solution

1) For JQUERY CONFLICT :

<script src="jquery1" />

<script src="jquery2" />
<script>
jQuery.noConflict();
</script>

Now where ever you are using bootstrap use 


<script>

jQuery(".class").fun();
</scrirt>

2) The CSS conflict . 


Wrap bootstrap CSS with name space .


Click here to see the live demo Here.


like this 


#bootstrap {

  /*!
 * Bootstrap v3.0.0
 *
 * Copyright 2013 Twitter, Inc
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Designed and built with all the love in the world by @mdo and @fat.
 */

  /*! normalize.css v2.1.0 | MIT License | git.io/normalize */


}

#bootstrap article,
#bootstrap aside,
#bootstrap details,
#bootstrap figcaption,
#bootstrap figure,
#bootstrap footer,
#bootstrap header,
#bootstrap hgroup,
#bootstrap main,
#bootstrap nav,
#bootstrap section, ....


<div class="content">
    <div id="bootstrap">
        <h1>Header 1</h1>
        <h2>An example of styles using bootstrap.</h2>
        <h3 class="text-muted">It's not pretty, but it works.</h3>
        <a href="#" class="btn btn-primary">Button</a>
        <br></br>
        <p>Notice how the markup in this div is not inheriting from the user's custom CSS.</p>
    </div>
    <hr></hr>
    <div id="Preview">
        <!-- Start Html Template -->
        <style>
            .user > h1 {color: red;}
            .user > h2 {color: blue;}
            .user > h3 {font-size: 40px;}
            .user > .btn {margin-top: 24px; background-color: red;}
        </style>
        <div class="user">
        <h1>Header 1</h1>
        <h2>An example of styles NOT using bootstrap.</h2>
        <h3 class="text-muted">It's a bit more work, but it gets the job done</h3>
        <p>Notice how the user's markup has the same classes as bootstrap, but they're not inheriting from it.</p>
        <a href="#" class="btn btn-primary">Button.</a>
        <!-- End Html Template -->
    </div>

</div>

:) Happy coding 
  

Wednesday, October 28, 2015

Reset user password from APEX in case of user lockout

With winter 16 we have issue with password lockout when we have two factor enabled

Click here to see the issue

We are experiencing so many lockouts so I came up with this 

global class scheduledPasswordReset implements Schedulable {

 global void execute(SchedulableContext SC) {
Set<String> Ids = new Set<String>();
Set<String> LockIds = new Set<String>();
for (LoginHistory l : [SELECT UserId,LoginTime, status FROM LoginHistory WHERE LoginTime = TODAY ORDER BY LoginTime DESC  ]){
if(!Ids.contains(l.userId)){
Ids.add(l.userId);
if(l.status == 'Password Lockout'){
LockIds.add(l.userId);
}
}
}
system.debug('### '+LockIds);
for(String uId : LockIds){
 System.resetPassword(uId, true);
}

   }

}

Friday, September 11, 2015

@chatter Mention user

Hello everyone after the version 31 below methods are no longer available 

ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null, ConnectApi.FeedType.News, userId);


So how we can do @mention now . see sample code below how to do that .


// Method that takes the list sobject as  parameter and post 


    public static void postOnChatter(List<Sobject> Items){

        List<ConnectApi.BatchInput> batchInputs = new                      List<ConnectApi.BatchInput>();
Integer MAXSIZE = 10 ;// Select Your size
        for (Sobject item : Items) {
            //  initialize the FeedItemInput
            ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
            input.subjectId = item.Id;
            
            // initialize the body of the chatter post
            ConnectApi.MessageBodyInput body = new ConnectApi.MessageBodyInput();
            body.messageSegments = new List<ConnectApi.MessageSegmentInput>();
            
            // add the mention to the post
            ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
            mentionSegment.id = item.OwnerId;
            body.messageSegments.add(mentionSegment);
            
            // add the text containing the Product Name and the tracking information
            ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
            textSegment.text = 'Sample Text';
            body.messageSegments.add(textSegment);
            
            input.body = body;
            ConnectApi.BatchInput batchInput = new ConnectApi.BatchInput(input);
            
            // add the FeedItemInput instances to a list
            batchInputs.add(batchInput);
            
            // postFeedElementBatch() method can process maximum of 500 feeds at a time
            // if the feeds are 500, post them and re-instantiate the list
            if(batchInputs.size() == MAXSIZE){
                ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), batchInputs);
                batchInputs = new List<ConnectApi.BatchInput>();
            }
        }
        // post the feeds  in the list
        if(batchInputs.size() > 0)
            ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), batchInputs);
    }

Wednesday, March 4, 2015

Keep alive your debug logs without manual refresh in Salesforce

Hello Everyone,

I felt this urge to write such thing because I have to monitor log in salesforce for performance testing being a lazy person J I don’t want to do it by keeping my eye on developer console. So I found this trick it might be helpful to you as well

Here goes the code !!!

Apex Class

/**
* This class will create debug log instances for users 
**/ 
public class LogResetController {
    public List<String> userIds {get;set;} //will hold the user ids 
    public List<String> userNames {get;set;} // will hold the user names used in soql
    Public Integer counter {get;set;} {counter = 0;}
    public Boolean isFstLoad {get;set;} { isFstLoad = true;}
    /**
* controller of the class initialize your user name list here  
**/
    public LogResetController(){    
        //initialise list of users here and call initpage();
        userNames = new List<String>();        
       //addition of users for those you want log to be enabled 
       userNames.add('test@test.com'); 
        initPage();
    }
    public void initPage(){
        // getting the users 
        List<User> users = [SELECT ID FROM USER WHERE USERNAME IN:userNames AND isActive = true];
        // creating list of ids this can be omitted i did it for ease of use on the page 
        userIds = new List<String>();
        for(User u : users){
            userIds.add(u.Id) ;
        }
    }
    public void dummyAction(){
        // this will be called from vf page action poller to re-initiate the debug log 
        counter++;
        isFstLoad = false;
    }
    public void ResetAction(){
        isFstLoad = true;
    }
}

Visualforce Page

<apex:page sidebar="false" showHeader="false" controller="LogResetController">
    <style>
    #loadingMessage {
   width: 100%;
   height: 100%;
   z-index: 1000;
   top: 50%;
   left:50%;
   position: absolute;
   background-repeat: no-repeat !important;

    </style>
    <script>
    var openWindows= new Array();
    </script>
    <apex:form id="mainform">
        <apex:actionFunction name="resetPage" action="{!ResetAction}" reRender="mainform" />
        <apex:repeat value="{!userIds}" var="u" rendered="{!isFstLoad}">
            <script>
                var user = '{!u}' ;
                var url = '/setup/ui/listApexTraces.apexp?user_id='+ '{!u}'+ '&user_logging=true';               
                var win = window.open(url);
                openWindows.push(win);
                console.log("************* Pushing ***************");
            </script>
        </apex:repeat>
        <apex:actionPoller action="{!dummyAction}" interval="20" reRender="mainform"> 
            <apex:outputPanel id="counterPanel">
            <div id="loadingMessage">
                    <img src="/img/loading32.gif" title="/img/loading32.gif"/>
                    <br/>
                    <div style="font-size:20px;margin-left:-60px;color:red">
                        Counter Value is : {!counter}
                    </div>
                </div>
            </apex:outputPanel>
        </apex:actionPoller>
        <apex:outputPanel id="refreshPanel">
            <apex:outputPanel rendered="{!NOT(isFstLoad)}">
                <apex:outputLabel > Refreshing .....</apex:outputLabel>
                <script>
                try{
                    for(var index = 0 ; index < openWindows.length ; index++){
                        console.log(" **************** CLOSING *********************** " + index );
                        openWindows[index].close();                           
                    }
                    openWindows= new Array();
                    resetPage();
                }
                catch(err){
                    console.log(err);    
                }
                </script>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:form>
</apex:page>


Test Class




@istest
public class LogResetControllerTest {
    private static testMethod void unitTest(){
        User U = [Select Id,UserName From User WHERE Id =: userInfo.getUserId()];
        Test.startTest();
        LogResetController con = new LogResetController();
        con.userNames = new List<String>();
        con.userNames.add(U.UserName);
        con.initPage();
        con.dummyAction();
        Test.stopTest();
        System.assertEquals(con.userIds.size(), 1);
    }

}

Tuesday, January 6, 2015

Intercommunication between parent and child window ( IFRAME and window.open)

I will show you how you can communicate between browser windows. We already know we can access it via parent. method but there is another way of doing it . 
parent.html
<html>
This is parent page 
<iframe src="childIframe.html" id="frame1" />
<script>
window.open("child.html");
function callParent(){
alert(" I am at parent");
// accessing child element of iframe make sure iframe loaded completely before you call this                          // will hide the div form the lunched window 
$($("#frame1").contents().find("#sampleDiv")).hide();  
}
</script>

</html>

child.html
<html>
This is child 
<script>
window.opener.callParent(); // accessing parent 
</script>
</html>

childIframe.html

<html>
This is a Iframe
<div id = "sampleDiv"> Hello </div>
</html>

Tips on passing Salesforce AI Associate Certification

  🌟 Motivation to Pursue the Salesforce AI Associate Certification 🌟 The world of technology is in a state of perpetual evolution, and on...