• orikker
  • NEWBIE
  • 95 Points
  • Member since 2008

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 57
    Replies

I am writing a trigger where if the region field on the opportunity owner's user record are certain values, to pull those values onto the Region field on the opportunity page, else look to the account owner's user record. I am getting the following error:

 

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger OpportunityOwnersAddress2 caused an unexpected exception, contact your administrator: OpportunityOwnersAddress2: execution of BeforeUpdate caused by: System.ListException: List index out of bounds: 0: Trigger.OpportunityOwnersAddress2: line 47, column 13

 

 

This error is at the end of the trigger. I am stared at this ad nausium, and it looks correct to me. But apparently it is not.

Here is the trigger:

 

 

trigger OpportunityOwnersAddress2 on Opportunity (before insert, before update) {

    Set<Id> UserIds = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 userids id : '+oppo.ownerid);
    
            UserIds.add(oppo.ownerId);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    Map<Id, User> entries = new Map<Id, User>();
    List<user> us = [select Id, User_Address__c, Phone, Fax, Email, Region__c from User where id in :UserIds];
    
    string txt = '';
    txt = us[0].User_Address__c;          
    txt = txt.replaceAll('<br>', '\n');
    System.debug('**** 1 ****txt txt txt txt *********:'+txt );


    string uc = 'US/Canada';
    string euro = 'Europe';
    string Inter = 'InterCon';
    string auc = 'US/Canada';
    string aeuro = 'Europe';
    string aInter = 'InterCon';
        
    for(Opportunity unity: Trigger.new) {
       unity.Opp_Owner_Address__c = txt;
       unity.Opp_Owner_Phone__c = us[0].Phone;
       unity.Opp_Owner_Fax__c = us[0].Fax;
       unity.Opp_Owner_Email__c = us[0].Email;
       
       UserIds.add(unity.ownerId);


    If( us[0].Region__c == uc || us[0].Region__c == euro || us[0].Region__c == Inter ){

       unity.Opportunity_Region__c =us[0].Region__c;
  
      }

    Map<Id, Account> a = new Map<Id, Account>();
    List<Account> ac = [select Id, OwnerId from Account where id =: unity.Accountid];
    List<user> aus = [select Id, Region__c from User where id =: unity.account.ownerid];
    
    If( aus[0].Region__c != auc || aus[0].Region__c != aeuro || aus[0].Region__c != aInter ){

       unity.Opportunity_Region__c = aus[0].Region__c;
    } else {
    unity.Opportunity_Region__c= txt;
    }
  }
}

 

 

How do I solve the error?

 

Thank you,

ckellie

OK so I've been an admin for about 3 years and (for better or worse) know more about SF than anyone in my company.  i have some experience with apex and Visualforce, but little with triggers.

 

what i need is to write a trigger in production that does this:  the trigger should create a new record in a custom object called "Vehicles" when an Opportunity record is created with a specific value in one of its custom fields (the field is called "Type").  So, when an opp is created and saved with Type = "x", then the trigger should fire, and a new vehicle object record should be created that is populated with a few fields from that opportunity record.

 

can anyone send me some code to show me what this trigger should be or look like?  I've been researching this but have no clue, and I'm afraid of writing bad code that will cause problems.

 

also, the custom object is not in a parent-child relationship with the opporuntiy object, and i don't want it to be unless it has to be.

 

i know the developers in here are ridiculously smart and talented, and i'm just hoping one of you feels sorry enough for an amateur like me to help me out.  thanks a lot.

I'm trying to do something I think is relatively simple. I am basically monitoring the insersts on a Task object. If one of the subjects of those inserts meets a certain criteria, I want to update the Comments field (Description) and have the new comments area inserted along with the rest of the Task information.

 

Been racking my brain on this, searched across the board and all but still haven't had much luck. If you have any insight, it's much appreciated!

 

The code below is runs without issue, I have a unit test and that's fine. Even when I throw in debugs in there, everything executes as it should. But still, the field never shows up updated.

 

 

trigger task_StoreMassEmailBody_upd on Task (before insert) {
	if(Trigger.isBefore) {
		for(Task t : Trigger.new) {
		    Boolean LogBody = Trigger.new[0].Subject.contains('special subject');
			if(LogBody) { t.Description = 'Win'; }
		}
	}
}

 What am I missing here? I've also tried it with an after update, and create a set of all the trigger.new ID's related to the task, and then iterate through those and do an update after (since, iirc, after insert the fields are ready only) but still no luck.

 

 

Thanks in advance!

  • February 16, 2011
  • Like
  • 0

I am updating 23000 records. Trigger is supposed to update a lookup Contact field FA_Name__c . There are about 40000 contacts, but not all of them would meet the criteria in the code... here is the error and the code...

 

Batch data load fails about 1900 records with error UNKNOWN_EXCEPTION:Unable to find query cursor data for this QueryLocator, please retry your query.:--

 

Plus a warning email.

 

Operation: N/A

 

By user/organization: user/org

 

Caused the following Apex resource warnings:

 

Number of query rows: 46557 out of 50000

 

 

Is there a way to attach a file from your computer when run java program using sendemail() api call?

 

book suggests the following code

EmailFileAttachment efa = new EmailFileAttachment();
    byte[] fileBody = new byte[1000000];
    efa.setBody(fileBody);
    efa.setFileName("attachment");

 

 

but where do I actually set the path to the file?

Ok. I give up... What am I doing wrong? 

 

 

package comEJMSandbox;


	import com.sforce.soap.enterprise.EnterpriseConnection;
	import com.sforce.soap.enterprise.GetUserInfoResult;
	import com.sforce.ws.*;

	public class testLogin {
		
	  
	  

	  public static void main(String[] args) {
		
		  ConnectorConfig config = new ConnectorConfig();
	      config.setUsername("admin@salesforce.com");
	      config.setPassword("password");
	      
	      config.setAuthEndpoint("https://login.salesforce.com/services/Soap/c/20.0");
	      EnterpriseConnection connection;
	      try {
	    	  connection = new EnterpriseConnection(config);
	          GetUserInfoResult userInfo = connection.getUserInfo();
	          System.out.println("\nLogging in ...\n");
	          System.out.println("UserID: " + userInfo.getUserId());
	          System.out.println("User Full Name: " + 
	              userInfo.getUserFullName());
	          System.out.println("User Email: " + 
	              userInfo.getUserEmail());
	          System.out.println();
	          System.out.println("SessionID: " + 
	              config.getSessionId());
	          System.out.println("Auth End Point: " + 
	              config.getAuthEndpoint());
	          System.out.println("Service End Point: " + 
	              config.getServiceEndpoint());
	          System.out.println();
	         
	        } catch (ConnectionException ce) {
	        	ce.printStackTrace();
	        }
		
		
		  
	    
	  }	  
	  
}

 

I get this error

 

 

com.sforce.ws.ConnectionException: Unexpected element. Parser was expecting element 'urn:enterprise.soap.sforce.com:orgAttachmentFileSizeLimit' but found 'urn:enterprise.soap.sforce.com:orgDefaultCurrencyIsoCode'
	at com.sforce.ws.bind.TypeMapper.verifyTag(TypeMapper.java:386)
	at com.sforce.ws.bind.TypeMapper.verifyElement(TypeMapper.java:415)
	at com.sforce.soap.enterprise.GetUserInfoResult.loadFields(GetUserInfoResult.java:1)
	at com.sforce.soap.enterprise.GetUserInfoResult.load(GetUserInfoResult.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.soap.enterprise.LoginResult.loadFields(LoginResult.java:1)
	at com.sforce.soap.enterprise.LoginResult.load(LoginResult.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.soap.enterprise.LoginResponse_element.loadFields(LoginResponse_element.java:1)
	at com.sforce.soap.enterprise.LoginResponse_element.load(LoginResponse_element.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:170)
	at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:144)
	at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
	at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:1)
	at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:1)
	at comEJMSandbox.testLogin.main(testLogin.java:22)

 

 

 

Here is a problem:

 

We need to be able to populate a date field on Opportunity every time a new task of specific record type is created and related to opportunity (and ONLY). 

 

Solution: create a trigger on insert. Here is where I am stuck, how to check if a task that is being created, relates to opportunity and not other object? 

 

Thank you. 

Does anyone know how to access checkbox through apex or how to enable it so when you create case through apex case uses active assignment rules? 

 

trigger farmingTasksGenerator on Opportunity (after update) {
	Task t;
	List <Task> tasksToInsert = new List <Task> ();
	List <Opportunity> oppList = [SELECT Id, Status_Code__c, FA__c, Name, Senior_HMA__c
								 FROM Opportunity WHERE Id IN :Trigger.NewMap.keySet()];
	
	
	for (Opportunity opp: oppList) {
		
		if (Trigger.newMap.get(opp.Id).Status_Code__c != Trigger.oldMap.get(opp.Id).Status_Code__c  ) {
			
			if (opp.Status_Code__c == 'A15' ||
				opp.Status_Code__c == 'C10' ||
				opp.Status_Code__c == 'C20' ||
				opp.Status_Code__c == 'E10'	) {
				
				t = new Task (Subject = 'Farming task - ' + opp.Status_Code__c + 
										' - loan ' + opp.Name, WhoId = opp.FA__c,
								ActivityDate = System.Today()+1, WhatId = opp.Id, Status = 'Not Started', 
								RecordTypeId = '012300000008qRE', Farming_Task__c = true, Type = 'OUTBOUND CALL',
								OwnerId = opp.Senior_HMA__c, isReminderSet = true, ReminderDateTime = System.Now(),
								Farming_Task_Description__c = 'Farming task - ' + opp.Status_Code__c + 
										' - loan ' + opp.Name);
				tasksToInsert.add (t);
			}
		}
	}
	
	insert tasksToInsert;
	tasksToInsert.clear();
	oppList.clear();

}

 We have a trigger that is supposed to create tasks for specific loans that are moved to a specific status. Update is run every morning and updates 3000 records from CSV file and that is when trigger is fired. For some reason, it creates the same task for some but not all records... Any ideas?

 

Thank you. 

 

I have two fieds on that page that are dynamically rendered on the page and if rendered they become required. When user hit save and the field is empty, there is no error message on the page or field that it is required, record does not get updated, but there is nothing indicating that..... Any ideas why?

does anyone know if it is possible to use selfservice portal authentication and then forward user to a specific visualforce page, rather than to a selfservice portal? 

Hi,

 

does anyone have ideas on how to make apex to email me error log after I upsert records via data loader bulk process.

 

Here is what's happening.

 

Every morning a file is dropped into a directory on the nework. Apex Loader picks it up and tries to upsert the records and spits out error file. Everything works to this point, but I have to email that error file to our people every morning. I know how to setup a java program to grab file and email it anywhere, but our firewall does not allow connections to gmail and email clients like that and I do not have settings for our MS exchange server. Is there a way to create an apex job to grab the file and email it to me? As far as I know every bulk job results files are saved in SF, the question is how can I access those via Apex.

 

No need for detailed code, if you don't have time.

 

Thank you.

  • September 02, 2010
  • Like
  • 0

Does anyone know how? there is no standard controller for Tasks...

I am trying to bulk update Contacts (FAs) with number of leads related to them.

 

I get stuck because of the SOQL limit... Please help.

 

thank you.

 

trigger CountLeads on Contact (before insert, before update) {

//production version
	
	Map <Id, Contact > FAList = new Map<Id, Contact> (
	
	[SELECT Id, Leads_2010_YTD__c FROM Contact WHERE Id in :Trigger.new]
	);
	
	
	
	Map<Id, Integer> LeadCount = new Map<Id, Integer> ();
	
	for (Contact con: Trigger.New ){
		Integer i = [SELECT count () FROM Lead 
		WHERE FA__c = :con.Id
		 AND (CreatedDate >= 2010-01-01T00:00:00Z AND CreatedDate <= 2010-12-31T00:00:00Z)];
		 
		LeadCount.put (con.Id, i);
		
		
	} //end for con
	
	
	try {
		
		for (Contact FAupdate : Trigger.new){
			
			FAupdate.Leads_2010_YTD__c = LeadCount.get(FAupdate.Id);
			
		} // end for FAupdate
		
		
		
	}// end try
    
    catch (System.Queryexception e){
    	
    	System.debug('FA Lead Count ERROR:' + e);
    	
    } // end catch
    
 
}

 

I am trying to see if there is a way build a visualforce page that I can put on a public website to search for some information in SF. For example, if a customer goes to my website and puts zip code in the search, it should show him top ten results within 10 miles radius from my salesforce contacts... any ideas? 

Thank you.

I am trying to get rid of checkbox and stupid notification about company field and accounts on top of the standart Convert lead page, by creating visualforce page.

 

Can anybody share experience? Or is there a workaround?

 

Thanks.

Message Edited by orikker on 03-03-2009 11:11 AM

Is there a way of locking notes records after those are created? Or is it possible at least to remove edit and delete buttons from the notes layout.

 

Thanks,

Does anybody know how to create a visualforce page that will pull all the notes related to a lead or opportunity, but without edit or delete action buttons.
Is it possible to create queries in MS Access 2007 that will pull data from SalesForce.com??

Details would be helpful,

Thanks,

Oleg.
Does anybody know a way to install Connector for Office without having rights on the machine?
 Or could you tell me where the installation puts files. I would basically just copy needed files from other source(machine with installed connector).
Either XP or Vista solution will work.

Thanks.


Message Edited by orikker on 10-21-2008 06:07 PM
I have a custom picklist for Tasks and I am trying to create a workflow that will update the Subject field with the value from this custom picklist field when create or save record.

The problem I have is that I am getting error for the Subject field formula in the field update rule.
in the formula field I type custom field name which is Type_Value__c and get this error:

Error: Formula result is data type (Text), incompatible with expected data type (Picklist).

Could you help me?

Hi All

 

Can you please help me in writing a test class for the following trigger. The scenario is whenever an opportunity is closed won or dead/lost a field should be updated in Case object.

 

trigger CaseUpadate on Opportunity (after update)
{
List <Case> caseList;
List <Id> oppIdList = new List <Id>();
for(Integer i=0; i<Trigger.new.size(); i++)
{
    if (Trigger.new[i].StageName != Trigger.old[i].StageName && (Trigger.new[i].StageName == 'Closed Won' || Trigger.new[i].StageName == 'Closed - Dead/Lost'))
       
        oppIdList.add(Trigger.new[i].Id);
}  
caseList = [select Id, Opportunity_closed_won__c from Case where Opportunity__c in :oppIdList];
if (caseList.size() > 0)
{
    for(Case c : caseList)
    {
        if (c.Opportunity_closed_won__c != true)
            c.Opportunity_closed_won__c = true;   
    }
   
    update caseList;
    }
}

I am writing a trigger where if the region field on the opportunity owner's user record are certain values, to pull those values onto the Region field on the opportunity page, else look to the account owner's user record. I am getting the following error:

 

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger OpportunityOwnersAddress2 caused an unexpected exception, contact your administrator: OpportunityOwnersAddress2: execution of BeforeUpdate caused by: System.ListException: List index out of bounds: 0: Trigger.OpportunityOwnersAddress2: line 47, column 13

 

 

This error is at the end of the trigger. I am stared at this ad nausium, and it looks correct to me. But apparently it is not.

Here is the trigger:

 

 

trigger OpportunityOwnersAddress2 on Opportunity (before insert, before update) {

    Set<Id> UserIds = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 userids id : '+oppo.ownerid);
    
            UserIds.add(oppo.ownerId);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    Map<Id, User> entries = new Map<Id, User>();
    List<user> us = [select Id, User_Address__c, Phone, Fax, Email, Region__c from User where id in :UserIds];
    
    string txt = '';
    txt = us[0].User_Address__c;          
    txt = txt.replaceAll('<br>', '\n');
    System.debug('**** 1 ****txt txt txt txt *********:'+txt );


    string uc = 'US/Canada';
    string euro = 'Europe';
    string Inter = 'InterCon';
    string auc = 'US/Canada';
    string aeuro = 'Europe';
    string aInter = 'InterCon';
        
    for(Opportunity unity: Trigger.new) {
       unity.Opp_Owner_Address__c = txt;
       unity.Opp_Owner_Phone__c = us[0].Phone;
       unity.Opp_Owner_Fax__c = us[0].Fax;
       unity.Opp_Owner_Email__c = us[0].Email;
       
       UserIds.add(unity.ownerId);


    If( us[0].Region__c == uc || us[0].Region__c == euro || us[0].Region__c == Inter ){

       unity.Opportunity_Region__c =us[0].Region__c;
  
      }

    Map<Id, Account> a = new Map<Id, Account>();
    List<Account> ac = [select Id, OwnerId from Account where id =: unity.Accountid];
    List<user> aus = [select Id, Region__c from User where id =: unity.account.ownerid];
    
    If( aus[0].Region__c != auc || aus[0].Region__c != aeuro || aus[0].Region__c != aInter ){

       unity.Opportunity_Region__c = aus[0].Region__c;
    } else {
    unity.Opportunity_Region__c= txt;
    }
  }
}

 

 

How do I solve the error?

 

Thank you,

ckellie

OK so I've been an admin for about 3 years and (for better or worse) know more about SF than anyone in my company.  i have some experience with apex and Visualforce, but little with triggers.

 

what i need is to write a trigger in production that does this:  the trigger should create a new record in a custom object called "Vehicles" when an Opportunity record is created with a specific value in one of its custom fields (the field is called "Type").  So, when an opp is created and saved with Type = "x", then the trigger should fire, and a new vehicle object record should be created that is populated with a few fields from that opportunity record.

 

can anyone send me some code to show me what this trigger should be or look like?  I've been researching this but have no clue, and I'm afraid of writing bad code that will cause problems.

 

also, the custom object is not in a parent-child relationship with the opporuntiy object, and i don't want it to be unless it has to be.

 

i know the developers in here are ridiculously smart and talented, and i'm just hoping one of you feels sorry enough for an amateur like me to help me out.  thanks a lot.

Ok. I give up... What am I doing wrong? 

 

 

package comEJMSandbox;


	import com.sforce.soap.enterprise.EnterpriseConnection;
	import com.sforce.soap.enterprise.GetUserInfoResult;
	import com.sforce.ws.*;

	public class testLogin {
		
	  
	  

	  public static void main(String[] args) {
		
		  ConnectorConfig config = new ConnectorConfig();
	      config.setUsername("admin@salesforce.com");
	      config.setPassword("password");
	      
	      config.setAuthEndpoint("https://login.salesforce.com/services/Soap/c/20.0");
	      EnterpriseConnection connection;
	      try {
	    	  connection = new EnterpriseConnection(config);
	          GetUserInfoResult userInfo = connection.getUserInfo();
	          System.out.println("\nLogging in ...\n");
	          System.out.println("UserID: " + userInfo.getUserId());
	          System.out.println("User Full Name: " + 
	              userInfo.getUserFullName());
	          System.out.println("User Email: " + 
	              userInfo.getUserEmail());
	          System.out.println();
	          System.out.println("SessionID: " + 
	              config.getSessionId());
	          System.out.println("Auth End Point: " + 
	              config.getAuthEndpoint());
	          System.out.println("Service End Point: " + 
	              config.getServiceEndpoint());
	          System.out.println();
	         
	        } catch (ConnectionException ce) {
	        	ce.printStackTrace();
	        }
		
		
		  
	    
	  }	  
	  
}

 

I get this error

 

 

com.sforce.ws.ConnectionException: Unexpected element. Parser was expecting element 'urn:enterprise.soap.sforce.com:orgAttachmentFileSizeLimit' but found 'urn:enterprise.soap.sforce.com:orgDefaultCurrencyIsoCode'
	at com.sforce.ws.bind.TypeMapper.verifyTag(TypeMapper.java:386)
	at com.sforce.ws.bind.TypeMapper.verifyElement(TypeMapper.java:415)
	at com.sforce.soap.enterprise.GetUserInfoResult.loadFields(GetUserInfoResult.java:1)
	at com.sforce.soap.enterprise.GetUserInfoResult.load(GetUserInfoResult.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.soap.enterprise.LoginResult.loadFields(LoginResult.java:1)
	at com.sforce.soap.enterprise.LoginResult.load(LoginResult.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.soap.enterprise.LoginResponse_element.loadFields(LoginResponse_element.java:1)
	at com.sforce.soap.enterprise.LoginResponse_element.load(LoginResponse_element.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:170)
	at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:144)
	at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
	at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:1)
	at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:1)
	at comEJMSandbox.testLogin.main(testLogin.java:22)

 

 

 

I'm trying to do something I think is relatively simple. I am basically monitoring the insersts on a Task object. If one of the subjects of those inserts meets a certain criteria, I want to update the Comments field (Description) and have the new comments area inserted along with the rest of the Task information.

 

Been racking my brain on this, searched across the board and all but still haven't had much luck. If you have any insight, it's much appreciated!

 

The code below is runs without issue, I have a unit test and that's fine. Even when I throw in debugs in there, everything executes as it should. But still, the field never shows up updated.

 

 

trigger task_StoreMassEmailBody_upd on Task (before insert) {
	if(Trigger.isBefore) {
		for(Task t : Trigger.new) {
		    Boolean LogBody = Trigger.new[0].Subject.contains('special subject');
			if(LogBody) { t.Description = 'Win'; }
		}
	}
}

 What am I missing here? I've also tried it with an after update, and create a set of all the trigger.new ID's related to the task, and then iterate through those and do an update after (since, iirc, after insert the fields are ready only) but still no luck.

 

 

Thanks in advance!

  • February 16, 2011
  • Like
  • 0