Tuesday, 21 July 2015

Action Status Rerendering in salesforce vf page

<style>
.custPopup{
    background-color: white;
    border-width: 0px;
    border-radius:10px;
    z-index: 9999;
    left: 50%;
    padding:20px;
    position: absolute;
    /* These are the 3 css properties you will need to change so the popup 
    displays in the center of the screen. First set the width. Then set 
    margin-left to negative half of what the width is. You can add 
    the height property for a fixed size pop up if you want.*/
    margin-left: -100px;
    top:40%;
}
.popupBackground{
    background-color:black;
    opacity: 0.30;
    filter: alpha(opacity = 30);
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 9998;
}
</style>

 <apex:actionStatus id="fetching">
        <apex:facet name="start">
             <apex:outputPanel id="tstpopup">
                    <apex:outputPanel styleClass="popupBackground" layout="block"/>
                    <apex:outputPanel styleClass="custPopup" layout="block">
                        <img src="/img/loading24.gif" style="vertical-align:middle; horizontal-align:middle"/> 
                        <span>Please wait...</span>  
                    </apex:outputPanel>
              </apex:outputPanel> 
        </apex:facet>
    </apex:actionStatus>

<apex:commandButton reRender="fetching"/>

Friday, 17 July 2015

Get related objects or related list object


You can get related objects with function :

public static map<string,string> getRelatedObjects(string masterObjectName){
map<string,string> relatedObjectsMap = new map<string,string>();
list<Schema.Childrelationship> relatedObjectsList = Schema.getGlobalDescribe().get(masterObjectName).getdescribe().getChildRelationships();

for (Schema.Childrelationship  relatedObject : relatedObjectsList) {
if(relatedObject.getChildSObject().getDescribe().isUpdateable()
&&
relatedObject.getChildSObject().getDescribe().getKeyPrefix()!=null
&&
!relatedObject.getChildSObject().getDescribe().isCustomSetting()
&&
relatedObject.getChildSObject().getDescribe().isCreateable()
)
relatedObjectsMap.put(relatedObject.getChildSObject().getDescribe().getName(),relatedObject.getChildSObject().getDescribe().getLabel());
   }
return relatedObjectsMap;
}

Wednesday, 8 July 2015

Remote Function with parameter in apex

Class code


public class MyController {

    @RemoteAction
    public static List<Account> getAccountsList(String userId, String value1, String value2) {
 
        return [SELECT Id FROM Account WHERE  id =: userId];
    }
}

Page Script

<script type="text/javascript">
    var valueTakenFromSomewhere = 'This will be value1 in the remote action';
    var valueTakenFromSomewhereElse = 'This will be value2 in the remote action';

    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyController.getAccountsList}',
        '{!$User.Id}',
        valueTakenFromSomewhere,
        valueTakenFromSomewhereElse,
        'This will be value2 in the remote action',
        function(result, event) {
            if (event.status) {
                //do whatever rendering of the list you want
            } else if (event.type === 'exception') {
                //handle errors
            } else {
                //handle unknown responses
            }
        },
        {escape: true}
    );
</script>