• LloydSilver
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 32
    Replies
I'm getting a Too many SOQL queries error on a trigger. Unfortunately, my developer has gone MIA. I'd greatly appreciate help and if it's something not simple I'm willing to pay to get it fixed (just send me a PM).

Specifically, the error is:
 
Apex script unhandled trigger exception by user/organization: 005i0000001Fi5L/00Di0000000H8nt

LumpSum_Trigger: System.LimitException: CFL:Too many SOQL queries: 101

Here is the relevant code (classes and triggers, likley some not involved but I wasn't sure). Thanks for taking a peak. I've done everything within my limited knowledge to figure it out to no avail.

TRIGGER
trigger LumpSum_Trigger on Insurance_Case__c (after update) {
    
    if (!CommissionExtensionHelper.hasLumpsumAlreadyCreated()) {
        InsuranceCaseHelperclass.UpdateAgentCaseCommissionOnCaseUpdate(Trigger.NewMap,Trigger.oldMap);
    }    
    CommissionExtensionHelper.setLumpsumAlreadyCreated();
    
    
}

COMMISSION EXTENSION HELPER CLASS
public with sharing class CommissionExtensionHelper {
  
   private static boolean x1035CommissionCalculated = false;
   private static boolean LumpsumCommissionCalculated = false;
   
    private static boolean bytrigger = false;
   
     public static boolean getbytrigger() {
        return  bytrigger;
    }
    
     public static void setbytrigger() {
       bytrigger = true;
    }
    
    public static boolean has1035AlreadyCreated() {
        return x1035CommissionCalculated;
    }

    
    
    public static void set1035AlreadyCreated() {
        x1035CommissionCalculated= true;
    }


    public static String get1035AlreadyCreated(String x1035created) {
        return 'x1035created: ' + x1035created;
    }
    
    
     public static boolean hasLumpsumAlreadyCreated() {
        return LumpsumCommissionCalculated;
    }

    
    
    public static void setLumpsumAlreadyCreated() {
        LumpsumCommissionCalculated= true;
    }


    public static String getLumpsumAlreadyCreated(String Lumpsum) {
        return 'Lumpsumcreated: ' + Lumpsum;
    }
   
  

}
INSURANCE CASE HELPER CLASS
public class InsuranceCaseHelperclass{


    public static void UpdateAgentCaseCommissionOnCaseUpdate(Map<Id,Insurance_Case__c> newMap,Map<Id,Insurance_Case__c> oldMap){
            Map<Id, Insurance_Case__c> cases = new Map<Id, Insurance_Case__c>();
            Map<Id, Insurance_Case__c> casesstatus = new Map<Id, Insurance_Case__c>();
            Agent_Cases_Commissions__c[] accToUpdate = new Agent_Cases_Commissions__c[0];
            
            for(Insurance_Case__c record: newMap.Values()){
                Insurance_Case__c oldcase = oldMap.get(record.Id);
                if(record.Status__c != oldcase.Status__c && record.Status__c != 'Submitted'){
                    casesstatus.put(record.Id, record);
                } 
                else {
                    cases.put(record.Id, record);
                }
            }
            
            Agent_Cases_Commissions__c[] accstatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :casesstatus.keyset() AND Contract_Type__c = 'Agent Contract'];
            Agent_Cases_Commissions__c[] accnostatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :cases.keyset() AND Contract_Type__c = 'Agent Contract'];
            
            for(Agent_Cases_Commissions__c acc :accstatus){
                acc.Case_Status_Change__c = TRUE;
                accToUpdate.add(acc);
            }
            
            for(Agent_Cases_Commissions__c acc2 :accnostatus){
                accToUpdate.add(acc2);
            }
            
            if(!accToUpdate.isEmpty()){
                update accToUpdate;
            }
      }
}

UPDATEAGENTCASECOMMISSIONONUPDATE TRIGGER
trigger UpdateAgentCaseCommissionOnCaseUpdate on Insurance_Case__c (after update) {

    Map<Id, Insurance_Case__c> cases = new Map<Id, Insurance_Case__c>();
    Map<Id, Insurance_Case__c> casesstatus = new Map<Id, Insurance_Case__c>();
    Agent_Cases_Commissions__c[] accToUpdate = new Agent_Cases_Commissions__c[0];
    
    for(Insurance_Case__c record: Trigger.new){
        Insurance_Case__c oldcase = Trigger.oldMap.get(record.Id);
        if(record.Status__c != oldcase.Status__c && record.Status__c != 'Submitted'){
            casesstatus.put(record.Id, record);
        } else {
            cases.put(record.Id, record);
        }
    }
    
    Agent_Cases_Commissions__c[] accstatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :casesstatus.keyset() AND Contract_Type__c = 'Agent Contract'];
    Agent_Cases_Commissions__c[] accnostatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :cases.keyset() AND Contract_Type__c = 'Agent Contract'];
    
    for(Agent_Cases_Commissions__c acc :accstatus){
        acc.Case_Status_Change__c = TRUE;
        accToUpdate.add(acc);
    }
    
    for(Agent_Cases_Commissions__c acc2 :accnostatus){
        accToUpdate.add(acc2);
    }
    
    if(!accToUpdate.isEmpty())
    update accToUpdate;

}



Again, thanks so much. I'm not sure if this is simple or not. If not, happy to pay for a fix.
 

I'm running into a bulk update issue on the trigger below. I thought that I properly structured the apex for bulkification but apparently I didn't and I'm stuck. I'd really appreciate some help. Thanks.

 

trigger UpdateAgentCaseCommissionOnCaseUpdate on Insurance_Case__c (after update) {

  Map<Id, Insurance_Case__c> cases = new Map<Id, Insurance_Case__c>();
  Map<Id, Insurance_Case__c> casesstatus = new Map<Id, Insurance_Case__c>();
  Agent_Cases_Commissions__c[] accToUpdate = new Agent_Cases_Commissions__c[0];
  
  for(Insurance_Case__c record: Trigger.new){
    Insurance_Case__c oldcase = Trigger.oldMap.get(record.Id);
    if(record.Status__c != oldcase.Status__c && record.Status__c != 'Submitted'){
      casesstatus.put(record.Id, record);
    } else {
      cases.put(record.Id, record);
    }
  }
  
  Agent_Cases_Commissions__c[] accstatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :casesstatus.keyset() AND Contract_Type__c = 'Agent Contract'];
  Agent_Cases_Commissions__c[] accnostatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :cases.keyset() AND Contract_Type__c = 'Agent Contract'];
  
  for(Agent_Cases_Commissions__c acc :accstatus){
    acc.Case_Status_Change__c = TRUE;
    accToUpdate.add(acc);
  }
  
  for(Agent_Cases_Commissions__c acc2 :accnostatus){
    accToUpdate.add(acc2);
  }
  
  if(!accToUpdate.isEmpty())
  update accToUpdate;

}

 

Ran into a bulk issue on a class. I re-wrote it (See attached code) but am having an issue still. The problem is with creating the list of opportunities by adding them to a list via looking up their ID in the list for OpportunityContactRole (line 15 through 18).

 

My interpretation of:

 

List<Opportunity> oppSureLC = [select ID, StageName from Opportunity where ID IN :ocrSureLC];

 

Is that it should add an opportunity to the list if the ID of the opportunity is included in the OpportunityContactRole list, which contains OpportunityID. Obviously I'm wrong.

 

I'd appreciate help in fixing this. Do I need to use a for statement to add the Opportunities instead of doing it within a list? Is there a way of using a relationship query to eliminate some of this? 

 

public class UpdateOpportunityStageOnContact {
	
		public static void agentstatus(Contact[] contactsToUpdate) {
			
			List<Contact> conSureLC = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'SureLC Packet Complete' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			List<Contact> conCarrier = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'Carrier Contracting Complete' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			List<Contact> conFirst = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'First Case Submitted' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			List<Contact> conClient = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'Client' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			
			List<OpportunityContactRole> ocrSureLC = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conSureLC];
			List<OpportunityContactRole> ocrCarrier = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conCarrier];
			List<OpportunityContactRole> ocrFirst = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conFirst];
			List<OpportunityContactRole> ocrClient = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conClient];
			
			List<Opportunity> oppSureLC = [select ID, StageName from Opportunity where ID IN :ocrSureLC];
			List<Opportunity> oppCarrier = [select ID, StageName from Opportunity where ID IN :ocrCarrier];
			List<Opportunity> oppFirst = [select ID, StageName from Opportunity where ID IN :ocrFirst];
			List<Opportunity> oppClient = [select ID, StageName from Opportunity where ID IN :ocrClient];
			
			List<Opportunity> oppsToUpdateSureLC = new List<Opportunity>{};
			List<Opportunity> oppsToUpdateContracting = new List<Opportunity>{};
			List<Opportunity> oppsToUpdateFirst = new List<Opportunity>{};
			List<Opportunity> oppsToUpdateClient = new List<Opportunity>{};
			
			for(Opportunity opp1: oppSureLC){
						opp1.StageName = 'SureLC Packet Complete';
						oppsToUpdateSureLC.add(opp1);
			}
					
			for(Opportunity opp2: oppCarrier){
						opp2.StageName = 'Carrier Contracting Complete';
						oppsToUpdateContracting.add(opp2);
			}
					
			for(Opportunity opp3: oppFirst){
						opp3.StageName = 'First Case Submitted';
						oppsToUpdateFirst.add(opp3);
			}

			for(Opportunity opp4: oppClient){
						opp4.StageName = 'Closed Won';
						oppsToUpdateClient.add(opp4);
			}
			
			if(!oppsToUpdateSureLC.isEmpty())
			update oppsToUpdateSureLC;
			
			if(!oppsToUpdateContracting.isEmpty())
			update oppsToUpdateContracting;
			
			if(!oppsToUpdateFirst.isEmpty())
			update oppsToUpdateFirst;
			
			if(!oppsToUpdateClient.isEmpty())
			update oppsToUpdateClient;
			
		}

}

 

I'd like this trigger to check a contact's old (before update) value of a field to the new value, and if it has changed, AND if the new field is of a certain value, to then pass the list of contacts to a class.

 

Below is my first draft of the code and it's not working. I've also included the class just in case there's an issue there, but that did deploy successfully.

 

The error I'm getting is:

 

Method does not exist or incorrect signature: UpdateOpportunityStageOnContact.agentstatus(LIST<Id>)

 

So I don't think my call to the class is formatted correctly. Or I'm not using the list correctly.

 

Thanks!

 

trigger AgentStatusChange on Contact (after update) {
	
	List<Id> contactsToUpdate = new List<Id>{};
	
	for (Contact agents: Trigger.new){
		Contact oldContact = Trigger.oldMap.get(agents.ID);
		if (agents.Agent_Status__c != oldContact.Agent_Status__c){
			if (agents.Agent_Status__c == 'SureLC Packet Complete' || agents.Agent_Status__c == 'Carrier Contracting Complete' || agents.Agent_Status__c == 'First Case Submitted' || agents.Agent_Status__c == 'Client'){
				
				contactsToUpdate.add(agents.ID);
			}
		}
	}
	
	if(!contactsToUpdate.isEmpty())
	UpdateOpportunityStageOnContact.agentstatus(contactsToUpdate);
	
}

 

public class UpdateOpportunityStageOnContact {
	
		public static void agentstatus(Contact[] contactsToUpdate) {
			
			List<Id> oppIdSureLC = new List<Id>{};
			List<Opportunity> oppsToUpdateSureLC = new List<Opportunity>{};
			List<Id> oppIdContracting = new List<Id>{};
			List<Opportunity> oppsToUpdateContracting = new List<Opportunity>{};
			List<Id> oppIdFirst = new List<Id>{};
			List<Opportunity> oppsToUpdateFirst = new List<Opportunity>{};
			List<Id> oppIdClient = new List<Id>{};
			List<Opportunity> oppsToUpdateClient = new List<Opportunity>{};
			
			for (Contact con :contactsToUpdate){
				
				if (con.Agent_Status__c == 'SureLC Packet Complete'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdSureLC.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdSureLC]){
						opp.StageName = 'SureLC Packet Complete';
						oppsToUpdateSureLC.add(opp);
					}
					
				}
				
				
				if (con.Agent_Status__c == 'Carrier Contracting Complete'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdContracting.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdContracting]){
						opp.StageName = 'Carrier Contracting Complete';
						oppsToUpdateContracting.add(opp);
					}
					
				}
				
				if (con.Agent_Status__c == 'First Case Submitted'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdFirst.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdFirst]){
						opp.StageName = 'First Case Submitted';
						oppsToUpdateFirst.add(opp);
					}
					
				}
				
				if (con.Agent_Status__c == 'Client'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdClient.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdClient]){
						opp.StageName = 'Closed Won';
						oppsToUpdateClient.add(opp);
					}
					
				}
				
			}
			
			if(!oppsToUpdateSureLC.isEmpty())
			update oppsToUpdateSureLC;
			
			if(!oppsToUpdateContracting.isEmpty())
			update oppsToUpdateContracting;
			
			if(!oppsToUpdateFirst.isEmpty())
			update oppsToUpdateFirst;
			
			if(!oppsToUpdateClient.isEmpty())
			update oppsToUpdateClient;
			
		}

}

 

 

 

The purpose of this class is to update a custom field on the Contact record of contacts associated with an opportunity via Opportunity Contact Role, when the Opportunity is a specific stage (Prospecting or Qualification).

 

Currently, when an Opportunity is created or updated I get an error:

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger OpportunityAgentStatus caused an unexpected exception, contact your administrator: OpportunityAgentStatus: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Class.OpportunityAgentStageProspect.prospect: line 15, column 1

 

Obviously something is wrong with how I'm pulling contacts but I can't figure it out.

 

I'd appreciate the help.

 

Thanks.

public class OpportunityAgentStageProspect {

	public static void prospect(Opportunity[] agentopps) {
		
		for (Opportunity opp :agentopps){
			
			Opportunity opp2 = [select ID, StageName from Opportunity where ID = :opp.Id];
			
			if (opp2.StageName == 'Prospecting' || opp2.StageName == 'Qualification') {
			
				OpportunityContactRole[] contacts = [select ID from OpportunityContactRole where OpportunityID = :opp2.Id];
			
					for (OpportunityContactRole con :contacts){
					
						Contact c = [select ID, Agent_Status__c from Contact where ID = :con.Id];
					
						c.Agent_Status__c = 'Prospect';
						update c;
				}
			
			}
		}
		
	}

}

 

 

Working on a test class.  I'm getting the error:

 

"Invalid initial expression type for field Account, expecting: SOBJECT:Account(or single row query result of that type). I'm new, and am at wit's end trying to figure this out. I'd appreciate some help. Thanks.

 

@isTest
private class TestOpportunityAgentStatus {

    static testMethod void myUnitTest() {
        
        Profile pf = [Select Id from Profile where Name = 'System Administrator'];
		
		User u = new User();
        u.FirstName = 'Test';
        u.LastName = 'User';
        u.Email = 'testuser@test123456789.com';
        u.CompanyName = 'test.com';
        u.Title = 'Test User';
        u.Username = 'testuser@test123456789.com';
        u.Alias = 'testuser';
        u.CommunityNickname = 'Test User';
        u.TimeZoneSidKey = 'America/Mexico_City';
        u.LocaleSidKey = 'en_US';
        u.EmailEncodingKey = 'ISO-8859-1';
        u.ProfileId = pf.Id;
        u.LanguageLocaleKey = 'en_US';
        insert u;
        
        system.runAs(u){
        	
       	
        	Account xxxacc1 = new Account(Name = 'Test Company');
        	insert xxxacc1;


        	Contact xxxcon1 = new Contact(FirstName = 'Test', LastName = 'Guy', Account = xxxacc1.Id);
        	insert xxxcon1;
        	
  	    	
        	Opportunity xxxopp1 = new Opportunity(
        							Name = 'Test Company - New Opp',
        							Account = xxxacc1.Id,
        							CloseDate = Date.today(),
        							StageName = 'Prospecting'
        							);
        	insert xxxopp1;
        	
        	
        	OpportunityContactRole xxxocr1 = new OpportunityContactRole(
        							ContactID = xxxcon1.Id,
        							OpportunityId = xxxopp1.Id,
        							Role = 'Decision Maker'
        							);
        	insert xxxocr1;
        	
        	
        	
        }
        
        
    }
}

 

Just learning APEX so appreciate the help.

 

I've created a trigger on a custom object. When the child object (Carrier_Contract__c) is inserted or updated, and the custom field "Has_Paid_For_A_Case__c" is true, it should check the single contact record associated with the record (Agent__c) and if that record's custom field Has_Paid_For_A_Case__c (different than the one on the trigger) is unchecked, go ahead and check it (true).

 

It should work but as it stands the update happens inside the loop which could cause an issue. 

 

How do I move the update outside the loop. And if there's anything else I'm doing wrong I'd certainly appreciate hearing about that as well.

 

Thanks.

trigger UpdateContactHasPaidForCase on Carrier_Contract__c (after insert, after update) {
	
	List<String> contractNames = new List<String>{};
	
	for(Carrier_Contract__c contract: Trigger.new){
	
		if(contract.Has_Paid_For_A_Case__c == TRUE && contract.RecordTypeID == '012i0000000FAWI'){
		
			Contact con = [select ID, Has_Paid_For_A_Case__c from Contact where ID = :contract.Agent__c];
		
			if(con.Has_Paid_For_A_Case__c == FALSE){
			con.Has_Paid_For_A_Case__c = TRUE;
			update con;
			}
			
		}
		
	}
	

}

 

I have a screen with two different dropdown lists (among other fields). The dropdown lists are:

 

Premium_Mode_Life: Has 5 different drop down choices.

Type_of_Application: Has 3 different drop down choices.

 

Once the user comples this screen and clicks on next, they are taken to a verfication screen where the information they selected in the prior screen is displayed via display text. What they selected for Premium_Mode_Life and Type_Of_Application is correctly being displayed on this screen.

 

Upon confirming the values are correct and clicking next, a record is then created. Two fields included in the new record are Premium_Mode_Life and Type_Of_Application. Neither of these fields are being added upon the record create.

 

I've triple checked and everything should be working correctly.

Is there a way that I can expose records within a custom object to our customers in a secure fashion - so they can only see records relating to their own contact record (e.g. custom objects with master-detail relationship to contacts).

 

Communities is more than I need, and outside my budget. So I'm hoping there's a way of doing this perhaps through a force.com site.

 

Thanks.

I have a custom object called Insurance Commissions with the following fields:

 

1. Agent

2. Commission Rate

3. Case (Master-Detail to the Case custom object which has a field called Premium)

 

In addition there are 2 record types: Base and Bonus.

 

Multiple Insurance Commissions records are added to each case. And for the record type Base, Commission Rates are what I'd call inclusive which is what makes it more complicated.

 

Here's an example:

 

Insurance Case 12345, premium of $1,000, with the following Insurance Commissions records associated with it:

 

1. Agent 1 - Base - 15%

2. Company 1 - Base - 20%

3. My Company - Base - 30%

4. Agent 1 - Bonus - 5%

 

To calculate the commissions we can start with the Base:

 

1. Agent 1 -- $1,000 * 15% = $150

2. Company 1 - $1,000 * (20% - 15% from Agent 1) = $50

3. My Company - $1,000 * (30% - 15% from Agent 1 - 5% from Company) = $100

4. Agent 1 - $1,000 * 5% = $50 which comes from My Company so My Company's net commission would be $50

 

If the Insurance Case changes (e.g. the premium changes), or if any of the Insurance Commissions records associated with a case change (or are added/removed), then the calculations need to be re-done.

 

It can get much more complicated with multiple agents and companies but this is a simplification. 

 

Is this an Apex thing?

 

Here's what I'm trying to do:

 

During the flow, the user gets to a screen which uses a multi-select checkbox field and a dynamic choice that returns those account records meeting a specific criteria.

 

The user can select multiple accounts.

 

The flow then creates new records, one for each account selected,  in a custom object which has a lookup field to accounts.

 

How can I do this?

 

I've been trying to figure out a loop but so far haven't been successful.

 

Thanks

I have a deployment of 70 items including custom objects, custom tabs, flows, page layouts, workflows, visualforce pages, as well as standard objects with custom fields.

 

I'm trying to deploy using Eclipse and Force.com IDe plugin. I cannot deploy and am getting failures.

 

The issue seems to be that these 70 items are all more or less connected to one another, and one item cannot be deployed because another item doesn't yet exist (since it hasn't yet been deployed).

 

For example, I can't deploy the page layout for an account record type because it includes related lists from several custom objects. And I can't deploy one custom object because another custom object hasn't yet been created.

 

It seems like this would be rather straightforward but perhaps it's not. Am I doing something wrong or is there a different way that I have to do this deployment?

 

I tried to deploy just one item at a time, and see if I can find the right order to deploy. But so far that hasn't worked, would take a long time, and just seems ridiculous to have to do.

 

Hopefully I'm just doing this incorrectly.

 

Thanks

I'm trying to deploy a package from one sandbox to another and get a failure message:

 

Cannot deploy InstalledPackage in Package Manifest with any other types!

 

I'm using Eclipse version Helios Service Release 1 along with the Spring 2013 version of Force.com IDE.

 

Any clue what's going on?

 

Thanks.

 

I have a flow which gives the user the option to modify an existing record. I'm having difficulty figuring out the best way to do this.

 

What I'd like is to have the flow do the record lookup and then on a screen display fields from that record and allow the user to modify those fields. So I'd have a Screen element with the appropriate fields (textbox, currency, checkbox, dropdown, etc.). The current values would be displayed and the user could make changes to those values.

 

I can't figure out how to do this, or if it's even possible.

 

What I'm doing right now is using a Display Text field to simply display the current values to the user. And then I have all of the fields needed under that display text. But there's no way that I can figure out to display the existing values as the default in each of the (choice) fields. So they basically have to go through each of the fields and re-populate them which is way less than ideal and prone to mistakes. For example, the display text would show their mailing address, but then they'd have to re-enter that address in the mailing address field.

 

While the fields allow for a default, it seems like they have to be one of the choices. And it doesn't look like the choices themselves can have a variable as a default value.

 

Am I missing something or is there a better approach to what I'm doing?

 

Thanks.

I have a Screen component with one Radio Button field. That field has two choices:

 

1. Create_New_Contract which is a simple choice field used in a later decision; and

 

2. Available_Contracts which is a dynamic choice

 

The Available_Contracts choice displays records from a custom object with a simple filter.

 

The Choice Label is the name of the custom object record. The Choice Stored Value is the Id of the custom object record.

 

After the user selects a record from the Available_Contracts they move further in the flow. There is a step where I want to use the (choice stored) value from Available_Contracts. To use it, I'm simply selecting Available_Contracts in the Dynamic Choice section of a formula.

 

However, nothing is stored there. I used a screen to display the value from that field and it's blank. Now, I can assign the ID obtained after the user selects the record to a new variable, and that works fine. But shouldn't using just Available_Contracts produce the ID of the record since that was what I used for Choice Stored Value.

 

Bottom line is it doesn't seem like Choice Stored Value is working. At least I cannot use it later in the flow.

 

Thanks.

This is a force.com page that has two date fields used to define a date range to lookup records to display. I want the user to be able to enter a simple date in a format such as MM/DD/YY instead of how it is currently. I've got no clue how to fix this if you could help. Thanks.

CONTROLLER

public with sharing class EstimateCommList {
    
    public list<Data_Estimated_Comm> LDEC {get;set;}
    public User user;
    public String curruserid;
    public String CId;
    public String sort_by {get;set;}
    public Date from_date {get;set;}
    public Date to_date {get;set;}
    
    
    public EstimateCommList() {
        
        curruserid = UserInfo.getUserId();
        system.debug('curruserid:'+curruserid);
        
        //get user record with contact__c
        user = [Select u.Name, u.Id, u.ContactId From User u where u.Id =:curruserid];
        CId = user.ContactId;
        system.debug('CId:'+CId);
    
        from_date = System.today();
        to_date = System.today().addMonths(6);
    /*  
        from_date =  System.now().addHours(0);
        String SStartDT = from_date.formatGMT('yyyy-MM-dd') + 'T' + StartDT.formatGMT('HH:mm:ss.SSS') + 'Z';
        
        to_date =  System.now().addHours(4);
        String SEndDT = to_date.formatGMT('yyyy-MM-dd') + 'T' + EndDT.formatGMT('HH:mm:ss.SSS') + 'Z';
        
        
        system.debug('from_date: '+from_date+ 'to_date: '+to_date);
    */
        list<Estimated_Commissions__c> LEC = [Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate, 
                    e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c, 
                    e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, 
                    e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c, 
                    e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name,
                    e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name, 
                    e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c, 
                    e.Insurance_Case__r.Policy_Number__c, 
                    e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name
                    From Estimated_Commissions__c e
                    where e.Agent__c  =:CId 
                    order by CreatedDate desc limit 10 ];   
                    
        system.debug('LEC:'+LEC);
        if(LDEC == null) LDEC = new list<Data_Estimated_Comm>{};
            
        for ( Estimated_Commissions__c EC : LEC){
            
            // Create a Data record and add it to the list
        
            Data_Estimated_Comm DEC = new Data_Estimated_Comm();
        
            DEC.Agency = EC.Agency__r.Name;   
            DEC.Agent = EC.Agent__r.Name;
            DEC.Casesplit = EC.Case_Split__c;
            DEC.ExcessCommAmt = EC.Excess_Commission_amount__c;
            DEC.ExcessCommRate = EC.Excess_Commission_Rate__c;
            DEC.FYCAmt = EC.FYC_Amount__c;
            DEC.FYCRate = EC.FYC_Rate__c;
            DEC.Insurance_Commission_Name = EC.Name;
            DEC.PolicyNumber = EC.Insurance_Case__r.Policy_Number__c;
            DEC.LineOfBusiness = EC.Insurance_Case__r.Line_of_Business__c;
            DEC.Carrier = EC.Insurance_Case__r.Carrier__r.Name;
            DEC.Product = EC.Insurance_Case__r.Product__r.Name;
            DEC.Client = EC.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name;
            DEC.PremiumMode = EC.Insurance_Case__r.Premium_Mode__c;
            DEC.Premium = EC.Insurance_Case__r.Target_Premium__c;
            DEC.Valid_From = EC.Valid_From__c;
        
            LDEC.add(DEC);
        }
        
    }
    
    public List<SelectOption> getSort() {
        
        
        
            List<SelectOption> options1 = new List<SelectOption>();
            options1.add(new SelectOption('Valid_From__c','Date'));
            options1.add(new SelectOption('Agent__r.Name','Agent Name'));
            options1.add(new SelectOption('Insurance_Case__r.Carrier__r.Name','Carrier'));
            options1.add(new SelectOption('Insurance_Case__r.Line_of_Business__c','Line Of Business'));
            options1.add(new SelectOption('Insurance_Case__r.Product__r.Name','Product'));
            options1.add(new SelectOption('Insurance_Case__r.Policy_Number__c','Policy Number'));
            options1.add(new SelectOption('Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name','Client'));
            options1.add(new SelectOption('Insurance_Case__r.Premium_Mode__c','Premium Mode'));
            options1.add(new SelectOption('Insurance_Case__r.Target_Premium__c','Premium'));
            options1.add(new SelectOption('FYC_Rate__c','FYC Rate'));
            options1.add(new SelectOption('FYC_Amount__c','FYC Amount'));
            options1.add(new SelectOption('Excess_Commission_Rate__c','Excess Rate'));
            options1.add(new SelectOption('Excess_Commission_amount__c','Excess Amount'));
           
            return options1;
        }
    
    public void searchEsti() {
        List<Estimated_Commissions__c> LEC = new  List<Estimated_Commissions__c>{};
        
        String DB1 = 'Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate,'; 
               DB1 += 'e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c,'; 
                    DB1 += 'e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, '; 
                    DB1 += 'e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c,'; 
                    DB1 += 'e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name,';
                    DB1 += 'e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,'; 
                    DB1 += 'e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c,'; 
                    DB1 += 'e.Insurance_Case__r.Policy_Number__c, ';
                    DB1 += 'e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name';
                    DB1 += 'From Estimated_Commissions__c e ';
                    DB1 += ' where e.Agent__c  =:CId ';
                    DB1 += ' and e.Valid_From__c >= '+from_date;
                    DB1 += ' and e.Valid_From__c <= '+to_date;
                    DB1 += ' order by '+ sort_by + ' asc ' ;
                    DB1 += ' limit 10';
                    LEC = DataBase.query(DB1);  
                    
        system.debug('LEC:'+LEC);
        LDEC = new list<Data_Estimated_Comm>{};
            
        for ( Estimated_Commissions__c est : LEC){
            
            // Create a Data record and add it to the list
        
            Data_Estimated_Comm DEC = new Data_Estimated_Comm();
        
            DEC.Agency = est.Agency__r.Name;   
            DEC.Agent = est.Agent__r.Name;
            DEC.Casesplit = est.Case_Split__c;
            DEC.ExcessCommAmt = est.Excess_Commission_amount__c;
            DEC.ExcessCommRate = est.Excess_Commission_Rate__c;
            DEC.FYCAmt = est.FYC_Amount__c;
            DEC.FYCRate = est.FYC_Rate__c;
            DEC.Insurance_Commission_Name = est.Name;
            DEC.PolicyNumber = est.Insurance_Case__r.Policy_Number__c;
            DEC.LineOfBusiness = est.Insurance_Case__r.Line_of_Business__c;
            DEC.Carrier = est.Insurance_Case__r.Carrier__r.Name;
            DEC.Product = est.Insurance_Case__r.Product__r.Name;
            DEC.Client = est.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name;
            DEC.PremiumMode = est.Insurance_Case__r.Premium_Mode__c;
            DEC.Premium = est.Insurance_Case__r.Target_Premium__c;
            DEC.Valid_From = est.Valid_From__c;
        
            LDEC.add(DEC);
        }
    }
    


}

PAGE

<apex:page controller="EstimateCommList" showHeader="false" standardStylesheets="true">
<!-- The site template provides layout & style for the site -->
    <apex:composition template="{!$Site.Template}">

    <apex:define name="body">
  
    <apex:form style="position:relative;top:50px;margin-left:25px;" >   
        <div style="width:1200px;margin-left:20px;">
        <apex:pageBlock title="Estimated Commission List">          
            
            <apex:pageblockSection title="Search Section" columns="2" >
                    
                    <apex:outputText value="Date Range " style="margin-left:100px;"></apex:outputText>
                    <apex:inputText value="{!from_date}" style="margin-left:20px; width:155px;"></apex:inputText> 
                    
                    <apex:outputText value="To" style="margin-left:20px; display: block; text-align: right;"></apex:outputText>
                    <apex:inputText value="{!to_date}" style="margin-left:20px; width:155px;"></apex:inputText> 
                    
                    <apex:outputText value="Sort by" style="margin-left:100px;"></apex:outputText>
                    <apex:selectList value="{!sort_by}" id="sort1" multiselect="false" size="1" style="padding-left: 30px;">
                            <apex:selectOptions value="{!Sort}" /> 
                    </apex:selectList>
              
                    
                    <apex:commandButton style="width:75px;margin-left:250px;" action="{!searchEsti}" value="Search"/>
                            
            </apex:pageblockSection>
            
            <apex:pageBlockTable value="{!LDEC}" var="e"   id="instancesTable">
            
                <apex:column >   
                    <apex:facet name="header"> Date</apex:facet>
                    <apex:outputText value="{0,date,MM'/'dd'/'yyyy }">
                                   <apex:param value="{!e.Valid_From}" /> 
                    </apex:outputText>
                </apex:column>
                
                <apex:column >   
                    <apex:facet name="header"> Agent Name</apex:facet>
                    <apex:outputText value="{!e.Agent}" ></apex:outputText>          
                </apex:column>
                
                <apex:column >   
                    <apex:facet name="header"> Carrier</apex:facet>
                    <apex:outputText value="{!e.Carrier}" ></apex:outputText>           
                </apex:column>
                
                <apex:column >   
                    <apex:facet name="header"> Line Of Business</apex:facet>
                    <apex:outputText value="{!e.LineOfBusiness}" ></apex:outputText>           
                </apex:column>
                
                <apex:column >   
                    <apex:facet name="header"> Product</apex:facet>
                    <apex:outputText value="{!e.Product}" ></apex:outputText>           
                </apex:column>
                
                <apex:column >
                    <apex:facet name="header"> Policy Number</apex:facet> 
                    <apex:outputText value="{!e.PolicyNumber}"></apex:outputText>          
                </apex:column>
                
                <apex:column >   
                    <apex:facet name="header"> Client</apex:facet>
                    <apex:outputText value="{!e.Client}" ></apex:outputText>          
                </apex:column>
                
                <apex:column >   
                    <apex:facet name="header"> Premium Mode</apex:facet>
                     <apex:outputText value="{!e.PremiumMode}" ></apex:outputText>          
                </apex:column>
                
                <apex:column >   
                    <apex:facet name="header"> Premium</apex:facet>
                <apex:outputText value="{!e.Premium}" ></apex:outputText>          
                </apex:column>
                
                <apex:column >
                    <apex:facet name="header"> FYC Rate</apex:facet>
                    <apex:outputText value="{!e.FYCRate}"></apex:outputText> 
                </apex:column>
                
                <apex:column >
                    <apex:facet name="header"> FYC Amount</apex:facet> 
                    <apex:outputText value="{!e.FYCAmt}"></apex:outputText>          
                </apex:column>    
                
                <apex:column >
                    <apex:facet name="header"> Excess Rate </apex:facet> 
                    <apex:outputText value="{!e.ExcessCommRate}"></apex:outputText>          
                </apex:column>
                
                <apex:column >
                    <apex:facet name="header"> Excess Amount </apex:facet> 
                    <apex:outputText value="{!e.ExcessCommAmt}"></apex:outputText>           
                </apex:column>
             
                
                <!-- 
                <apex:column >
                    <apex:facet name="header"> Insurance Commission Name</apex:facet> 
                    <apex:outputText value="{!e.Insurance_Commission_Name}"></apex:outputText>          
                </apex:column>               
         
                <apex:column >
                    <apex:facet name="header"> Agency</apex:facet>
                    <apex:outputText value="{!e.Agency}" ></apex:outputText> 
                </apex:column>                               
        
                 <apex:column >
                    <apex:facet name="header"> Case split</apex:facet>
                    <apex:outputText value="{!e.Casesplit}"></apex:outputText> 
                </apex:column>            
        
                <apex:column >
                    <apex:facet name="header"> Excess Commission amount</apex:facet>
                    <apex:outputText value="{!e.ExcessCommAmt}"></apex:outputText>           
                </apex:column>
        
                <apex:column >
                    <apex:facet name="header"> Excess Commission Rate</apex:facet>
                    <apex:outputText value="{!e.ExcessCommRate}"></apex:outputText> 
                </apex:column>
        
                
              -->
                
            </apex:pageBlockTable>
        </apex:pageBlock>
        </div>  
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
    </apex:form>
        </apex:define>
        
    </apex:composition>
</apex:page>


I'm running into a bulk update issue on the trigger below. I thought that I properly structured the apex for bulkification but apparently I didn't and I'm stuck. I'd really appreciate some help. Thanks.

 

trigger UpdateAgentCaseCommissionOnCaseUpdate on Insurance_Case__c (after update) {

  Map<Id, Insurance_Case__c> cases = new Map<Id, Insurance_Case__c>();
  Map<Id, Insurance_Case__c> casesstatus = new Map<Id, Insurance_Case__c>();
  Agent_Cases_Commissions__c[] accToUpdate = new Agent_Cases_Commissions__c[0];
  
  for(Insurance_Case__c record: Trigger.new){
    Insurance_Case__c oldcase = Trigger.oldMap.get(record.Id);
    if(record.Status__c != oldcase.Status__c && record.Status__c != 'Submitted'){
      casesstatus.put(record.Id, record);
    } else {
      cases.put(record.Id, record);
    }
  }
  
  Agent_Cases_Commissions__c[] accstatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :casesstatus.keyset() AND Contract_Type__c = 'Agent Contract'];
  Agent_Cases_Commissions__c[] accnostatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :cases.keyset() AND Contract_Type__c = 'Agent Contract'];
  
  for(Agent_Cases_Commissions__c acc :accstatus){
    acc.Case_Status_Change__c = TRUE;
    accToUpdate.add(acc);
  }
  
  for(Agent_Cases_Commissions__c acc2 :accnostatus){
    accToUpdate.add(acc2);
  }
  
  if(!accToUpdate.isEmpty())
  update accToUpdate;

}

 

Ran into a bulk issue on a class. I re-wrote it (See attached code) but am having an issue still. The problem is with creating the list of opportunities by adding them to a list via looking up their ID in the list for OpportunityContactRole (line 15 through 18).

 

My interpretation of:

 

List<Opportunity> oppSureLC = [select ID, StageName from Opportunity where ID IN :ocrSureLC];

 

Is that it should add an opportunity to the list if the ID of the opportunity is included in the OpportunityContactRole list, which contains OpportunityID. Obviously I'm wrong.

 

I'd appreciate help in fixing this. Do I need to use a for statement to add the Opportunities instead of doing it within a list? Is there a way of using a relationship query to eliminate some of this? 

 

public class UpdateOpportunityStageOnContact {
	
		public static void agentstatus(Contact[] contactsToUpdate) {
			
			List<Contact> conSureLC = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'SureLC Packet Complete' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			List<Contact> conCarrier = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'Carrier Contracting Complete' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			List<Contact> conFirst = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'First Case Submitted' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			List<Contact> conClient = [select ID, Agent_Status__c, Don_t_Update_Opportunity_Via_Flow__c from Contact where ID IN :contactsToUpdate AND Agent_Status__c = 'Client' AND Don_t_Update_Opportunity_Via_Flow__c = FALSE];
			
			List<OpportunityContactRole> ocrSureLC = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conSureLC];
			List<OpportunityContactRole> ocrCarrier = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conCarrier];
			List<OpportunityContactRole> ocrFirst = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conFirst];
			List<OpportunityContactRole> ocrClient = [select ID, OpportunityID from OpportunityContactRole where ContactID IN :conClient];
			
			List<Opportunity> oppSureLC = [select ID, StageName from Opportunity where ID IN :ocrSureLC];
			List<Opportunity> oppCarrier = [select ID, StageName from Opportunity where ID IN :ocrCarrier];
			List<Opportunity> oppFirst = [select ID, StageName from Opportunity where ID IN :ocrFirst];
			List<Opportunity> oppClient = [select ID, StageName from Opportunity where ID IN :ocrClient];
			
			List<Opportunity> oppsToUpdateSureLC = new List<Opportunity>{};
			List<Opportunity> oppsToUpdateContracting = new List<Opportunity>{};
			List<Opportunity> oppsToUpdateFirst = new List<Opportunity>{};
			List<Opportunity> oppsToUpdateClient = new List<Opportunity>{};
			
			for(Opportunity opp1: oppSureLC){
						opp1.StageName = 'SureLC Packet Complete';
						oppsToUpdateSureLC.add(opp1);
			}
					
			for(Opportunity opp2: oppCarrier){
						opp2.StageName = 'Carrier Contracting Complete';
						oppsToUpdateContracting.add(opp2);
			}
					
			for(Opportunity opp3: oppFirst){
						opp3.StageName = 'First Case Submitted';
						oppsToUpdateFirst.add(opp3);
			}

			for(Opportunity opp4: oppClient){
						opp4.StageName = 'Closed Won';
						oppsToUpdateClient.add(opp4);
			}
			
			if(!oppsToUpdateSureLC.isEmpty())
			update oppsToUpdateSureLC;
			
			if(!oppsToUpdateContracting.isEmpty())
			update oppsToUpdateContracting;
			
			if(!oppsToUpdateFirst.isEmpty())
			update oppsToUpdateFirst;
			
			if(!oppsToUpdateClient.isEmpty())
			update oppsToUpdateClient;
			
		}

}

 

I'd like this trigger to check a contact's old (before update) value of a field to the new value, and if it has changed, AND if the new field is of a certain value, to then pass the list of contacts to a class.

 

Below is my first draft of the code and it's not working. I've also included the class just in case there's an issue there, but that did deploy successfully.

 

The error I'm getting is:

 

Method does not exist or incorrect signature: UpdateOpportunityStageOnContact.agentstatus(LIST<Id>)

 

So I don't think my call to the class is formatted correctly. Or I'm not using the list correctly.

 

Thanks!

 

trigger AgentStatusChange on Contact (after update) {
	
	List<Id> contactsToUpdate = new List<Id>{};
	
	for (Contact agents: Trigger.new){
		Contact oldContact = Trigger.oldMap.get(agents.ID);
		if (agents.Agent_Status__c != oldContact.Agent_Status__c){
			if (agents.Agent_Status__c == 'SureLC Packet Complete' || agents.Agent_Status__c == 'Carrier Contracting Complete' || agents.Agent_Status__c == 'First Case Submitted' || agents.Agent_Status__c == 'Client'){
				
				contactsToUpdate.add(agents.ID);
			}
		}
	}
	
	if(!contactsToUpdate.isEmpty())
	UpdateOpportunityStageOnContact.agentstatus(contactsToUpdate);
	
}

 

public class UpdateOpportunityStageOnContact {
	
		public static void agentstatus(Contact[] contactsToUpdate) {
			
			List<Id> oppIdSureLC = new List<Id>{};
			List<Opportunity> oppsToUpdateSureLC = new List<Opportunity>{};
			List<Id> oppIdContracting = new List<Id>{};
			List<Opportunity> oppsToUpdateContracting = new List<Opportunity>{};
			List<Id> oppIdFirst = new List<Id>{};
			List<Opportunity> oppsToUpdateFirst = new List<Opportunity>{};
			List<Id> oppIdClient = new List<Id>{};
			List<Opportunity> oppsToUpdateClient = new List<Opportunity>{};
			
			for (Contact con :contactsToUpdate){
				
				if (con.Agent_Status__c == 'SureLC Packet Complete'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdSureLC.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdSureLC]){
						opp.StageName = 'SureLC Packet Complete';
						oppsToUpdateSureLC.add(opp);
					}
					
				}
				
				
				if (con.Agent_Status__c == 'Carrier Contracting Complete'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdContracting.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdContracting]){
						opp.StageName = 'Carrier Contracting Complete';
						oppsToUpdateContracting.add(opp);
					}
					
				}
				
				if (con.Agent_Status__c == 'First Case Submitted'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdFirst.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdFirst]){
						opp.StageName = 'First Case Submitted';
						oppsToUpdateFirst.add(opp);
					}
					
				}
				
				if (con.Agent_Status__c == 'Client'){
					
					for(OpportunityContactRole ocr: [select OpportunityID from OpportunityContactRole where ContactID = :con.Id]){
						oppIdClient.add(ocr.OpportunityID);
					}
					
					for(Opportunity opp: [select ID, StageName from Opportunity where ID = :oppIdClient]){
						opp.StageName = 'Closed Won';
						oppsToUpdateClient.add(opp);
					}
					
				}
				
			}
			
			if(!oppsToUpdateSureLC.isEmpty())
			update oppsToUpdateSureLC;
			
			if(!oppsToUpdateContracting.isEmpty())
			update oppsToUpdateContracting;
			
			if(!oppsToUpdateFirst.isEmpty())
			update oppsToUpdateFirst;
			
			if(!oppsToUpdateClient.isEmpty())
			update oppsToUpdateClient;
			
		}

}

 

 

 

The purpose of this class is to update a custom field on the Contact record of contacts associated with an opportunity via Opportunity Contact Role, when the Opportunity is a specific stage (Prospecting or Qualification).

 

Currently, when an Opportunity is created or updated I get an error:

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger OpportunityAgentStatus caused an unexpected exception, contact your administrator: OpportunityAgentStatus: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Class.OpportunityAgentStageProspect.prospect: line 15, column 1

 

Obviously something is wrong with how I'm pulling contacts but I can't figure it out.

 

I'd appreciate the help.

 

Thanks.

public class OpportunityAgentStageProspect {

	public static void prospect(Opportunity[] agentopps) {
		
		for (Opportunity opp :agentopps){
			
			Opportunity opp2 = [select ID, StageName from Opportunity where ID = :opp.Id];
			
			if (opp2.StageName == 'Prospecting' || opp2.StageName == 'Qualification') {
			
				OpportunityContactRole[] contacts = [select ID from OpportunityContactRole where OpportunityID = :opp2.Id];
			
					for (OpportunityContactRole con :contacts){
					
						Contact c = [select ID, Agent_Status__c from Contact where ID = :con.Id];
					
						c.Agent_Status__c = 'Prospect';
						update c;
				}
			
			}
		}
		
	}

}

 

 

Working on a test class.  I'm getting the error:

 

"Invalid initial expression type for field Account, expecting: SOBJECT:Account(or single row query result of that type). I'm new, and am at wit's end trying to figure this out. I'd appreciate some help. Thanks.

 

@isTest
private class TestOpportunityAgentStatus {

    static testMethod void myUnitTest() {
        
        Profile pf = [Select Id from Profile where Name = 'System Administrator'];
		
		User u = new User();
        u.FirstName = 'Test';
        u.LastName = 'User';
        u.Email = 'testuser@test123456789.com';
        u.CompanyName = 'test.com';
        u.Title = 'Test User';
        u.Username = 'testuser@test123456789.com';
        u.Alias = 'testuser';
        u.CommunityNickname = 'Test User';
        u.TimeZoneSidKey = 'America/Mexico_City';
        u.LocaleSidKey = 'en_US';
        u.EmailEncodingKey = 'ISO-8859-1';
        u.ProfileId = pf.Id;
        u.LanguageLocaleKey = 'en_US';
        insert u;
        
        system.runAs(u){
        	
       	
        	Account xxxacc1 = new Account(Name = 'Test Company');
        	insert xxxacc1;


        	Contact xxxcon1 = new Contact(FirstName = 'Test', LastName = 'Guy', Account = xxxacc1.Id);
        	insert xxxcon1;
        	
  	    	
        	Opportunity xxxopp1 = new Opportunity(
        							Name = 'Test Company - New Opp',
        							Account = xxxacc1.Id,
        							CloseDate = Date.today(),
        							StageName = 'Prospecting'
        							);
        	insert xxxopp1;
        	
        	
        	OpportunityContactRole xxxocr1 = new OpportunityContactRole(
        							ContactID = xxxcon1.Id,
        							OpportunityId = xxxopp1.Id,
        							Role = 'Decision Maker'
        							);
        	insert xxxocr1;
        	
        	
        	
        }
        
        
    }
}

 

Just learning APEX so appreciate the help.

 

I've created a trigger on a custom object. When the child object (Carrier_Contract__c) is inserted or updated, and the custom field "Has_Paid_For_A_Case__c" is true, it should check the single contact record associated with the record (Agent__c) and if that record's custom field Has_Paid_For_A_Case__c (different than the one on the trigger) is unchecked, go ahead and check it (true).

 

It should work but as it stands the update happens inside the loop which could cause an issue. 

 

How do I move the update outside the loop. And if there's anything else I'm doing wrong I'd certainly appreciate hearing about that as well.

 

Thanks.

trigger UpdateContactHasPaidForCase on Carrier_Contract__c (after insert, after update) {
	
	List<String> contractNames = new List<String>{};
	
	for(Carrier_Contract__c contract: Trigger.new){
	
		if(contract.Has_Paid_For_A_Case__c == TRUE && contract.RecordTypeID == '012i0000000FAWI'){
		
			Contact con = [select ID, Has_Paid_For_A_Case__c from Contact where ID = :contract.Agent__c];
		
			if(con.Has_Paid_For_A_Case__c == FALSE){
			con.Has_Paid_For_A_Case__c = TRUE;
			update con;
			}
			
		}
		
	}
	

}

 

I have a screen with two different dropdown lists (among other fields). The dropdown lists are:

 

Premium_Mode_Life: Has 5 different drop down choices.

Type_of_Application: Has 3 different drop down choices.

 

Once the user comples this screen and clicks on next, they are taken to a verfication screen where the information they selected in the prior screen is displayed via display text. What they selected for Premium_Mode_Life and Type_Of_Application is correctly being displayed on this screen.

 

Upon confirming the values are correct and clicking next, a record is then created. Two fields included in the new record are Premium_Mode_Life and Type_Of_Application. Neither of these fields are being added upon the record create.

 

I've triple checked and everything should be working correctly.

Is there a way that I can expose records within a custom object to our customers in a secure fashion - so they can only see records relating to their own contact record (e.g. custom objects with master-detail relationship to contacts).

 

Communities is more than I need, and outside my budget. So I'm hoping there's a way of doing this perhaps through a force.com site.

 

Thanks.

Hi,

 

I am working on rollup summary on opportunity but it doesn't allow master relationship with my custom object.

 

So, i created a look up realtionship with opportunity but now i need Apex triggers to create a relationship.

 

So, can anyone help me in this.

 

my custom object is :-   vik__productitem__c

my field which have look up with opportunity :-  vik__Opportunity__c

my field in opportunity with rollup summary :-  vik__products__c

 

please help me to overcome this problem

 

Thanks in advance.