• Sean McMickle
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 18
    Replies
Hi everyone,

   I am newbie to salesforce and i want help to update the parent account of amount field when ever the contact of amount field is inserted or updated.and i have the scenario like when ever the contact is created or updated the amount field of account should be auto populated this is the first scenario. The second scenario is when the 2nd contact is created if the amount field is greater the first amount the greater amount field should be populated on the account amount field. The 3rd scenario is there are two check boxes greater amount and lesser amount in the account object this should be populated with the latest contact whether it should be greater or lesser than the previous account.

The fields are
Account object:
Parent_amount__c = Text field
Greater_amount__c = checkbox
Lesser_Amount__c = checkbox

Contact object:
Amount__c 

I have written some code only for update thing and please help me for second and third scenarios.

The 1st scenario is also giving error for me.

trigger UpdateAmount on Contact (after insert, after update) { //You want it on update too, right?
  Map<ID, Account> parentOpps = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (contact childObj : Trigger.new) {
    listIds.add(childObj.Account.id);
  }

  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called Quotes__r (not Quote__r) but check
  //You only need to select the child quotes if you are going to do something for example checking whether the quote in the trigger is the latest
  parentOpps = new Map<Id, account>([SELECT id, Parent_amount__c,Greater_amount__c,Lesser_Amount__c,Name,(SELECT ID, Amount__c FROM contacts) FROM Account WHERE ID IN :listIds]);

  for (contact con: Trigger.new){
     Account myParentOpp = parentOpps.get(con.Account.id);
     myParentOpp.Parent_amount__c = con.Amount__c;
  }

  update parentOpps.values();

}

The error is 
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger UpdateAmount caused an unexpected exception, contact your administrator: UpdateAmount: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateAmount: line 16, column 1

Please help in fixing the bug and please suggest me for 2nd and 3rd scenarios

Thanks.
I have not been able to find any documentation regarding sharing OneDrive files using Apex. Does anyone have an example or a resource that they could give?

I would like to be able to use condition based triggers to attach particular files from particular folders from OneDrive to particular objects.

Thanks!

-Sean
We have a custom object and around 2 million records. We would like to do a clean up on duplicate records. Like if they have same name, same email, opt out flag etc. I would like to create a batch class to delete the duplicate records and just keep one record.

For ex:

Record1: Name = Name1 Email = name1@name.com opt out = true created date 01/01
Record 2:  Name = Name1 Email = name1@name.com opt out = true created date 02/02
Record 3: Name = Name1 Email = name1@name.com opt out = true created date 03/03

I woul dlike to delete 2 records and keep the most recent created date record. So in this case, delete Record 1 an dRecord 2 and keep Record 3

Can someone help with this batch class? I appreciate your help!
  • September 08, 2016
  • Like
  • 0

I am trying to create a Table in the dashboard, which contains 4 columns and the values are displayed priority wise. Please see the below screen shot.

User-added image

Can anyone tell me how can i do this using visual force page? Your help would be really appreciated. 

Hi everyone,

   I am newbie to salesforce and i want help to update the parent account of amount field when ever the contact of amount field is inserted or updated.and i have the scenario like when ever the contact is created or updated the amount field of account should be auto populated this is the first scenario. The second scenario is when the 2nd contact is created if the amount field is greater the first amount the greater amount field should be populated on the account amount field. The 3rd scenario is there are two check boxes greater amount and lesser amount in the account object this should be populated with the latest contact whether it should be greater or lesser than the previous account.

The fields are
Account object:
Parent_amount__c = Text field
Greater_amount__c = checkbox
Lesser_Amount__c = checkbox

Contact object:
Amount__c 

I have written some code only for update thing and please help me for second and third scenarios.

The 1st scenario is also giving error for me.

trigger UpdateAmount on Contact (after insert, after update) { //You want it on update too, right?
  Map<ID, Account> parentOpps = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (contact childObj : Trigger.new) {
    listIds.add(childObj.Account.id);
  }

  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called Quotes__r (not Quote__r) but check
  //You only need to select the child quotes if you are going to do something for example checking whether the quote in the trigger is the latest
  parentOpps = new Map<Id, account>([SELECT id, Parent_amount__c,Greater_amount__c,Lesser_Amount__c,Name,(SELECT ID, Amount__c FROM contacts) FROM Account WHERE ID IN :listIds]);

  for (contact con: Trigger.new){
     Account myParentOpp = parentOpps.get(con.Account.id);
     myParentOpp.Parent_amount__c = con.Amount__c;
  }

  update parentOpps.values();

}

The error is 
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger UpdateAmount caused an unexpected exception, contact your administrator: UpdateAmount: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateAmount: line 16, column 1

Please help in fixing the bug and please suggest me for 2nd and 3rd scenarios

Thanks.
I've been researching this for two weeks, and I can only come up with half the solution.  I need to have the same capability as the standard Clone, but be able to pull in pre-populated fields.  We currently use Super Clone (https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B4mjFEAR), but I can't use that to pull data from one custom object (Expiring Structure) to another (Pricing Option).  Plus, with over a 100 fields on each page, it's really hard to maintain the page layouts.  

I'm starting with a simple clone of Pricing Option before I move onto something more difficult, but I'm lost as to how to proceed.  I DO NOT want to use a URL hack because that will not function correctly when we move to Lightning. I use that solution on several other objects, but I want to code this using Apex and VF on this object.

I've studied Jeff Douglas' code (http://blog.jeffdouglas.com/2009/11/19/apex-deep-clone-controller/) and can successfully clone the record with pre-populated data.  Unfortunately, you have to insert the record and then open in edit mode.  I do not want the record created before the user chooses to complete the clone process.
//Created from instructions by Jeff Douglas: http://blog.jeffdouglas.com/2009/11/19/apex-deep-clone-controller/

public with sharing class PricingOptionCloneController {
    
	//add an instance variable for the standard controller
    private ApexPages.StandardController controller {get; set;}

    //add the instance for the variables being passed by id on the url
    private Pricing_Option__c clonePO {get; set;}
    
    //set the id of the record that is created -- only used by test class
    public ID newRecordId {get; set;}
    
    //initialize the controller
    public PricingOptionCloneController(ApexPages.StandardController controller){
    	
    	//initialize the standard controller
        this.controller = controller;
        
        //load the current record
        clonePO = (Pricing_Option__c)controller.getRecord();
    
    }
    
    //method called from the VF's action attribute to clone the case
    public PageReference cloneSelectFields(){
    	
    	//setup the save point for rollback
    	Savepoint sp = Database.setSavepoint();
    	Pricing_Option__c newPO;
    	
    	try{
    		//copy the pricing option -- only include the fields that should be cloned
    		clonePO = [SELECT id, 
    					Opportunity__c,    					
    					Underlying_Comments__c
    				 FROM Pricing_Option__c
    				 WHERE id = :clonePO.id];
    		newPO = clonePO.clone(false);
    		newPO.Name = 'Autopopulated';
    		newPO.Pricing_Option_Description__c = 'update field';
    		newPO.Managing_Director_Pricing_Comments__c = 'update field';
    		insert newPO;
    		    		
    		//set the id of the new po created for testing
    		newRecordId = newPO.id;    		
    		    		
    	} catch (Exception e){
    		//roll the database back to before record was saved
    		Database.rollback(sp);
    		//add a page error/send an email/debug etc.
    		ApexPages.addMessages(e);
    		return null;
    	}
    	return new PageReference('/'+newPO.id+'/e?retURL=%2F'+newPO.id);
    }    
}

<apex:page standardController="Pricing_Option__c" 
    extensions="PricingOptionCloneController"
    action="{!cloneSelectFields}">
    <apex:pageMessages />
</apex:page>
I've also studied Deepak Gulian's code (https://developer.salesforce.com/forums?id=906F0000000D8XwIAK) and can successfully clone a record into edit mode without first inserting, but I cannot pre-prepopulate any of the fields.
//Created from instructions by Deepak Gulian: https://developer.salesforce.com/forums?id=906F0000000D8XwIAK

public with sharing class AccountController {

    public Account objAccount {get;set;}        
    public string AccountID;                        
   
    public AccountController(ApexPages.StandardController controller){       
       accountid = controller.getId();    
    }
   
    public PageReference autoRun(){
        PageReference clonePage = new PageReference('/'+accountid+'/e?clone=1&retURL=%2F'+accountid);
        clonePage.setRedirect(true);
        return clonePage;
    }   

}

<apex:page standardController="Account" extensions="AccountController" action="{!autoRun}">

  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have been redirected back to the record you clicked the button from.
  </apex:outputPanel>
</apex:page>
I really need a blend of both techniques, but all of my attempts to modify their code has failed.  Can someone assist me in where I need to go?
I'm very new to development, and this is the first Apex Class I've built not using the training courses as guidelines.  My Apex Class and Trigger seem to be working fine, but I'm only getting 50% coverage on my test code.  I'm studied dozens of test code over the last two weeks, and tried oh so many attempts to get this to work, but just don't have the knowledge yet to troubleshoot.

In a nutshell, when an Opportunity is 30 days prior to CloseDate, I need to check a box on the Opp that will trigger a Process Builder process that my admin can maintain.  So simple, yet for some reason so complicated.

Can someone point me in the right direction?  Thanks!

Apex Class
public class OFACMCOQuote {
	
	//create list of Opps
	public static void OFACTask(List<Opportunity> oppList){
		System.Debug('OFACTask: Entering');
			
		oppList = [SELECT Id, Name, isMCOOFACQuoteTriggered__c
	  			   FROM Opportunity 
	  			   WHERE (Type = 'Renewal' OR Type = 'Guaranteed Renewal') 
	  			     AND isClosed = False
	  			     AND Market_Segment__c = 'Managed Care Organization'
	  			     AND CloseDateTrigger_30__c <= TODAY
	  			     AND isMCOOFACQuoteTriggered__c = False]; {
	  				  	  
	 		//field update to trigger process
	 		for(Opportunity opp : oppList) {
	  			System.debug('Name: ' + opp.Name);
	  			if (!oppList.isEmpty()){
					opp.isMCOOFACQuoteTriggered__c = True;	  				
	  			}
	  		}
	 		update oppList;
	  	}	
	}  					 
}
Apex Trigger
trigger OFACMCOTriggers on Opportunity (after insert, after update) {
	OFACMCOQuote.OFACTask(Trigger.new);
	OFACMCOBinder.OFACTask(Trigger.new);
}
Test Class:
@isTest
private class OFACMCOQuote_Test {

	//Verify that OFAC task and notification are triggered
    static testMethod void OFACTask_Test() {
        
		//Load test Profile
    	Map<String, Profile> profiles = new Map<String, Profile>();
        for(Profile p : [select id, name from profile where name IN ('System Administrator')]){
            profiles.put(p.Name, p);
        }
        
        //Load test User
        User u1 = new User(alias = 'test01', email='test01@testorg.com',
                        emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                        localesidkey='en_US', profileid = profiles.get('System Administrator').Id,
                        timezonesidkey='America/Los_Angeles', username='test01@testorg.com', CommunityNickname = 'test01');
    	insert new List<User>{u1};
        
        //Load test Account 
      	Account acc1 = new Account(Name='Test01', Managing_Director_lu__c = u1.Id);
        insert new List<Account>{acc1};
    
        //Load test Opportunity 
      	Opportunity opp1 = new Opportunity(AccountId = acc1.Id, Name = 'Test Opp 1', StageName = 'Qualified', Submission_Entry__c = FALSE, 
      										Managing_Director_lu__c = u1.Id, Market_Segment__c = 'Managed Care Organization', 
      										Type = 'Renewal', CloseDate = date.Today()/*, isMCOOFACQuoteTriggered__c = TRUE*/);
      	//Opportunity opp2 = new Opportunity(AccountId = acc1.Id, Name = 'Test Opp 2', StageName = 'Qualified', Submission_Entry__c = FALSE, 
      		//								Managing_Director_lu__c = u1.Id, CloseDate = Date.today(), isMCOOFACQuoteTriggered__c = FALSE);
      	insert new List<Opportunity>{opp1};
      	
      	opp1.CloseDate = opp1.MCOOFACDateHelper__c;
      	update new List<Opportunity>{opp1};
      	        
        Map<Id, Opportunity> opps2Check = new Map<Id, Opportunity>([SELECT Id, CloseDate, isMCOOFACQuoteTriggered__c
        															FROM Opportunity WHERE Id IN :new List<Opportunity>{opp1}]);
        System.assert(opps2Check.get(opp1.Id).isMCOOFACQuoteTriggered__c);
        System.assertEquals(opp1.isMCOOFACQuoteTriggered__c,opps2Check.get(opp1.Id).isMCOOFACQuoteTriggered__c);
        //System.assertNotEquals(opp2.isMCOOFACQuoteTriggered__c,opps2Check.get(opp2.Id).isMCOOFACQuoteTriggered__c);       
    }
}
I have a class which assigns Name field by appending two other fields -

Ex -

Name = Name + '-' + Market__c;

I have a trigger which appends the name with autonumber -

Name = Name + '-' + Market__c + '-' + autonumber;

Below is the problem which i am facing -

On insert it creates the name like -

Name = X-A-1

When i insert another record it creates the name like -

Name = X-A-1-1
Name = X-B-2

But i want the on insert it should continue the autonumber, Not start it again from 1st record.
 
trigger childrfptest on ChildRFP__c (after insert) {
    integer auto=1;
    set<id> uatid = new set<id>();

    for(ChildRFP__c r:trigger.new){
        uatid.add(r.id); 
    }

    List<ChildRFP__c> cp = new List<ChildRFP__c>();
    List<ChildRFP__c> cp1 = new List<ChildRFP__c>();
    cp = [select Parent_RFP__c from ChildRFP__c where id =:uatid];

    for(ChildRFP__c cd: cp)
    {    
       cp1=  [select Id,Name from ChildRFP__c where Parent_RFP__c =:cd.Parent_RFP__c];

    }
    auto=1;
    for( ChildRFP__c cd1: cp1)
    {

        cd1.Name= cd1.Name + '-'+ auto;
        update cd1;

        auto++;
    }

}

Regards
 
Hi,

I  have a method in a controller, which takes to the edit page of a contact where user can edit the contact and save.
How do i compare the old and new values of that contact ?

apex Controller
==============

public pageReference gotoContactEditPage()
{
             PageReference conEditPage = new PageReference('/' + contactId+ '/e');         
             conEditPage.setRedirect(true);
            // Here i want to compare the old and new values of contact (before save and after save)
             return conEditPage
           


}

 
I no longer have access to my old trailhead account, it was tied with my previous works email address. Is there a way to transfer my badges to my new account?