• Abby Becker
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 6
    Questions
  • 5
    Replies
I am new to Apex development and have the following code. I'd appreciate any help or suggestions.

Requirements: 
I will be uploading Opportunities periodically through Dataloader, all of record type "Outbound Call Opportunity." The file will contain the following info for each opp:
  • RecordTypeID
  • TIN__c (Tax ID Number)
  • Product__c
  • Outbound_Call_Score__c
I need my code to do the following:
  • Query Contacts where the Opp's TIN__c matches Contact's Tax_ID_Number__c and set Contact as Opp Owner
  • Confirm before insert that there are no other Outbound Call Opportunities with the same Contact and Product, in other words, there can only be one Outbound Call Opportunity per Contact per Product.
  • Give error if a Outbound Opportunity exists already with that contact and product, else update pertinent fields
I think I have that sorted out, but I have one remaining requirement:
  • Rollup Outbound_Call_Score__c to related Contact. Each Opp with have a numeric weight signifying how "important" it is. I want that number to aggregate and rollup to the Contact on a field also named Outbound_Call_Score__c. I am not sure how to accompish that, any help would be appreciated!
Trigger:
trigger OpportunityTrigger on Opportunity (before insert) {

  if (Trigger.isBefore) {
    if (Trigger.isInsert) {
      OpportunityHandler.insertOutboundCallLists(Trigger.new);
    } 
  }
}

Handler class:
 
public class OpportunityHandler {
    
    public OpportunityHandler() { }
    
    public static void insertOutboundCallLists(List<Opportunity> newOpps){
        Set<String> oppTINs = new Set<String>();
        String outboundCallRecTypeID = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Outbound Call Opportunity').getRecordTypeId();
        
        for(Opportunity opp : newOpps){
            oppTINs.add(opp.TIN__c);
        }        
        //system.debug(oppTINs);
        
        List<Contact> contacts = [SELECT Id, OwnerId, Tax_ID_Number__c, Outbound_Call_Score__c 
                                  FROM Contact WHERE Tax_ID_Number__c IN :oppTINs]; 
        List<Opportunity> existingOutboundOpps = new List<Opportunity>([SELECT Id, Product__c, Contact__r.Id, Contact__r.Tax_ID_Number__c 
                                                                        FROM Opportunity WHERE RecordTypeId = :outboundCallRecTypeId 
                                                                        AND Contact__r.Id IN :contacts]);
        system.debug(contacts);
        system.debug(existingOutboundOpps);
        
        if(contacts.size() > 0){
            for(Opportunity opp : newOpps){
                for(Integer i = 0; i < existingOutboundOpps.size(); i++){
                    if(opp.TIN__c == existingOutboundOpps[i].Contact__r.Tax_ID_Number__c && opp.Product__c == existingOutboundOpps[i].Product__c){
                        opp.addError('Outbound Opportunity Already Exists.');
                    } else {
                        for(Integer j = 0; j < contacts.size(); j++){
                            if(opp.TIN__c == contacts[j].Tax_ID_Number__c && opp.RecordTypeId == outboundCallRecTypeID){
                                opp.Name = 'test';
                                opp.CloseDate = system.today() + 14;
                                opp.StageName = 'Prospecting';
                                opp.OwnerId = contacts[j].OwnerId;
                                opp.Contact__c = contacts[j].Id;
                                //contacts[j].Outbound_Call_Score__c = contacts[j].Outbound_Call_Score__c + opp.Outbound_Call_Score__c;
                            }   
                        }
                    }
                }  
            } 
        } 
    }     
}



 
<div aura:id="error_message"></div>
        <div class="body-wrapper">
            <iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2FFirstNationalBank%2F&amp;tabs=timeline&amp;width=450&amp;height=1200&amp;small_header=false&amp;adapt_container_width=true&amp;hide_cover=false&amp;show_facepile=true" width="450" height="1200" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe>
        </div>

We have a lightning component that houses my company's Facebook page via a plugin within an iframe. From time to time, we get this error. I just want to confirm that this is an issue with Facebook and not the component or Salesforce platform... 

User-added image
I am a new 'admineloper' of a brand new Financial Services Cloud org.

We have records coming from our banking core and my business unit does not want to change the record type of them. They all come in with the same record type on an object within the managed package. They want different page layouts (or Visual Force pages) dependent on a value in a field on the record.

I have no idea how to execute this - directing records of the same record type to different layouts (or Visual Force pages) based on a field value - not the record type... is this even possible?

I am working in a managed packaged, Financial Services Cloud, and am aware that this limits my development, although - this early on - I'm not sure to what extent...

Any advice or direction is appreciated. Thanks.
Hi,

I work for a community bank as an 'admineloper.' I have a custom object named Financial_Account__c and a field on that object named Responsibility_Code__c. This information is flooded from our core financial processor every night by an ETL tool. Currently, every Financial_Account_c record is owned by a dummy user used by our ETL tool. (As far as I'm aware, this is due to a limitation of our ETL tool/core.)

We are looking for a way to correct that so a User owns the record - not the dummy account.

My initial thoughts are to create a field on the User object named User_Responsiblity_Code__c and build some logic to evaluate 'if User_Responsibility_Code__c on the User object matches Responsiblity_Code__c on the Financial_Account__c custom object, change Record Owner to that User.'

I'm just not entirely sure how to go forward. Any insight or suggestions would be appreciated.

Thanks.
New 'adminelope'r here - grateful for any advice that's thrown my way!

I have an Apex trigger on the Attachment sObject that changes the value of a checkbox on a related object to True when an attachment is added to the record. Below is the trigger:
 
trigger AttachmentAdded on Attachment (before insert) {	
 	
	list<Customer_Tool__c> ctListA = new List<Customer_Tool__c>();
	list<Customer_Tool__c> ctListB = new List<Customer_Tool__c>();
	Set<id> ctID = new Set<id>();

	for(Attachment at : trigger.new) {
		ctID.add(at.parentid);
	}

	ctListA = [Select id, Has_Attachment__c from Customer_Tool__c where id in: ctID];
		if(ctListA!=null && ctListA.size()>0){
			for(Customer_Tool__c ct : ctListA) {
				ct.Has_Attachment__c = true;
				ctListB.add(ct);
			}
			update ctListB;
		}
}

When the Has_Attachment__c custom field is updated to 'True,' I have a workflow rule that executes to notify another department that an attachment has been added to the record. The workflow rule also has a Field Update that "unchecks" the Has_Attachment__c field so that if ANOTHER attachment is added, they'll be notified again.

My question is how do I write a test class for this? When I deactivate the workflow rule, my test class passes. It's the workflow rule and field update that is messing it up... I just don't know how to go forward from here. Below is my test method:
 
static testMethod void testOneAttachment () {
		Customer_Tool__c ct1 = new Customer_Tool__c();
		insert ct1;

		Attachment att = new Attachment();
		Blob b = Blob.valueOf('Test Data');
		att.Name = 'Unit Test Attachment';
		att.Body = b;
		att.ParentID = ct1.Id;
		att.IsPrivate = false;
		insert att;

		List<Customer_Tool__c> cts = [select Has_Attachment__c from Customer_Tool__c where Id = :ct1.Id];

		System.assertEquals(1, cts.size());
		System.assertEquals(true, cts[0].Has_Attachment__c);  //This is failing the test because of the field update
	} //testOneAttachment

Thanks in advance

Hi all,

New "admineloper" here. I have an Apex trigger that checks a custom field "Has_Attachment__c" when an attachment is added to a record, then a workflow rule that sends an email alert to the record owner, notifying them that an attachment has been added.  Right now, it works great the FIRST time an attachment is added. Any further attachments, don't generate emails.

How can I go about sending an email for every added attachment? Is there a way to uncheck the box after the trigger has executed and the email has been sent? Below is my Apex trigger.
 

trigger AttachmentAdded on Attachment (before insert) {	
 
	list<Customer_Tool__c> ctList = new List<Customer_Tool__c>();
	list<Customer_Tool__c> ctListAdded = new List<Customer_Tool__c>();
	Set<id> ctID = new Set<id>();

	for(Attachment at : trigger.new) {
		ctID.add(at.parentid);
	}

	ctList = [Select id, Has_Attachment__c from Customer_Tool__c where id in: ctID];
		if(ctList!=null && ctList.size()>0){
			for(Customer_Tool__c ct : ctList) {
				ct.Has_Attachment__c = true;
				ctListAdded.add(ct);
			}
			update ctListAdded;
		}
}
 

Very new to development - so any advice/help/guidance would be greatly appreciated!

Thanks,

I am new to Apex development and have the following code. I'd appreciate any help or suggestions.

Requirements: 
I will be uploading Opportunities periodically through Dataloader, all of record type "Outbound Call Opportunity." The file will contain the following info for each opp:
  • RecordTypeID
  • TIN__c (Tax ID Number)
  • Product__c
  • Outbound_Call_Score__c
I need my code to do the following:
  • Query Contacts where the Opp's TIN__c matches Contact's Tax_ID_Number__c and set Contact as Opp Owner
  • Confirm before insert that there are no other Outbound Call Opportunities with the same Contact and Product, in other words, there can only be one Outbound Call Opportunity per Contact per Product.
  • Give error if a Outbound Opportunity exists already with that contact and product, else update pertinent fields
I think I have that sorted out, but I have one remaining requirement:
  • Rollup Outbound_Call_Score__c to related Contact. Each Opp with have a numeric weight signifying how "important" it is. I want that number to aggregate and rollup to the Contact on a field also named Outbound_Call_Score__c. I am not sure how to accompish that, any help would be appreciated!
Trigger:
trigger OpportunityTrigger on Opportunity (before insert) {

  if (Trigger.isBefore) {
    if (Trigger.isInsert) {
      OpportunityHandler.insertOutboundCallLists(Trigger.new);
    } 
  }
}

Handler class:
 
public class OpportunityHandler {
    
    public OpportunityHandler() { }
    
    public static void insertOutboundCallLists(List<Opportunity> newOpps){
        Set<String> oppTINs = new Set<String>();
        String outboundCallRecTypeID = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Outbound Call Opportunity').getRecordTypeId();
        
        for(Opportunity opp : newOpps){
            oppTINs.add(opp.TIN__c);
        }        
        //system.debug(oppTINs);
        
        List<Contact> contacts = [SELECT Id, OwnerId, Tax_ID_Number__c, Outbound_Call_Score__c 
                                  FROM Contact WHERE Tax_ID_Number__c IN :oppTINs]; 
        List<Opportunity> existingOutboundOpps = new List<Opportunity>([SELECT Id, Product__c, Contact__r.Id, Contact__r.Tax_ID_Number__c 
                                                                        FROM Opportunity WHERE RecordTypeId = :outboundCallRecTypeId 
                                                                        AND Contact__r.Id IN :contacts]);
        system.debug(contacts);
        system.debug(existingOutboundOpps);
        
        if(contacts.size() > 0){
            for(Opportunity opp : newOpps){
                for(Integer i = 0; i < existingOutboundOpps.size(); i++){
                    if(opp.TIN__c == existingOutboundOpps[i].Contact__r.Tax_ID_Number__c && opp.Product__c == existingOutboundOpps[i].Product__c){
                        opp.addError('Outbound Opportunity Already Exists.');
                    } else {
                        for(Integer j = 0; j < contacts.size(); j++){
                            if(opp.TIN__c == contacts[j].Tax_ID_Number__c && opp.RecordTypeId == outboundCallRecTypeID){
                                opp.Name = 'test';
                                opp.CloseDate = system.today() + 14;
                                opp.StageName = 'Prospecting';
                                opp.OwnerId = contacts[j].OwnerId;
                                opp.Contact__c = contacts[j].Id;
                                //contacts[j].Outbound_Call_Score__c = contacts[j].Outbound_Call_Score__c + opp.Outbound_Call_Score__c;
                            }   
                        }
                    }
                }  
            } 
        } 
    }     
}



 
Hi,

I work for a community bank as an 'admineloper.' I have a custom object named Financial_Account__c and a field on that object named Responsibility_Code__c. This information is flooded from our core financial processor every night by an ETL tool. Currently, every Financial_Account_c record is owned by a dummy user used by our ETL tool. (As far as I'm aware, this is due to a limitation of our ETL tool/core.)

We are looking for a way to correct that so a User owns the record - not the dummy account.

My initial thoughts are to create a field on the User object named User_Responsiblity_Code__c and build some logic to evaluate 'if User_Responsibility_Code__c on the User object matches Responsiblity_Code__c on the Financial_Account__c custom object, change Record Owner to that User.'

I'm just not entirely sure how to go forward. Any insight or suggestions would be appreciated.

Thanks.
New 'adminelope'r here - grateful for any advice that's thrown my way!

I have an Apex trigger on the Attachment sObject that changes the value of a checkbox on a related object to True when an attachment is added to the record. Below is the trigger:
 
trigger AttachmentAdded on Attachment (before insert) {	
 	
	list<Customer_Tool__c> ctListA = new List<Customer_Tool__c>();
	list<Customer_Tool__c> ctListB = new List<Customer_Tool__c>();
	Set<id> ctID = new Set<id>();

	for(Attachment at : trigger.new) {
		ctID.add(at.parentid);
	}

	ctListA = [Select id, Has_Attachment__c from Customer_Tool__c where id in: ctID];
		if(ctListA!=null && ctListA.size()>0){
			for(Customer_Tool__c ct : ctListA) {
				ct.Has_Attachment__c = true;
				ctListB.add(ct);
			}
			update ctListB;
		}
}

When the Has_Attachment__c custom field is updated to 'True,' I have a workflow rule that executes to notify another department that an attachment has been added to the record. The workflow rule also has a Field Update that "unchecks" the Has_Attachment__c field so that if ANOTHER attachment is added, they'll be notified again.

My question is how do I write a test class for this? When I deactivate the workflow rule, my test class passes. It's the workflow rule and field update that is messing it up... I just don't know how to go forward from here. Below is my test method:
 
static testMethod void testOneAttachment () {
		Customer_Tool__c ct1 = new Customer_Tool__c();
		insert ct1;

		Attachment att = new Attachment();
		Blob b = Blob.valueOf('Test Data');
		att.Name = 'Unit Test Attachment';
		att.Body = b;
		att.ParentID = ct1.Id;
		att.IsPrivate = false;
		insert att;

		List<Customer_Tool__c> cts = [select Has_Attachment__c from Customer_Tool__c where Id = :ct1.Id];

		System.assertEquals(1, cts.size());
		System.assertEquals(true, cts[0].Has_Attachment__c);  //This is failing the test because of the field update
	} //testOneAttachment

Thanks in advance

Hi all,

New "admineloper" here. I have an Apex trigger that checks a custom field "Has_Attachment__c" when an attachment is added to a record, then a workflow rule that sends an email alert to the record owner, notifying them that an attachment has been added.  Right now, it works great the FIRST time an attachment is added. Any further attachments, don't generate emails.

How can I go about sending an email for every added attachment? Is there a way to uncheck the box after the trigger has executed and the email has been sent? Below is my Apex trigger.
 

trigger AttachmentAdded on Attachment (before insert) {	
 
	list<Customer_Tool__c> ctList = new List<Customer_Tool__c>();
	list<Customer_Tool__c> ctListAdded = new List<Customer_Tool__c>();
	Set<id> ctID = new Set<id>();

	for(Attachment at : trigger.new) {
		ctID.add(at.parentid);
	}

	ctList = [Select id, Has_Attachment__c from Customer_Tool__c where id in: ctID];
		if(ctList!=null && ctList.size()>0){
			for(Customer_Tool__c ct : ctList) {
				ct.Has_Attachment__c = true;
				ctListAdded.add(ct);
			}
			update ctListAdded;
		}
}
 

Very new to development - so any advice/help/guidance would be greatly appreciated!

Thanks,

Hello, as from the title of my post I am having problems with some simple stuff, but I assume it's a problem with my companies connection or salesforce.

My playgrounds will get created, but when I go to launch them it comes up with "This page can't be displayed", and even after refreshing 5+ min down the road, nothing happens.

Also, during my sample data initialization. I would let it pend for about 5-10 min before I'd try to refresh the page, but it also wouldn't go through.
The internet at my company is a little slow today, but everything else seems to work fine, so I am not sure if it's a salesforce related issue or not.

Thanks for any insight.
Hello, as from the title of my post I am having problems with some simple stuff, but I assume it's a problem with my companies connection or salesforce.

My playgrounds will get created, but when I go to launch them it comes up with "This page can't be displayed", and even after refreshing 5+ min down the road, nothing happens.

Also, during my sample data initialization. I would let it pend for about 5-10 min before I'd try to refresh the page, but it also wouldn't go through.
The internet at my company is a little slow today, but everything else seems to work fine, so I am not sure if it's a salesforce related issue or not.

Thanks for any insight.