• Vj@88
  • NEWBIE
  • 89 Points
  • Member since 2014
  • Developer

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 7
    Questions
  • 51
    Replies
Hello Everyone,

Primary Question: Can someone pinpoint what we are doing wrong in our Trigger below?

Background: The purpose of this trigger is to "break up" large single payments (Fleet Lease Pay) made by business clients and create parallel records showing the payments per vehicle (Fleet Truck Pay). Each "Fleet Truck Pay" record needs to be linked to to both the original "Fleet Lease Pay" and another custom object called "Vehicle Inventory". This is important because we track payments made per vehicle on the object called "Vehicle Inventory".

Problem: Our trigger works for manual entries of new "Fleet Lease Pay" records. However, when using the dataoloader (with batch size greater than 1) the trigger explodes and creates thousands upon thousands of records matching "Fleet Trucks" that aren't part of the parent "Fleet Lease". We have not been able to figure out a rhyme or reason to this explosion. We figure the data is getting blended together like the ingredients in a body-builder's smoothie. But we're not sure how.

Does anybody know why the information is getting blended up?

Fleet Lease Pay   =   Fleet_Lease_Payment__c
Fleet Lease   =   Fleet_Lease_ID__c or Fleet_Lease__c
Fleet Truck   =   Fleet_Truck__c
Fleet Truck Pay   =   Fleet_Vehicle_Payment__c
Vehicle Inventory   =   VIN_Vehicle_Inventory__c or Vehicle_Inventory__c

Relationship Diagram

Trigger Code:

trigger FleetLeasePaymentDivider on Fleet_Lease_Payment__c (after insert) {
    Set<Id> ids = Trigger.newMap.keySet();
    
    //Create all the lists needed for this process.
    List<Fleet_Truck__c> fleetVehicles = new List<Fleet_Truck__c>();
    List<String> leaseId = new List<String>();
    List<FLeet_Lease_Payment__c> fleetLeasePayments = new List<Fleet_Lease_Payment__c>();
    List<Fleet_Vehicle_Payment__c> fleetVehiclePayments = new List<Fleet_Vehicle_Payment__c>();
    List<Fleet_Truck__c> vehicles = new List<Fleet_Truck__c>();
    
    //Get Data from the "Fleet Lease Pay" Object.
    //Obtain the "Fleet Lease" Parent ID
    for (Fleet_Lease_Payment__c pmt : [SELECT Id, Fleet_Lease_ID__c, Lease_Amount__c, Date_Paid__c FROM Fleet_Lease_Payment__c WHERE Id IN :Trigger.new])
    {
        //Populate List of Fleet Lease Payments in Upload
        fleetLeasePayments.add(pmt);

        //Populate List of Parent IDs
        leaseId.add(pmt.Fleet_Lease_ID__c);
    }
    
    //Get List of all the Fleet Trucks attached to Parent
    for (Fleet_Truck__c fleetUnit : [SELECT Id, Fleet_Lease__c, VIN_Lookup__c FROM Fleet_Truck__c WHERE Fleet_Lease__c IN :leaseId])
    {
         //Populate List of Fleet Trucks attached to parent
         fleetVehicles.add(fleetUnit);
    }
    
    //Start final phase of trigger by cycling through each Fleet Lease Payment
    for (FLeet_Lease_Payment__c FLPmt : fleetLeasePayments)
    {
        //Make Parent ID easy to reference
        String fleetLeaseId = FLPmt.Fleet_Lease_ID__c;
        
        //Summon back up the list of all Fleeet Trucks attached to Parent
        for (Fleet_Truck__c fleetTruck : fleetVehicles)
        {
            //Check to see if the the Fleet Lease Pay and Fleet Truck records belong to the same parent
            if (fleetTruck.FLeet_Lease__c == fleetLeaseId)
            {
                //If so, Populate a second list of trucks, that is specific to each Fleet Lease Pay record
                vehicles.add(fleetTruck);
            }
        }
        //Get the second list of trucks we just made
        for (Fleet_Truck__c truck : vehicles)
        {
            //Create Fleet Truck Payment Records from that data
            Decimal truckPmt = FLPmt.Lease_Amount__c / vehicles.size();
            Fleet_Vehicle_Payment__c fleetPmt = new Fleet_Vehicle_Payment__c(Date_Paid__c = FLPmt.Date_Paid__c,
                                                                             Fleet_Lease_Payment__c = FLPmt.Id,
                                                                             VIN_Vehicle_Inventory__c = truck.VIN_Lookup__c,
                                                                             Fleet_Vehicle__c = truck.Id,
                                                                             Lease_Amount__c = truckPmt);
            //Populate the Fleet Truck Payments we want to Upload
            fleetVehiclePayments.add(fleetPmt);
        }
    }
    
    //Check to see if there is anything in the list.
    if (!fleetVehiclePayments.isEmpty())
    {
        //If so, insert the list.
        insert fleetVehiclePayments;
    }
}
Hi Everyone,

I have a custom object (Account_Manager_Handoff__c) with a Mast-Detail relationship to the Opportunity object.  The trigger below is meant to fire when the custom object is created or edited.  In either case, a field on the associated Account (Account_Manager_Handoff_Notes__c) gets updated with some text values from the custom object.  In addition, if another checkbox field (Handoff_Official__c) is marked as TRUE, the Account Owner is supposed to be changed to the person indicated in the Assigned_Account_Manager__c field on the custom object, and the related Opportunity (Opportunity__c) on the custom object is supposed to be cloned.  The trigger saves without errors, but when I try to create a record I get the following error:

MainTriggerAccountManagerHandoff: execution of AfterInsert caused by: System.FinalException: Record is read-only: Class.ClassAccountManagerHandoffNotes.addNotes: line 21, column 1

Does anyone know why I am getting this error and what I need to do to fix it?

Trigger:
 
trigger MainTriggerAccountManagerHandoff on Account_Manager_Handoff__c (after insert,after update) {
    
    IF(trigger.isAfter){
        
        if(trigger.isInsert || trigger.isUpdate){
            
            if(checkAccountManagerHandoffRecursive.runAfterInsertOnce()){
            
                ClassAccountManagerHandoffNotes updater = new ClassAccountManagerHandoffNotes();
                updater.addNotes(Trigger.new);
                
            }                
        }
    }
}

Trigger Class:
public class ClassAccountManagerHandoffNotes {
    
    public void addNotes(List<Account_Manager_Handoff__c> accountManagerHandoffs){
        
        Set<Id> accountsInTrigger = new Set<Id>();
        Map<Id,String> accountMap = new Map<Id,String>();
        Map<Id,Id>accountMap2 = new Map<Id,Id>();
        List<Account> accountsToUpdate = new List<Account>();
        
        FOR(Account_Manager_Handoff__c amh : accountManagerHandoffs){
            IF(amh.AccountLookup__c != NULL){
            
            accountsInTrigger.add(amh.AccountLookup__c);
            String notes = amh.Platform_Experience__c + '\n\n' + amh.Issues_Encountered__c + '\n\n' + amh.Known_Goals__c + '\n\n' + amh.Additional_Notes__c;
            Id owner = amh.Assigned_Account_Manager__c;
            accountMap.put(amh.AccountLookup__c,notes);
            accountMap2.put(amh.AccountLookup__c,owner);


//Clone the Opportunity that is associated with the handoff and all createable fields 
            IF(amh.Handoff_Official__c = TRUE){
                /* query Opportunity and then clone it */
                String soql = RecClone.getCreatableFieldsSOQL('Opportunity','Id =: amh.Opportunity__c.Id');
                    Opportunity opp = (Opportunity)Database.query(soql);
                    Opportunity opp2 = opp.clone(false, true);
                insert opp2;
            }

            }
        }
        
        FOR(Account a : [SELECT Id,Account_Manager_Handoff_Notes__c,OwnerId
                         FROM Account
                         WHERE Id In :accountsInTrigger]){
                             
                            a.Account_Manager_Handoff_Notes__c = accountMap.get(a.Id);

                        FOR(Account_Manager_Handoff__c amh2 : [SELECT Id,Handoff_Official__c
                                                                FROM Account_Manager_Handoff__c
                                                                WHERE Id =: a.Id]){

                            IF(amh2.Handoff_Official__c = TRUE){
                            a.OwnerId = accountMap2.get(a.Id);
                            }
                        }

                        accountsToUpdate.add(a);
                             
                        }
        
        UPDATE accountsToUpdate;        
    }
}

Class for Clone:
//This class is used to clone all the creatable fields on objects for use with Apex cloning.

public with sharing class RecClone{ 
 
    // Returns a dynamic SOQL statement for the whole object, includes only creatable fields since we will be inserting a cloned result of this query
    public static string getCreatableFieldsSOQL(String objectName, String whereClause){
         
        String selects = '';
         
        if (whereClause == null || whereClause == ''){ return null; }
         
        // Get a map of field name and field token
        Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get(objectName.toLowerCase()).getDescribe().Fields.getMap();
        list<string> selectFields = new list<string>();
         
        if (fMap != null){
            for (Schema.SObjectField ft : fMap.values()){ // loop through all field tokens (ft)
                Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd)
                if (fd.isCreateable()){ // field is creatable
                    selectFields.add(fd.getName());
                }
            }
        }
        if (!selectFields.isEmpty()){
            for (string s:selectFields){
                selects += s + ',';
            }
            if (selects.endsWith(',')){selects = selects.substring(0,selects.lastIndexOf(','));}
        }
        return 'SELECT ' + selects + ' FROM ' + objectName + ' WHERE ' + whereClause;    
    } 
}

 
I am trying to query records using IN clause via SOAP API, but It is throwing  me the error --

'Failed to process query: MALFORMED_QUERY: SOQL statements cannot be empty or null'
Query - list contains around 550 ID's like
 SELECT id from Account where id IN ('001i000000iG2EJAA0','001i000000iGHzvAAS','001i000000iFHpbAAS','001i000000iFGYXAAW','001i000001F2hTgAAJ','001i000000iErcWAAS','00001i000000iExVNAA0','001i000000iF44RAAS','001i000000iV17RAG','001i000000iEf43AAK','001i000000iF8QQAA0','001i000000iEer3AAC')

Even the length of query is within limits (around 12k char)Can you please let me know what I am doing wrong?
  • April 26, 2016
  • Like
  • 0
Hi,

I am getting 'Unable to Lock Row' Exception(When inserting mock data)  when executing all test classes at once.
But if I execute the test classes one at a time, test classes are passing without any exception.
Can anyone please explain why?

Thanks,
Vijay
 
  • July 28, 2015
  • Like
  • 0
I recently have an issue with lookup fields not copied properly into my partial data sandbox.

I have two lookup fields in Opportunity object. When I refreshed the sandbox, I am getting null pointer error while saving some records.
I found that those look up fields are not copied correctly for all Opps. These fields just show Ids of the records that are not copied. When I click the lookup fields it shows error "The Data Not Available. The data you are trying to access could not be found......".

When I raised a case with Salesfroce Support they replied like this is expected behavior and told that Partial data copies will not copy over all lookup fields properly unless they are required fields or master detailed and advised to blank all the look up fields using data loader.

This is a huge limitation as I cannot clear this fields because of a validation. If this fields are blank, there is no point in having sampled data.
 
  • January 28, 2015
  • Like
  • 0
I created a custom detail page button that executes the following Javascipt 
if({!Quote.Approval_Validation__c} == "")
{
window.open('/apex/Quotesubmit?id={!Quote.Id}'}
}
else
{
alert ("You can submit for Approval. Please check the Approval Validation on the top pd the Page to meet the requirements for submitting Approval");

}

When I click the button its giving me the error 'Unexpected Identifier'
I am new to Java script. Can anyone help me on this?
  • January 16, 2015
  • Like
  • 0
I have an workflow on Opportunity that needs to trigger everytime its created.
The criteria is based on a formula field(Account.name) -- Formula_field__c contains 'TEXT', trigger the workflow.
This Workflow does bunch of field updates

The problem is, the workflow is not triggerring some times eventhough it meets the criteria.
Note: I am creating the Opportunity using lead conversion.

I got issues with Data integrity because of the Issue
  • December 29, 2015
  • Like
  • 0
Hi,

I wrote some apex code that will based on the result of a formula field. It works fine with real data.
But the problem is when I try to generate mock data in test class, the formula field is not evaluating and is always 'Null'.
Can annybody help me how to get the formula field evaluated?

 
  • December 19, 2014
  • Like
  • 0
Not able to query the standard field 'subtotal' from quoteLineItem. 
Query: select subtotal from quotelineitem where id = 'xxxxx'
Error:No such column 'subtotal' on entity 'QuoteLineItem'. If you are attempting to use a custom field, be sure to append the '__c'

Can anyone help me on this?
  • November 03, 2014
  • Like
  • 0
We have a date field called book date....what we want to do is create workflow rule to update the bookdate to the date the opportunity stage was changed to "Order Form Recieved". Not sure how to update the field action on my workflow, anyone have any ideas?
I am trying to query records using IN clause via SOAP API, but It is throwing  me the error --

'Failed to process query: MALFORMED_QUERY: SOQL statements cannot be empty or null'
Query - list contains around 550 ID's like
 SELECT id from Account where id IN ('001i000000iG2EJAA0','001i000000iGHzvAAS','001i000000iFHpbAAS','001i000000iFGYXAAW','001i000001F2hTgAAJ','001i000000iErcWAAS','00001i000000iExVNAA0','001i000000iF44RAAS','001i000000iV17RAG','001i000000iEf43AAK','001i000000iF8QQAA0','001i000000iEer3AAC')

Even the length of query is within limits (around 12k char)Can you please let me know what I am doing wrong?
  • April 26, 2016
  • Like
  • 0
Can anybody tell how to read the barcode from the image and display the product information details regarding the barcode image.

Using EAN 128 image format. It should accept only EAN 128 image format. 

Thanks in advance.

I have a installed managed package. The package has a visual force page which is put as a button on the detailed page. The controller for the viusal force page is not defined global and hence I cannot see that code. 

I also have another custom button on the list view of the same object. I would like to call the visual force page of the installed package after my own logic in the custom button (visual force page with controller). 

Is there any way to do that?

Thanks,

In below code showing site value is null in debug.kindly help us to resolve the issue.
@isTest
public class testOnUpdation{
static testmethod void Siteupdate()
{
Account aa = new Account (name='istest',RecordTypeId='012j0000000ogEQAAY',Site='istest');
insert aa;
System.Test.startTest();
system.debug('starttest');
Account bb= new Account(name='naugh',RecordTypeId='012j0000000qRATAA2',self__c=aa.id);
insert bb;
system.debug('site'+bb.site);//Here it is showing null value
Account cc=[select Id, name,Site from account where Id =:aa.Id];
cc.Site ='istestchanged' ;
update cc;
update bb;
System.Test.stopTest();
}
 
Hello Everyone,

Primary Question: Can someone pinpoint what we are doing wrong in our Trigger below?

Background: The purpose of this trigger is to "break up" large single payments (Fleet Lease Pay) made by business clients and create parallel records showing the payments per vehicle (Fleet Truck Pay). Each "Fleet Truck Pay" record needs to be linked to to both the original "Fleet Lease Pay" and another custom object called "Vehicle Inventory". This is important because we track payments made per vehicle on the object called "Vehicle Inventory".

Problem: Our trigger works for manual entries of new "Fleet Lease Pay" records. However, when using the dataoloader (with batch size greater than 1) the trigger explodes and creates thousands upon thousands of records matching "Fleet Trucks" that aren't part of the parent "Fleet Lease". We have not been able to figure out a rhyme or reason to this explosion. We figure the data is getting blended together like the ingredients in a body-builder's smoothie. But we're not sure how.

Does anybody know why the information is getting blended up?

Fleet Lease Pay   =   Fleet_Lease_Payment__c
Fleet Lease   =   Fleet_Lease_ID__c or Fleet_Lease__c
Fleet Truck   =   Fleet_Truck__c
Fleet Truck Pay   =   Fleet_Vehicle_Payment__c
Vehicle Inventory   =   VIN_Vehicle_Inventory__c or Vehicle_Inventory__c

Relationship Diagram

Trigger Code:

trigger FleetLeasePaymentDivider on Fleet_Lease_Payment__c (after insert) {
    Set<Id> ids = Trigger.newMap.keySet();
    
    //Create all the lists needed for this process.
    List<Fleet_Truck__c> fleetVehicles = new List<Fleet_Truck__c>();
    List<String> leaseId = new List<String>();
    List<FLeet_Lease_Payment__c> fleetLeasePayments = new List<Fleet_Lease_Payment__c>();
    List<Fleet_Vehicle_Payment__c> fleetVehiclePayments = new List<Fleet_Vehicle_Payment__c>();
    List<Fleet_Truck__c> vehicles = new List<Fleet_Truck__c>();
    
    //Get Data from the "Fleet Lease Pay" Object.
    //Obtain the "Fleet Lease" Parent ID
    for (Fleet_Lease_Payment__c pmt : [SELECT Id, Fleet_Lease_ID__c, Lease_Amount__c, Date_Paid__c FROM Fleet_Lease_Payment__c WHERE Id IN :Trigger.new])
    {
        //Populate List of Fleet Lease Payments in Upload
        fleetLeasePayments.add(pmt);

        //Populate List of Parent IDs
        leaseId.add(pmt.Fleet_Lease_ID__c);
    }
    
    //Get List of all the Fleet Trucks attached to Parent
    for (Fleet_Truck__c fleetUnit : [SELECT Id, Fleet_Lease__c, VIN_Lookup__c FROM Fleet_Truck__c WHERE Fleet_Lease__c IN :leaseId])
    {
         //Populate List of Fleet Trucks attached to parent
         fleetVehicles.add(fleetUnit);
    }
    
    //Start final phase of trigger by cycling through each Fleet Lease Payment
    for (FLeet_Lease_Payment__c FLPmt : fleetLeasePayments)
    {
        //Make Parent ID easy to reference
        String fleetLeaseId = FLPmt.Fleet_Lease_ID__c;
        
        //Summon back up the list of all Fleeet Trucks attached to Parent
        for (Fleet_Truck__c fleetTruck : fleetVehicles)
        {
            //Check to see if the the Fleet Lease Pay and Fleet Truck records belong to the same parent
            if (fleetTruck.FLeet_Lease__c == fleetLeaseId)
            {
                //If so, Populate a second list of trucks, that is specific to each Fleet Lease Pay record
                vehicles.add(fleetTruck);
            }
        }
        //Get the second list of trucks we just made
        for (Fleet_Truck__c truck : vehicles)
        {
            //Create Fleet Truck Payment Records from that data
            Decimal truckPmt = FLPmt.Lease_Amount__c / vehicles.size();
            Fleet_Vehicle_Payment__c fleetPmt = new Fleet_Vehicle_Payment__c(Date_Paid__c = FLPmt.Date_Paid__c,
                                                                             Fleet_Lease_Payment__c = FLPmt.Id,
                                                                             VIN_Vehicle_Inventory__c = truck.VIN_Lookup__c,
                                                                             Fleet_Vehicle__c = truck.Id,
                                                                             Lease_Amount__c = truckPmt);
            //Populate the Fleet Truck Payments we want to Upload
            fleetVehiclePayments.add(fleetPmt);
        }
    }
    
    //Check to see if there is anything in the list.
    if (!fleetVehiclePayments.isEmpty())
    {
        //If so, insert the list.
        insert fleetVehiclePayments;
    }
}
Hello,

We have a requirement to create different record types under Solution object and give access to specific profile to those record type.

Setting as of now :
Profile A - Object access (RCE) , Record type access (A1)
Profile B - Object access (RCE) , Record type access (A1 , A2)

But problem is users from Profile A have access to record having record type A2. They cannot create new of type A2 but they have read/edit access for A2 type.

Can you please help me with this.

Thanks, Rahul
Hello All  ,

I am preparing for Salesforce 201 certification .Please help me in finding appropraite material for the certification .

Thanks
Pooja Upadhyaya
I've created a custom List Button on the Contact object that's accessible via the Account page layout Related Lists section. However, the # of records in that section exceeds 5, so there's a hyperlink displayed below it that says "Go to List". If clicked, this hyperlink brings me to a page that shows the full related list of Contacts. I'd like to put a button on this page, but I can't figure out how to. There isn't an Edit Layout hyperlink present, and despite everything I've tried I can't figure out how to add buttons to that screen.

Related List as shown on Account - note See List hyperlink at bottom of screenshot-
User-added image

Page I'd like to add the button to, but can't figure out how to access:
User-added image
Hi,

I am a bit of an amateur coder so please forgive my ignorance.

I am trying to have the results of a sub query returned in Perl.

my $result = $sforce->do_query("Select FirstName,Account.Name,LastName,Title,Description,(SELECT Note.Body,Note.Title FROM Contact.Notes where Note.title like '%resume%') From Contact where FirstName like '%abcd%'");

    foreach my $row (@$result) {
      print $row->{FirstName}.";".$row->{LastName}.";".$row->{Notes}.";\n";
    ...
I get this:
abcde;test;QueryResult=HASH(0x...)

How do I get the results of the query, i.e. the Note Body and Note Title now?

Thanks!
Hi I am facing a issue when I run all test cases together I am getting some error like unable to lock the row and those test classes are failing. However when I run then alone or single then they pass. Will this be a problem when we deploy to prod if all dont pass togehter? If so can some one guide how to overcome this scenario?
I have the following validation rule to forbid users altering the close date (field) of the opportunity before the 4th day of the current month although I got a problem because is not taking the desired effect.

The Formula I'm using is:
 
AND(ISCHANGED( CloseDate ),
IF(AND(TODAY() <= DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
MONTH (CloseDate) < MONTH (TODAY ()) -1)
,TRUE,IF(AND(TODAY() > DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
 CloseDate < DATEVALUE (TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '01')),TRUE,FALSE)))




Can someone with more knowledge than me give me  some light ? It will be much appreciatted 

Thank you

Posting this in order to help others who, months from now, might Google "OP_WITH_INVALID_USER_TYPE_EXCEPTION" and find this explanation.

 

We wrote an Apex trigger on the User object, to insert a custom object record anytime a user updates their Chatter status.  This was done to fulfill a client's requirement to audit all Chatter activity.

 

The trigger worked fine, until one day the client signed up some Chatter Free users.  When such a user tried to update their status, they got a pop-up with an OP_WITH_INVALID_USER_TYPE_EXCEPTION error.

 

We scratched our collective heads for awhile.  After all, Apex triggers run in "system mode," right?  That is supposed to mean that "object and field-level permissions of the current user are ignored."  And yet this trigger seemed like it was running in "user mode," enforcing restrictions based on who the current user was.

 

The root cause turned out to be that a Chatter Free user cannot be the owner of a custom object record, and SFDC by default sets the current user as a new record's first owner.  We discovered this when we realized, via experiment, that Apex triggers fired as the result of actions by Chatter Free users could definitely update an existing record, but were having problems creating records.

 

So the simple solution was to explicitly set the owner of the new record to some fully-licensed user prior to inserting it.