Friday, June 24, 2016

Developer: “Compiled formula is too big to execute (xxxxx characters). Maximum size is 5,000 characters,”

If you have ever hit this error “Compiled formula is too big to execute (xxxxx characters). Maximum size is 5,000 characters,” then it means that is it time to revisit the implemented formula
and refine it.

This does not in the literal sense mean that you have 5000 chars in your formula, it just means that there are either: too many nested IF's, formulas referring other formulas etc.

Following are some of the approaches that you can take to resolve this error:


  • Use CASE Instead Of Nested IFs--Implementing this has usually worked for me
  • Use Workflow Field Update--the formula field here has a larger capacity and hence might
       accomodate your formula but be careful to ensure that this update is executed only as needed
  • Use an Apex Trigger
Thanks

Friday, June 17, 2016

Administrator: No Portal available error....

I was trying to setup Partner Portal on my local and getting this error. Basically, you need to create


  • Account and Enable as Partner Account.
  • Create a Contact and associate it to the Partner Account.
  • Create a User record and associate the Contact record to the Partner User.

From Setup---Portal Settings; Identify the right profile that needs to be associated to the Portal and then associate this Profile to the User record.

You should now be able to login to Partner Portal on your local.

Monday, June 6, 2016

Developer: Scheduleable class has jobs pending or in progress...

If you run into this error while making changes to an APEX class "Scheduleable class has jobs pending or in progress..." then it means that there are scheduled jobs thru the UI or thru the System.Schedule method.

Firstly, clear the existing job by running the following code:

List<CronTrigger> listCronTrigger = [select Id, CronExpression, EndTime, NextFireTime, OwnerId,
        PreviousFireTime, StartTime, State, TimesTriggered, TimeZoneSidKey from CronTrigger
        where State = 'Waiting' or State='Running'];
       
System.debug('No of jobs: '+listCronTrigger.size());

If (listCronTrigger.size() > 0)
{
    for (Integer i = 0; i < listCronTrigger.size(); i++)
    {
        System.abortJob(listCronTrigger[i].Id);
        System.debug('Job details ::'+String.valueOf(listCronTrigger[i]));
    }
}

Now, try to save your APEX class and it should go thru successfully.

Wednesday, June 1, 2016

Developer:Error: Compile Error: Loop variable must be of type SObject

Our environment had implemented seperation of concerns and so the logic for triggers was in helper classes.

When trying to access trigger.new in helper classes; the context is not available automatically, you have to explicitly pass these attributes to your helper classes.

So, ClassName.MethodName(Trigger.New) should be used to call your class and explicitly pass the trigger collections.

Developer: System.Exception: SObject row does not allow errors

"SObject row does not allow .."  error was encountered while doing validation in a BeforeDelete trigger.

Solution

Very often; error in triggers are handled the traditional way that object.adderror('ErrorMessage').
trigger ClosedOpportunityPreventDeletion on Opportunity (before delete) {
if (system.Trigger.isDelete){
Opportunity[] Opps = [select id, (select id, Opportunity__c from PCFS__r) from Opportunity where id in :Trigger.oldMap.keySet()];

for (Opportunity o : Opps){
if(o.PCFS__r.size()>0){
o.adderror('You cannot delete this Opportunity as it has one or more Customer Forms associated with it');
}
}
}
However, when using adderror in a before delete it is important to maintain Context, the error can only be applied to those records that are in context.

Use the OldMap to get the actual record and apply the adderror message against that record. That should solve the problem. See sample below.


  Opportunity actualRecord = Trigger.oldMap.get(o.Id);
actualRecord.adderror('You cannot delete this O