• Masie
  • NEWBIE
  • 65 Points
  • Member since 2014
  • Business Analyst
  • SureSwipe

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 25
    Replies
Hi

Me again- I have written a trigger on a join object to update the one of its parent object based on the other's details.

The two objects are Accounts and Rate Type and the join object is called Company and Rate Type Links. May someone please take a look and let me know where I am going wrong as it is not firing.

trigger UpdateGroupRates on Company_and_RateType_Link__c (after update, after insert)
{  
if(trigger.isUpdate)
{
  Set<Id> accountIds = new Set<Id>();
  Set<Id> ratesIds = new Set<Id>();
  for(Company_and_RateType_Link__c tempJ : Trigger.new)
  {
   accountIds.add(tempJ.Company__c);
   ratesIds.add(tempJ.Rate_Type__c);
  }
 
  List<Account> AccountList = [Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id IN: accountIds];
 
  List<Rate_Type_del__c> Ratelist = [Select id, Name, Rate_Type__c, Number_Credit_Card_Fee__c, Number_Debit_Card_Fee__c from Rate_Type_del__c where id in: ratesIds];
 
  for(Company_and_RateType_Link__c tempJ : Trigger.new)
  {
   for(Account tempAcc : AccountList)
   {
    if(tempJ.Company__c == tempAcc.Id)
    {
     for(Rate_Type_del__c tempRate : Ratelist)
     {

                       if(tempJ.Rate_Type__c == tempRate.Id )
      {
       tempAcc.Rate_Type__c = tempRate.Rate_Type__c;
                            tempAcc.Fixed_Credit_Card_Rate__c = tempRate.Number_Credit_Card_Fee__c;
                            tempAcc.Fixed_Debit_Card_Rate__c = tempRate.Number_Debit_Card_Fee__c;
      }    
    
     }
   
    }
  
   }
  
  } 
   update AccountList;
}
      
}
  • September 09, 2014
  • Like
  • 0
Hi lovely people

I need to create a trigger that will update the accounts object based on values in either my rates object or my group rates custom object. I have a trigger to update the account based on the rates object but I would like to have a delimitor that says should there not be a rates id update using the group rate information.

Any assistance with this will be greatly appreciated.
  • September 08, 2014
  • Like
  • 0
Hello Everyone

Please may I have some help, I have this trigger and it is not firing. Can someone please take a look for me.

trigger updateRates on Rate_Type_del__c (after update) {
  
Set<Id> RateTypedelids = new Set<Id>();
    list <Account> newratelist = new list <Account>();
   
    for(Rate_Type_del__c rate:trigger.new){
        RateTypedelids.add(rate.id);
}
    List <Account> ratelist =[Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id in:RateTypedelids];
                                                 
      for(Rate_Type_del__c temprate:trigger.new){
      for(Account tempacc:ratelist){
      if(temprate.Company_del__c == tempacc.id && temprate.RecordType.Name == 'SureSwipe Base Rates' && temprate.Status__c == 'Active'){
{
    tempacc.Rate_Type__c = temprate.Rate_Type__c;
    tempacc.Fixed_Credit_Card_Rate__c = temprate.Number_Credit_Card_Fee__c;
    tempacc.Fixed_Debit_Card_Rate__c = temprate.Number_Debit_Card_Fee__c;
}
          }
        update newratelist;
    }
}

}
  • September 04, 2014
  • Like
  • 0
Hi 

I have a trigger that records the old value of a rich text area field but I am getting the following error when an update is done.

caused by: System.DmlException: Insert failed. First exception on row 3; first error: STRING_TOO_LONG, Old Value: data value too large (max length=220)

Is there a way to increase this?


  • September 01, 2014
  • Like
  • 0
Hi

I need some help with the following trigger- it creates a record in my asset history table should certain conditions be met. I need to add another condition and I am already running into apex governor limits when I do mass updates. 

trigger AssetHistoryTracking on Asset(after update){
 
  String AccId = null;
  String AccName = null;
  Integer index = 0;  
  String OldAccName = null;
 
 
 
  //create a list to hold the new record(s) to create
  List<Asset_History__c> historyObjList = new List<Asset_History__c>();
  
   for(Asset ass : Trigger.New){
    String OldAccId = Trigger.Old[index].AccountId;
    AccId = ass.AccountId;
   
  List <Account> acclist = [select name, id from Account where id = :AccId ];
    Accname = acclist[0].name;
   
    List <Account> oldacclist = [select name, id from Account where id = :OldAccId ];
    OldAccname = oldacclist[0].name;
       
     //If status changes
     if(ass.Status != Trigger.Old[index].Status){
               
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = Trigger.Old[index].Status;
     objAssetH.New_value__c = ass.Status;
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Status';
     objAssetH.Changed_By__c = UserInfo.getUserId();
                   
                         //Trigger Action Logic
                        // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
   // index++;
     }
      //when Account changes
    if(ass.AccountId != Trigger.Old[index].AccountId){
                   
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = OldAccname ;
//    objAssetH.Old_Value__c = Trigger.Old[index].AccountId;
     objAssetH.New_value__c = AccName ;
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Company Name';
     objAssetH.Changed_By__c = UserInfo.getUserId();
                   
    //Trigger Action Logic
    // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
//   index++;
     }
     //when install date changes
    if(ass.InstallDate != Trigger.Old[index].InstallDate){
                   
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = String.valueof(Trigger.Old[index].InstallDate);
     objAssetH.New_value__c = string.valueof(ass.InstallDate);
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Install Date';
     objAssetH.Changed_By__c = UserInfo.getUserId();
                   
      //Trigger Action Logic
     // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
   // index++;
         }
     //when Usage End Date changes
    if(ass.UsageEndDate != Trigger.Old[index].UsageEndDate){
                   
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = String.valueof(Trigger.Old[index].UsageEndDate);
     objAssetH.New_value__c = string.valueof(ass.UsageEndDate);
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Usage End Date';
     objAssetH.Changed_By__c = UserInfo.getUserId();
  
                         //Trigger Action Logic
                        // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
    //index++;
}
     //when Stock is For Show Devices
    if(ass.Show_Device__c != Trigger.Old[index].Show_Device__c){

     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = String.valueof(Trigger.Old[index].Show_Device__c);
     objAssetH.New_value__c = string.valueof(ass.Show_Device__c);
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Show Device';
     objAssetH.Changed_By__c = UserInfo.getUserId();
  
                         //Trigger Action Logic
                        // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
       
    index++;
     }
  }
       
   if(historyObjList.size() > 0){
    insert historyObjList;
 
   }
}
  • August 29, 2014
  • Like
  • 0
Hi

May someone please help, I have an object called the rebate that has a lookup relationship to the account object. I want when a field is updated on the account object a field should also be updated on the rebate object but I am having a problem with this trigger.

trigger updateStartDate on Rebates__c (after insert, after update,before update){

Set<Id> accountIds = new Set<Id>();
   
    for(Rebates__c reb :trigger.new){
        accountIds.add(reb.Company__c);
}

    Map <ID,Account> updateAccounts = new Map<ID,Account>([Select id, Date_Installed__c from Account where id IN: AccountIds]);{
                                                 
for(Rebates__c reb :trigger.new){
accountIds.add(reb.Company__c);

       if(reb.From_Install_Date__c == true && updateAccounts.get(reb.Company__c).Date_Installed__c != null){

    if(reb.Product__c == '1t200000024Dtm')

{
                reb.Start_Date__c = reb.First_Day_of_the_Month__c;
   
    accountIds.update(reb);

}

else
{

   reb.Start_Date__c = reb.Install_Date__c;
    accountIds.update(reb);

       }
           try
              
           {
               update accountIds;
           }
           catch (system.DmlException e)
           {
               system.debug (e);
           }

   }
}
}
}
  • August 19, 2014
  • Like
  • 0
Hi

I am trying to create a custom button that will create a new event with a prepopulated field but I keep getting the error that my url is not valid. Can someone please help. Here is the URL.

https://cs18.salesforce.com/00U/e?who_id={!Case.AccountId}&what_id={!Case.Id}&retURL=%2F{!Case.Id}&RecordType=0122000000061K7&ent=Event&evt6={!Case.Description}
  • July 29, 2014
  • Like
  • 0
Hi

May someone please help, I have written a trigger to create a record in a custom object when a status is changed on my assets. The test class I have passes but the percentage coverage is very low.

Trigger:

trigger createBillableSwappedAsset on Asset (after update) {

List <Billable_Swapped_Asset__c> auditTrailList = new List <Billable_Swapped_Asset__c>();

// or whatever your custom object name put instead of Vehicle__c

for ( Asset ass : Trigger.new) {

              if (Trigger.oldMap.get(ass.Id).Movement_Status__c != 'Swapped') {
 
 
  // here is where you check if asset that is being inserted meets the criteria
              if (ass.Movement_Status__c == 'Swapped' && ass.Product2Id != null && ass.Show_Device__c != true) { 


           
       //instantiate the object to put values for future record 
  Billable_Swapped_Asset__c  b =  new Billable_Swapped_Asset__c ();
        
  // now map asset fields to billable swapped asset that is being created with this asset
 
                      b.Company__c = Trigger.oldMap.get(ass.Id).AccountId;
                      b.Product__c = ass.Product2Id;
                      b.Install_Date__c =  ass.InstallDate;
                      b.End_Date__c = ass.UsageEndDate;
 
  auditTrailList.add(b);
 
 
  }//end if
 
}//end for ass

//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
  insert auditTrailList;
} catch (system.Dmlexception e) {
        system.debug (e);
    }
}

}


Test Class:

@isTest

private class TestCreateBillableSwappedAsset

{

static testMethod void TestCreateBillableSwappedAsset()
{
    Date todaysDate = System.today();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        
        //Create  & Insert Test User
  User u = new User(Alias = 'standt', Email='standarduser@sureswipe.com',
                  EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
                  LocaleSidKey='en_US', ProfileId = p.Id,
                  TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@sureswipe.com'); 
        System.runAs(u)
           
        {
          //Create and Insert Account
  Account a = new Account(Name = 'Test Company', Status__c = 'Active', Industry = 'Fashion',Type = 'Customer',
                                        Company_Email_Adress__c = 'test@test.com');
            insert a;
           
   //Create and Insert Asset
   Asset ass = new Asset(
   Name = 'Test Asset',
   Status = 'Installed',
   AccountId = a.Id,
   InstallDate = System.Today(),
   Product2Id = '01t200000024GTq',
   UsageEndDate = System.Today()
   );
   insert ass;

//Update Asset status to swapped
           
ass.status = 'Swapped';
ass.show_device__c = false;
update ass; 
           
//Update Asset status to swapped with show device true      
ass.status = 'Swapped';
ass.show_device__c = true;
update ass;
           
//Update Asset status to swapped with no product         
ass.status = 'Swapped';
ass.show_device__c = false;
ass.Product2Id = null;
update ass; 
           

        }
    }
}

  • June 19, 2014
  • Like
  • 1
May someone please help. 

If we run this query :

SELECT Name ,Id , Mercantile_Merchant_Number__c , Date_Installed__c , PriceBook__c ,
      (SELECT Ad_Hoc_Billing_Item__c.Effective_Date__c, Ad_Hoc_Billing_Item__c.Product__r.ProductCode,
      Ad_Hoc_Billing_Item__c.Quantity__c
      from Ad_Hoc_Billing_Items__r)  from Account
      where Mercantile_Merchant_Number__c <> null

Then we get two results that does not include a specific record but if we include the specific record's id in the query like this:

SELECT Name ,Id , Mercantile_Merchant_Number__c , Date_Installed__c , PriceBook__c ,
      (SELECT Ad_Hoc_Billing_Item__c.Effective_Date__c, Ad_Hoc_Billing_Item__c.Product__r.ProductCode,
      Ad_Hoc_Billing_Item__c.Quantity__c
      from Ad_Hoc_Billing_Items__r)  from Account
      where Mercantile_Merchant_Number__c = '360000000041032'

we get a result. The Ad Hoc Billing Item is a child of the account table. Is it in the way we are nesting the statements?


  • June 18, 2014
  • Like
  • 0
Hi, I am a complete novice on trigger creation so please hep. 

I need help with the following trigger- it is supposed to create a new record in my custom objectt Billable Swapped Assets should an asset's Custom Field called Movement Status be changed to Swapped. 

I am getting an unexpected token error on the underlined line for the "For"

trigger create on Asset (after update) {

List <Billable_Swapped_Asset__c> auditTrailList = new List <Billable_Swapped_Asset__c>

// or whatever your custom object name put instead of Vehicle__c

for (Asset ass : Trigger.new) {
 
 
  // here is where you check if opportunity that is being inserted meets the criteria
  if (ass.Movement_Status__c = 'Swapped') { 


                           //instantiate the object to put values for future record 
  Billable_Swapped_Asset__c  b=  new Billable_Swapped_Asset__c ();
        
  // now map opportunity fields to new vehicle object that is being created with this opportunity
 
 
                            ass.Product2= b.Product__c;
                            ass.InstallDate= b.Install_Date__c;
                      ass.UsageEndDate= b.End_Date__c;
 
  //once done, you need to add this new object to the list that would be later inserted.
  //don't worry about the details for now
 
  auditTrailList.add(b);
 
 
  }//end if
 
}//end for ass

//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
  insert auditTrailList;
} catch (system.Dmlexception e) {
  system.debug (e);
}

}
  • June 13, 2014
  • Like
  • 0
I have installed a mass edit package that does the editing on a visualforce page. I am unable to add the lookup for the record type on this page can someone please assist.  I either add the record type name or the record type id but I cannot add the actuall lookup
  • March 25, 2014
  • Like
  • 1
Test Class

/*

Copyright (c) 2012, salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.
    * Neither the name of the salesforce.com, Inc. nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.


* Salesforce version written for: Winter '12 onwards
* This Apex plug-in for Visual Workflow does the lead conversion of any given lead.
* Inputs:
*    lead ID (Required)
*    Contact ID (Optional)
*    Account ID (Optional)
*    Converted Status (Optional)
*    OverwriteLeadSource (Optional)
*    Converted Status (Optional)
*    Opportunity Name (Optional)
*    SendEmailtoOwner (Optional)
*
* Outputs:
*    Account ID: ID of the account after the conversion
*    Contact ID: ID of the contact after the conversion
*    Opportunity ID: ID of the Opportunity after the conversion
*/


// The Apex Plug-in for a flow must implement the Apex Process.Plugin Interface
global with sharing class  ConvertLead implements Process.Plugin {

    // This is the main method the Flow engine calls at run-time.
    global Process.PluginResult invoke(Process.PluginRequest request) {   

        // Get all the inputs from the Flow
        String leadID = (String) request.inputParameters.get('LeadID');
        String contactID = (String) request.inputParameters.get('ContactID');
        String accountID = (String) request.inputParameters.get('AccountID');
        String convertedStatus = (String) request.inputParameters.get('ConvertedStatus');
        Boolean overWriteLeadSource = (Boolean) request.inputParameters.get('OverwriteLeadSource');
        Boolean createOpportunity = (Boolean) request.inputParameters.get('CreateOpportunity');
        String opportunityName = (String) request.inputParameters.get('OpportunityName');
        Boolean sendEmailToOwner = (Boolean) request.inputParameters.get('SendEmailToOwner');  
       
        // Set the default handling for booleans
        if (overWriteLeadSource == null) overWriteLeadSource = false;
        if (createOpportunity == null) createOpportunity = true;
        if (sendEmailToOwner == null) sendEmailToOwner = false;
       
        Map<String,Object> result = new Map<String,Object>();
   
        //Convert the lead
        result = convertLead(leadID, contactID, accountID, convertedStatus, overWriteLeadSource, createOpportunity, opportunityName, sendEmailToOwner);
        return new Process.PluginResult(result);
    }


    /* This is the method the Cloud Flow Designer calls to show the Apex Plug-ins to the flow author
     * The implemnetation of this method drives how author of the flow interacts in the the Cloud Flow Designer
     */  
    global Process.PluginDescribeResult describe() {
   
    Process.PluginDescribeResult result = new Process.PluginDescribeResult();
        //Shows the description visible in the Palette tab of the Cloud Flow Designer.
        result.description = 'The LeadConvert Flow Plug-in converts a lead into an account and contact, as well as (optionally) an opportunity.';
       
        //Setting the 'tag' give the Apex Plug-in as its own section on the Cloud Flow Designer Palette tab.
        // Use this attribute to group related Apex Plug-ins together in the Cloud Flow Designer.
        result.tag = 'Lead Management';
       
        //All the Inputs needed, their data type and the requiredness
        result.inputParameters = new List<Process.PluginDescribeResult.InputParameter>{
            new Process.PluginDescribeResult.InputParameter('LeadID',
                Process.PluginDescribeResult.ParameterType.STRING, true),
            new Process.PluginDescribeResult.InputParameter('AccountID',
                Process.PluginDescribeResult.ParameterType.STRING, false),
            new Process.PluginDescribeResult.InputParameter('ContactID',
                Process.PluginDescribeResult.ParameterType.STRING, false),           
            new Process.PluginDescribeResult.InputParameter('ConvertedStatus',
                Process.PluginDescribeResult.ParameterType.STRING, false),
            new Process.PluginDescribeResult.InputParameter('OpportunityName',
                Process.PluginDescribeResult.ParameterType.STRING, false),
            new Process.PluginDescribeResult.InputParameter('OverwriteLeadSource',
                Process.PluginDescribeResult.ParameterType.BOOLEAN, false),
            new Process.PluginDescribeResult.InputParameter('CreateOpportunity',
                Process.PluginDescribeResult.ParameterType.BOOLEAN, false),
            new Process.PluginDescribeResult.InputParameter('SendEmailToOwner',
                Process.PluginDescribeResult.ParameterType.BOOLEAN, false)                                                  
                };
        //All the Outputs and their data type
        result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter>{
            new Process.PluginDescribeResult.OutputParameter('AccountID',
                Process.PluginDescribeResult.ParameterType.STRING),
            new Process.PluginDescribeResult.OutputParameter('ContactID',
                Process.PluginDescribeResult.ParameterType.STRING),
            new Process.PluginDescribeResult.OutputParameter('OpportunityID',
                Process.PluginDescribeResult.ParameterType.STRING)               
                };
  
       
        return result;
    }
   
   
       
    /**
     * The Implementation of the Lead conversion using the standard Apex LeadConvert API
     */
    public Map<String,String> convertLead (
                               String leadID,
                               String contactID,
                               String accountID,
                               String convertedStatus,
                               Boolean overWriteLeadSource,
                               Boolean createOpportunity,
                               String opportunityName,
                               Boolean sendEmailToOwner
        ) {
        Map<String,String> result = new Map<String,String>();
        LeadStatus convertStatus;
        if (leadId == null) throw new ConvertLeadPluginException('Lead Id cannot be null');
        if (convertedStatus == null) {
            convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        }
   
       
        Lead[] leads = [Select Id, FirstName, LastName, Company From Lead where Id = :leadID];
        if (leads.size() > 0) {
            Lead l = leads[0];
            // CheckAccount = true, checkContact = false
            if (accountID == null && l.Company != null) {
                Account[] accounts = [Select Id, Name FROM Account where Name = :l.Company LIMIT 1];
                if (accounts.size() > 0) {
                    accountId = accounts[0].id;
                }
            }
           
            Database.LeadConvert lc = new Database.LeadConvert();
            lc.setLeadId(leadID);
            lc.setOverwriteLeadSource(overWriteLeadSource);
            lc.setDoNotCreateOpportunity(!createOpportunity);
            lc.setConvertedStatus(convertedStatus!=null ? convertedStatus : convertStatus.MasterLabel );
            if (sendEmailToOwner != null) lc.setSendNotificationEmail(sendEmailToOwner);
            if (accountId != null && accountId.length() > 0) lc.setAccountId(accountId);
            if (contactId != null && contactId.length() > 0) lc.setContactId(contactId);
            if (createOpportunity) {
                lc.setOpportunityName(opportunityName);
            }
           
            Database.LeadConvertResult lcr = Database.convertLead(lc, true);
            if (lcr.isSuccess()) {
                result.put('AccountID', lcr.getAccountId());
                result.put('ContactID', lcr.getContactId());
                if (createOpportunity) {
                    result.put('OpportunityID', lcr.getOpportunityId());
                }
            } else {
                String error = lcr.getErrors()[0].getMessage();
                throw new ConvertLeadPluginException(error);
            }
        } else {
            throw new ConvertLeadPluginException('No leads found with Id : "' + leadId + '"');
        }
        return result;
    }
       
        class ConvertLeadPluginException extends Exception {}

/*
* This section onwards are for the tests
*/


/*
* This is a basic test with just the LeadID and Converted Status specified in the call the Apex Plug-in
*/

    static testMethod void basicTestwith() {

        // Create dummy lead
        Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe');
        insert testLead;
   
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
       
        // Create dummy conversion
        ConvertLead aLeadPlugin = new ConvertLead();
        Map<String,Object> inputParams = new Map<String,Object>();
        Map<String,Object> outputParams = new Map<String,Object>();

        inputParams.put('LeadID',testLead.ID);
        inputParams.put('ConvertedStatus',convertStatus.MasterLabel);

        Process.PluginRequest request = new Process.PluginRequest(inputParams);
        Process.PluginResult result;
        result = aLeadPlugin.invoke(request);
       
        Lead aLead = [select name, id, isConverted from Lead where id = :testLead.ID];
        System.Assert(aLead.isConverted);
       
    }

/*
* This is another basic test with just the LeadID and nothing else.
*/

    static testMethod void basicTestWithoutConvertedStatus() {

        // Create dummy lead
        Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe');
        insert testLead;
           
        // Create dummy conversion
        ConvertLead aLeadPlugin = new ConvertLead();
        Map<String,Object> inputParams = new Map<String,Object>();
        Map<String,Object> outputParams = new Map<String,Object>();

        inputParams.put('LeadID',testLead.ID);

        Process.PluginRequest request = new Process.PluginRequest(inputParams);
        Process.PluginResult result;
        result = aLeadPlugin.invoke(request);
       
        Lead aLead = [select name, id, isConverted from Lead where id = :testLead.ID];
        System.Assert(aLead.isConverted);
       
    }
   
/*
  * This test is to test the convert Lead with the Account ID specified
  */
       static testMethod void basicTestwithAccount() {

        // Create dummy lead
        Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe');
        insert testLead;
       
        Account testAccount = new Account(name='Test Account');
        insert testAccount;
   

        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
       
        // Create dummy conversion
        ConvertLead aLeadPlugin = new ConvertLead();
        Map<String,Object> inputParams = new Map<String,Object>();
        Map<String,Object> outputParams = new Map<String,Object>();

        inputParams.put('LeadID',testLead.ID);
        inputParams.put('AccountID',testAccount.ID);
        inputParams.put('ConvertedStatus',convertStatus.MasterLabel);

        Process.PluginRequest request = new Process.PluginRequest(inputParams);
        Process.PluginResult result;
        result = aLeadPlugin.invoke(request);
       
        Lead aLead = [select name, id, isConverted, convertedAccountID from Lead where id = :testLead.ID];
        System.Assert(aLead.isConverted);
        //System.debug('ACCOUNT AFTER' + aLead.convertedAccountID);
        System.AssertEquals(testAccount.ID, aLead.convertedAccountID);
    }

/*
  * This test is to test the convert Lead with the Company matching more than one existing Account Names
  */
       static testMethod void basicTestwithAccounts() {

        // Create dummy lead
        Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe');
        insert testLead;
       
        Account testAccount1 = new Account(name='Test Lead');
        insert testAccount1;
        Account testAccount2 = new Account(name='Test Lead');
        insert testAccount2;


        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
       
        // Create dummy conversion
        ConvertLead aLeadPlugin = new ConvertLead();
        Map<String,Object> inputParams = new Map<String,Object>();
        Map<String,Object> outputParams = new Map<String,Object>();

        inputParams.put('LeadID',testLead.ID);
        inputParams.put('ConvertedStatus',convertStatus.MasterLabel);

        Process.PluginRequest request = new Process.PluginRequest(inputParams);
        Process.PluginResult result;
        result = aLeadPlugin.invoke(request);
       
        Lead aLead = [select name, id, isConverted, convertedAccountID from Lead where id = :testLead.ID];
        System.Assert(aLead.isConverted);
    }


/*
  * -ve Test
  */   
    static testMethod void errorTest() {

        // Create dummy lead
        //Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe');
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
       
        // Create dummy conversion
        ConvertLead aLeadPlugin = new ConvertLead();
        Map<String,Object> inputParams = new Map<String,Object>();
        Map<String,Object> outputParams = new Map<String,Object>();
        inputParams.put('LeadID','00Q7XXXXxxxxxxx');
        inputParams.put('ConvertedStatus',convertStatus.MasterLabel);

        Process.PluginRequest request = new Process.PluginRequest(inputParams);
        Process.PluginResult result;
        try {
            result = aLeadPlugin.invoke(request);   
        }
        catch (Exception e) {
          System.debug('EXCEPTION' + e);
          System.AssertEquals(1,1);
        }
       
    }
   
   
/*
  * This test is to test the describe() method
  */
        static testMethod void describeTest() {

                ConvertLead aLeadPlugin = new ConvertLead();
                Process.PluginDescribeResult result = aLeadPlugin.describe();
               
                System.AssertEquals(result.inputParameters.size(), 8);
                System.AssertEquals(result.OutputParameters.size(), 3);
       
        }

   

}
  • February 17, 2014
  • Like
  • 0
Hi

May someone please help, I have written a trigger to create a record in a custom object when a status is changed on my assets. The test class I have passes but the percentage coverage is very low.

Trigger:

trigger createBillableSwappedAsset on Asset (after update) {

List <Billable_Swapped_Asset__c> auditTrailList = new List <Billable_Swapped_Asset__c>();

// or whatever your custom object name put instead of Vehicle__c

for ( Asset ass : Trigger.new) {

              if (Trigger.oldMap.get(ass.Id).Movement_Status__c != 'Swapped') {
 
 
  // here is where you check if asset that is being inserted meets the criteria
              if (ass.Movement_Status__c == 'Swapped' && ass.Product2Id != null && ass.Show_Device__c != true) { 


           
       //instantiate the object to put values for future record 
  Billable_Swapped_Asset__c  b =  new Billable_Swapped_Asset__c ();
        
  // now map asset fields to billable swapped asset that is being created with this asset
 
                      b.Company__c = Trigger.oldMap.get(ass.Id).AccountId;
                      b.Product__c = ass.Product2Id;
                      b.Install_Date__c =  ass.InstallDate;
                      b.End_Date__c = ass.UsageEndDate;
 
  auditTrailList.add(b);
 
 
  }//end if
 
}//end for ass

//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
  insert auditTrailList;
} catch (system.Dmlexception e) {
        system.debug (e);
    }
}

}


Test Class:

@isTest

private class TestCreateBillableSwappedAsset

{

static testMethod void TestCreateBillableSwappedAsset()
{
    Date todaysDate = System.today();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        
        //Create  & Insert Test User
  User u = new User(Alias = 'standt', Email='standarduser@sureswipe.com',
                  EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
                  LocaleSidKey='en_US', ProfileId = p.Id,
                  TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@sureswipe.com'); 
        System.runAs(u)
           
        {
          //Create and Insert Account
  Account a = new Account(Name = 'Test Company', Status__c = 'Active', Industry = 'Fashion',Type = 'Customer',
                                        Company_Email_Adress__c = 'test@test.com');
            insert a;
           
   //Create and Insert Asset
   Asset ass = new Asset(
   Name = 'Test Asset',
   Status = 'Installed',
   AccountId = a.Id,
   InstallDate = System.Today(),
   Product2Id = '01t200000024GTq',
   UsageEndDate = System.Today()
   );
   insert ass;

//Update Asset status to swapped
           
ass.status = 'Swapped';
ass.show_device__c = false;
update ass; 
           
//Update Asset status to swapped with show device true      
ass.status = 'Swapped';
ass.show_device__c = true;
update ass;
           
//Update Asset status to swapped with no product         
ass.status = 'Swapped';
ass.show_device__c = false;
ass.Product2Id = null;
update ass; 
           

        }
    }
}

  • June 19, 2014
  • Like
  • 1
I have installed a mass edit package that does the editing on a visualforce page. I am unable to add the lookup for the record type on this page can someone please assist.  I either add the record type name or the record type id but I cannot add the actuall lookup
  • March 25, 2014
  • Like
  • 1
Hi

Me again- I have written a trigger on a join object to update the one of its parent object based on the other's details.

The two objects are Accounts and Rate Type and the join object is called Company and Rate Type Links. May someone please take a look and let me know where I am going wrong as it is not firing.

trigger UpdateGroupRates on Company_and_RateType_Link__c (after update, after insert)
{  
if(trigger.isUpdate)
{
  Set<Id> accountIds = new Set<Id>();
  Set<Id> ratesIds = new Set<Id>();
  for(Company_and_RateType_Link__c tempJ : Trigger.new)
  {
   accountIds.add(tempJ.Company__c);
   ratesIds.add(tempJ.Rate_Type__c);
  }
 
  List<Account> AccountList = [Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id IN: accountIds];
 
  List<Rate_Type_del__c> Ratelist = [Select id, Name, Rate_Type__c, Number_Credit_Card_Fee__c, Number_Debit_Card_Fee__c from Rate_Type_del__c where id in: ratesIds];
 
  for(Company_and_RateType_Link__c tempJ : Trigger.new)
  {
   for(Account tempAcc : AccountList)
   {
    if(tempJ.Company__c == tempAcc.Id)
    {
     for(Rate_Type_del__c tempRate : Ratelist)
     {

                       if(tempJ.Rate_Type__c == tempRate.Id )
      {
       tempAcc.Rate_Type__c = tempRate.Rate_Type__c;
                            tempAcc.Fixed_Credit_Card_Rate__c = tempRate.Number_Credit_Card_Fee__c;
                            tempAcc.Fixed_Debit_Card_Rate__c = tempRate.Number_Debit_Card_Fee__c;
      }    
    
     }
   
    }
  
   }
  
  } 
   update AccountList;
}
      
}
  • September 09, 2014
  • Like
  • 0
Hi lovely people

I need to create a trigger that will update the accounts object based on values in either my rates object or my group rates custom object. I have a trigger to update the account based on the rates object but I would like to have a delimitor that says should there not be a rates id update using the group rate information.

Any assistance with this will be greatly appreciated.
  • September 08, 2014
  • Like
  • 0
Hello Everyone

Please may I have some help, I have this trigger and it is not firing. Can someone please take a look for me.

trigger updateRates on Rate_Type_del__c (after update) {
  
Set<Id> RateTypedelids = new Set<Id>();
    list <Account> newratelist = new list <Account>();
   
    for(Rate_Type_del__c rate:trigger.new){
        RateTypedelids.add(rate.id);
}
    List <Account> ratelist =[Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id in:RateTypedelids];
                                                 
      for(Rate_Type_del__c temprate:trigger.new){
      for(Account tempacc:ratelist){
      if(temprate.Company_del__c == tempacc.id && temprate.RecordType.Name == 'SureSwipe Base Rates' && temprate.Status__c == 'Active'){
{
    tempacc.Rate_Type__c = temprate.Rate_Type__c;
    tempacc.Fixed_Credit_Card_Rate__c = temprate.Number_Credit_Card_Fee__c;
    tempacc.Fixed_Debit_Card_Rate__c = temprate.Number_Debit_Card_Fee__c;
}
          }
        update newratelist;
    }
}

}
  • September 04, 2014
  • Like
  • 0
Hi 

I have a trigger that records the old value of a rich text area field but I am getting the following error when an update is done.

caused by: System.DmlException: Insert failed. First exception on row 3; first error: STRING_TOO_LONG, Old Value: data value too large (max length=220)

Is there a way to increase this?


  • September 01, 2014
  • Like
  • 0
Hi

I need some help with the following trigger- it creates a record in my asset history table should certain conditions be met. I need to add another condition and I am already running into apex governor limits when I do mass updates. 

trigger AssetHistoryTracking on Asset(after update){
 
  String AccId = null;
  String AccName = null;
  Integer index = 0;  
  String OldAccName = null;
 
 
 
  //create a list to hold the new record(s) to create
  List<Asset_History__c> historyObjList = new List<Asset_History__c>();
  
   for(Asset ass : Trigger.New){
    String OldAccId = Trigger.Old[index].AccountId;
    AccId = ass.AccountId;
   
  List <Account> acclist = [select name, id from Account where id = :AccId ];
    Accname = acclist[0].name;
   
    List <Account> oldacclist = [select name, id from Account where id = :OldAccId ];
    OldAccname = oldacclist[0].name;
       
     //If status changes
     if(ass.Status != Trigger.Old[index].Status){
               
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = Trigger.Old[index].Status;
     objAssetH.New_value__c = ass.Status;
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Status';
     objAssetH.Changed_By__c = UserInfo.getUserId();
                   
                         //Trigger Action Logic
                        // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
   // index++;
     }
      //when Account changes
    if(ass.AccountId != Trigger.Old[index].AccountId){
                   
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = OldAccname ;
//    objAssetH.Old_Value__c = Trigger.Old[index].AccountId;
     objAssetH.New_value__c = AccName ;
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Company Name';
     objAssetH.Changed_By__c = UserInfo.getUserId();
                   
    //Trigger Action Logic
    // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
//   index++;
     }
     //when install date changes
    if(ass.InstallDate != Trigger.Old[index].InstallDate){
                   
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = String.valueof(Trigger.Old[index].InstallDate);
     objAssetH.New_value__c = string.valueof(ass.InstallDate);
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Install Date';
     objAssetH.Changed_By__c = UserInfo.getUserId();
                   
      //Trigger Action Logic
     // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
   // index++;
         }
     //when Usage End Date changes
    if(ass.UsageEndDate != Trigger.Old[index].UsageEndDate){
                   
     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = String.valueof(Trigger.Old[index].UsageEndDate);
     objAssetH.New_value__c = string.valueof(ass.UsageEndDate);
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Usage End Date';
     objAssetH.Changed_By__c = UserInfo.getUserId();
  
                         //Trigger Action Logic
                        // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
   
    //index++;
}
     //when Stock is For Show Devices
    if(ass.Show_Device__c != Trigger.Old[index].Show_Device__c){

     Asset_History__c objAssetH = new Asset_History__c();
     objAssetH.Asset__c = ass.id;
     objAssetH.Old_Value__c = String.valueof(Trigger.Old[index].Show_Device__c);
     objAssetH.New_value__c = string.valueof(ass.Show_Device__c);
     objAssetH.Date_Changed__c = system.today();
     objAssetH.Field_Changed__c = 'Show Device';
     objAssetH.Changed_By__c = UserInfo.getUserId();
  
                         //Trigger Action Logic
                        // Asset_History__c historyObj = new Asset_History__c(Old_Value__c = Trigger.Old[index].Status, New_value__c = ass.Status);
    historyObjList.add(objAssetH);
       
    index++;
     }
  }
       
   if(historyObjList.size() > 0){
    insert historyObjList;
 
   }
}
  • August 29, 2014
  • Like
  • 0
Hi

May someone please help, I have an object called the rebate that has a lookup relationship to the account object. I want when a field is updated on the account object a field should also be updated on the rebate object but I am having a problem with this trigger.

trigger updateStartDate on Rebates__c (after insert, after update,before update){

Set<Id> accountIds = new Set<Id>();
   
    for(Rebates__c reb :trigger.new){
        accountIds.add(reb.Company__c);
}

    Map <ID,Account> updateAccounts = new Map<ID,Account>([Select id, Date_Installed__c from Account where id IN: AccountIds]);{
                                                 
for(Rebates__c reb :trigger.new){
accountIds.add(reb.Company__c);

       if(reb.From_Install_Date__c == true && updateAccounts.get(reb.Company__c).Date_Installed__c != null){

    if(reb.Product__c == '1t200000024Dtm')

{
                reb.Start_Date__c = reb.First_Day_of_the_Month__c;
   
    accountIds.update(reb);

}

else
{

   reb.Start_Date__c = reb.Install_Date__c;
    accountIds.update(reb);

       }
           try
              
           {
               update accountIds;
           }
           catch (system.DmlException e)
           {
               system.debug (e);
           }

   }
}
}
}
  • August 19, 2014
  • Like
  • 0
Hi

I am trying to create a custom button that will create a new event with a prepopulated field but I keep getting the error that my url is not valid. Can someone please help. Here is the URL.

https://cs18.salesforce.com/00U/e?who_id={!Case.AccountId}&what_id={!Case.Id}&retURL=%2F{!Case.Id}&RecordType=0122000000061K7&ent=Event&evt6={!Case.Description}
  • July 29, 2014
  • Like
  • 0
Hi

May someone please help, I have written a trigger to create a record in a custom object when a status is changed on my assets. The test class I have passes but the percentage coverage is very low.

Trigger:

trigger createBillableSwappedAsset on Asset (after update) {

List <Billable_Swapped_Asset__c> auditTrailList = new List <Billable_Swapped_Asset__c>();

// or whatever your custom object name put instead of Vehicle__c

for ( Asset ass : Trigger.new) {

              if (Trigger.oldMap.get(ass.Id).Movement_Status__c != 'Swapped') {
 
 
  // here is where you check if asset that is being inserted meets the criteria
              if (ass.Movement_Status__c == 'Swapped' && ass.Product2Id != null && ass.Show_Device__c != true) { 


           
       //instantiate the object to put values for future record 
  Billable_Swapped_Asset__c  b =  new Billable_Swapped_Asset__c ();
        
  // now map asset fields to billable swapped asset that is being created with this asset
 
                      b.Company__c = Trigger.oldMap.get(ass.Id).AccountId;
                      b.Product__c = ass.Product2Id;
                      b.Install_Date__c =  ass.InstallDate;
                      b.End_Date__c = ass.UsageEndDate;
 
  auditTrailList.add(b);
 
 
  }//end if
 
}//end for ass

//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
  insert auditTrailList;
} catch (system.Dmlexception e) {
        system.debug (e);
    }
}

}


Test Class:

@isTest

private class TestCreateBillableSwappedAsset

{

static testMethod void TestCreateBillableSwappedAsset()
{
    Date todaysDate = System.today();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        
        //Create  & Insert Test User
  User u = new User(Alias = 'standt', Email='standarduser@sureswipe.com',
                  EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
                  LocaleSidKey='en_US', ProfileId = p.Id,
                  TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@sureswipe.com'); 
        System.runAs(u)
           
        {
          //Create and Insert Account
  Account a = new Account(Name = 'Test Company', Status__c = 'Active', Industry = 'Fashion',Type = 'Customer',
                                        Company_Email_Adress__c = 'test@test.com');
            insert a;
           
   //Create and Insert Asset
   Asset ass = new Asset(
   Name = 'Test Asset',
   Status = 'Installed',
   AccountId = a.Id,
   InstallDate = System.Today(),
   Product2Id = '01t200000024GTq',
   UsageEndDate = System.Today()
   );
   insert ass;

//Update Asset status to swapped
           
ass.status = 'Swapped';
ass.show_device__c = false;
update ass; 
           
//Update Asset status to swapped with show device true      
ass.status = 'Swapped';
ass.show_device__c = true;
update ass;
           
//Update Asset status to swapped with no product         
ass.status = 'Swapped';
ass.show_device__c = false;
ass.Product2Id = null;
update ass; 
           

        }
    }
}

  • June 19, 2014
  • Like
  • 1