Friday, September 26, 2014

Package Installation failure Due to Permission Set



Few days back, I faced an issue with installation of my managed package.
But unfortunately Salesforce does not provide proper error message of installation failure.

Installation failure message was :

 (permission_admin) Unable to Access Page
The value of the "{0}" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.



Validation Errors While Saving Record(s)



There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "00D10000000b8uC: VALIDATION_FAILED [PF_permission_admin: Unable to Access Page: The value of the "{0}" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information., permission_siteguestuser: Unable to Access Page: The value of the "{0}" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.]".

Then I contacted salesforce support to get proper reason of installation failure.
I got the exact reason, where we did mistake in permission Set. But these permission are not allowed in managed package, then SFDC allow user to include those wrong setting in package!.

In another blog, I have explained few reason.
Here I'm listing the

1.    Only we can include following permissions and settings
  •     Custom object permissions
  •     External object permissions
  •     Custom field permissions
  •     Custom permissions
  •     Apex class access
  •     Visualforce page access
  •     External data source access
2.    Subscribers can edit permission sets in unmanaged packages, but not in managed packages.
3.    Subscriber clones a permission set or creates one that's based on a packaged permission set, it won't be updated in subsequent upgrades. Only the permission sets included in a package are upgraded.
4.    Standard Object  and User permissions should not be included in permission set in Package.
5.    Also, we  can’t include object permissions for a custom object in a master-detail relationship where the master is a standard object.
6.    Create packaged permission sets that grant access to the custom components in a package, but not standard Salesforce components.
 
In my case , installation failure was due to step-4.
Actually I have included Account, Contact and Lead permission setting in package.

For Detail information please visit

Please visit my another blog, for other salesforce stuffs.

Friday, April 19, 2013

One to One Relationship in Salesforce


We all know about the 1-M && M-M relationship(using junction Object) in salesforce.
Some times we may need 1-1 relationship among two objects.
but Unfortunately Salesforce doesnot allow any direct methodolgy to build 1-1 relationship

We can achieve the same by workflow or trigger. But workflow is more flexible & the easier way

Steps
-------
Say Two Objects OBJECT-A and OBJECT-B

1- create a look up field in one object
    say in OBJECT-A, there is a lookup to OBJECT-B
    field Name= obj-B (say)

2- Create another textfield at same Object with unique property (used to hold same obj-B field value)
     fieldName= unique_Obj-B (say)

3- Define a workFlow Rule /Trigger to  Update the custom "unique_Obj-B" field with the value of the associated OBJECT-B ID.(i.e the field value of "obj-B")

Now we have done with 1-1 Relationship
When we try to add a second same OBJECT-B to the OBJECT-A, the "unique" constraint in OBJECT-A (field "unique_Obj-B")would be violated and an error would be thrown.....

Thursday, April 18, 2013

Triggers and Order of Execution


Few days back I faced a situation , in which it was needed to update a field depending upon a Roll-up Summary field Value through trigger.
FYI we can not get the RollUpSummary field value inside trigger, because of sequence of execution of trigger(after, before) & RollUpSummary field value.

So here I am posting sequence of Trigger , automation rules ,validation rule etc execution in Salesforce.com .
The following is the order salesforce logic is applied to a record.

1- Old record loaded from database (or initialized for new inserts)
2- New record values overwrite old values
3- System Validation Rules
4- All Apex “before” triggers 
5- Custom Validation Rules
6- Record saved to database (but not committed)
7- Record reloaded from database
8- All Apex “after” triggers 
9- Assignment rules
10- Auto-response rules
11- Workflow rules
12- Escalation rules
13- Parent Rollup Summary Formula value updated (if present)
14- Database commit
15- Post-commit logic (sending email)

For Detail explanation please refer
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm 

notes: There is no way to control the order of execution within each group above

Tuesday, February 26, 2013

How To Display Inline Help Text of a SObject field in Visual Force Page



Most of the time when we override Visualforce page, clients/Users many time demand for same Standard page layout inline Help Text bubbles.

apex:inputField and apex:outputField shows their help Text bubble when nested within a pageBlockSection component automatically.

However, there are scenario when helpText Bubble is not displayed at VF page

scenario
----------
1- If we use "Label" attribute of "apex:outputField" , then helpText bubble is not displayed
2- If we set "showHeader=false"  of <aapex:Page>, in that case also helpText bubbles is not displayed

We can access the help text within an expression by using the respective $ObjectType global as such:

    $ObjectType.Account.Fields.myField__c.inlineHelpText

So I came up with my own idea to display help text at VF page with above two scenarios

<div id="mainContent">
    Sample helpText Example
    <span class="Custom ToolTip text">
            <img src="/s.gif" alt="Help" class="helpIcon" title="$ObjectType.Account.Fields.myField__c.inlineHelpText"/>
     </span>
</div>

By Providing "$ObjectType.Account.Fields.myField__c.inlineHelpText" in TITLE attribute of <img> tag..the helpText will be displayed as ToolTip Text

Thursday, January 3, 2013

Collapse PageBlockSection by default on page load



Collapse PageBlockSection by default on page load 
In a normal Salesforce VF page, the PageBlock Section is not collapsed at the time of page loading.
But some times we want a pageblock section to be collapsed by default at the time of page loading. 
We can do this, with some tricky javascript. We have to get a javascript function that is a document "onload" handler to call "twistSection" on the image that is the little twist control for the page block section. 

Please try the following post , which will Collapse PageBlockSection by default on page load

VF Code:
------------
<apex:page tabStyle="MyObject__c" id="myPage">

<script language="javascript">

/**

    <!-- Collapse PageBlockSection on Page Load-->

    **/

    function addLoadEvent(func) {

      var oldonload = window.onload;

      if (typeof window.onload != 'function') {

        window.onload = func;

      } else {

        window.onload = function() {

          if (oldonload) {

            oldonload();

          }

          func();

        }

      }

    }

function dotest() {

     if(document.getElementById('myPage:myForm:myBlock:mySection') != null){

         twistSection(document.getElementById('myPage:myForm:myBlock:mySection').childNodes[0].childNodes[0]);

     }

    }

addLoadEvent(dotest);

</script>

<apex:form id="myForm">

<apex:pageBlock id="myBlock">

<apex:pageBlockSection title="CollapsablePageBlockSection" collapsible="true" id="mySection">

Mindfire Solutions

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form >

</apex:page>

Thursday, November 22, 2012

Prevent Recursion of Trigger Execution in Salesforce - Part2




Salesforce – Stop Recursion of Trigger Execution- <Method-2>
As per my previous post , the method-2 for preventing recursive trigger execution in salesforce  is

Method (2) : Add a new field to the object so the trigger can inspect the record to see if it is being called by the future method.

The trigger checks the value of IsFutureExecute__c in the list of Accounts passed into the trigger. If the IsFutureExecute__c value is true then the trigger is being called from the future method and the record shouldn’t be processed. If the value of IsFutureExecute__c is false, then the  trigger is being called the first time and the future method should be called and passed the Set of unique names.

trigger updateSomething on Account (before insert, before update) {
     Set<Id> idsToProcess = new Se<Id>();
     for (Account acct : Trigger.new) {
          if (acct.IsFutureExecute__c) {
               acct.IsFutureExecute__c = false;
          } else {
              if(acct.NumberOfEmployees > 500){
                idsToProcess.add(acct.Id);
            }
          }
     }
     if (!idsToProcess.isEmpty())
          AccountProcessor.processAccounts(idsToProcess );
}

The AccountProcessor class contains the static method with the future annotation i.e called by the trigger. The method processes each Account and sets the value of IsFutureExecute__c to false before committing. This prevents the trigger from calling the future method once again.

public class AccountProcessor {

     @future
     public static void processAccounts(Set<ID> Ids) {
          // list to store the accounts to update
          List<Account> accountsToUpdate = new List<Account>();
          // iterate through the list of accounts to process
          for (Account a : [Select Id, Name, IsFutureExecute__c From Account where ID IN :Ids]) {
               // ... do you account processing
               // set the field to true, since we are about to fire the trigger again
               a.IsFutureExecute__c = true;
               // add the account to the list to update
               accountsToUpdate.add(a);
          }
          // update the accounts
          update accountsToUpdate;
     }

}

Tuesday, May 29, 2012

Assignment rule in a trigger

                                   
The objective is to have assignment rules to be fired on a  record creation. 
But, the assignment rule only can be fired on UPDATE operation inside the trigger.
Because when we try to perform DML operation in trigger.new or trigger.old , It throws exception

"Execution of AfterInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old:"

The rule can be assigned only when using "update" DML in an "after insert" trigger.
So the logic should be  in AFTER trigger collect the record Ids , and then SELECT the records & try to UPDATE the same .


trigger caseAssignment on Case (after insert) {

        List<Id> caseIds = new List<Id>{};
        for (Case caseObj:trigger.new)
            caseIds.add(caseObj.Id);
     
        List<Case> caseList = new List<Case>{};
        for(Case myCase : [Select Id from Case where Id in :caseIds])
        {
            Database.DMLOptions dmo = new Database.DMLOptions();

            dmo.assignmentRuleHeader.useDefaultRule = true;
            myCase.setOptions(dmo);
         
            caseList.add(myCase);
        }
        Database.upsert(caseList);
}