+ Start a Discussion
Tobias GareisTobias Gareis 

Country-Picklist problem

Hi,

I'm trying to create a really simple trigger on events, that changes a field in the related opportunity on event-creation. I had some help with the code, that's why I think it's correct. But I'm getting tons of errors all saying:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Bei diesem Land liegt ein Problem vor, auch wenn es möglicherweise korrekt aussieht. Bitte wählen Sie ein Land aus der Liste der gültigen Länder aus.: [BillingCountry]
In English that should be something like:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION:  There's a problem with this county, even though it might look correct. Please choose a country from the list of available countries..: [BillingCountry]
Any ideas?
 
Best Answer chosen by Tobias Gareis
ManojjenaManojjena
Hey Tobias,

Please try the below code .
trigger updateOpportunty on Event (before insert, before update) {
	     
	    List<Id> OpportuntyIds=new List<Id>();
	    List<Opportunity> OpportunitysToUpdate =new List<Opportunity>();
	    for(Event t:trigger.new){
	            if(String.valueOf(t.whatId).startsWith('006') == TRUE){//check if the task is associated with a Opportunty
	                OpportuntyIds.add(t.whatId);
	            }
	    }
	    Map<Id,Opportunity> OpportunityMap = new Map<Id,Opportunity>([SELECT Id,NextStep FROM Opportunity WHERE Id IN :OpportuntyIds]);
	     
	    For (Event t:trigger.new){
		    if(String.valueOf(t.whatId).startsWith('006'){
				Opportunity opp = OpportunityMap.get(t.whatId);
				opp.NextStep = t.subject+ ' ' +t.ActivityDate;
				OpportunitysToUpdate.add(opp);
			}
	    }
	     
	    try{
	        update OpportunitysToUpdate;
	    }catch(DMLException e){
	        system.debug('Opportunitys were not all properly updated.  Error: '+e);
	    }
	}

 

All Answers

ManojjenaManojjena
Hey Tobias,
Is it possible to paste your trigger code ?
 
Tobias GareisTobias Gareis
trigger updateOpportunty on Event (before insert, before update) {
02	     
03	    List<Id> OpportuntyIds=new List<Id>();
04	    List<Opportunity> OpportunitysToUpdate =new List<Opportunity>();
05	    for(Event t:trigger.new){
06	            if(String.valueOf(t.whatId).startsWith('006') == TRUE){//check if the task is associated with a Opportunty
07	                OpportuntyIds.add(t.whatId);
08	            }
09	    }
10	    Map<Id,Opportunity> OpportunityMap = new Map<Id,Opportunity>([SELECT Id,NextStep FROM Opportunity WHERE Id IN :OpportuntyIds]);
11	     
12	    For (Event t:trigger.new){
13	        Opportunity opp = OpportunityMap.get(t.whatId);
14	        opp.NextStep = t.subject+ ' ' +t.ActivityDate;
15	        OpportunitysToUpdate.add(opp);
16	    }
17	     
18	    try{
19	        update OpportunitysToUpdate;
20	    }catch(DMLException e){
21	        system.debug('Opportunitys were not all properly updated.  Error: '+e);
22	    }
23	}
When turning off Country-Picklist, it works, but I don't want to turn that off in production.
 
ManojjenaManojjena
Hey Tobias,

Please try the below code .
trigger updateOpportunty on Event (before insert, before update) {
	     
	    List<Id> OpportuntyIds=new List<Id>();
	    List<Opportunity> OpportunitysToUpdate =new List<Opportunity>();
	    for(Event t:trigger.new){
	            if(String.valueOf(t.whatId).startsWith('006') == TRUE){//check if the task is associated with a Opportunty
	                OpportuntyIds.add(t.whatId);
	            }
	    }
	    Map<Id,Opportunity> OpportunityMap = new Map<Id,Opportunity>([SELECT Id,NextStep FROM Opportunity WHERE Id IN :OpportuntyIds]);
	     
	    For (Event t:trigger.new){
		    if(String.valueOf(t.whatId).startsWith('006'){
				Opportunity opp = OpportunityMap.get(t.whatId);
				opp.NextStep = t.subject+ ' ' +t.ActivityDate;
				OpportunitysToUpdate.add(opp);
			}
	    }
	     
	    try{
	        update OpportunitysToUpdate;
	    }catch(DMLException e){
	        system.debug('Opportunitys were not all properly updated.  Error: '+e);
	    }
	}

 
This was selected as the best answer
Tobias GareisTobias Gareis
Thanks Mate, that helped a lot!