You need to sign in to do that
Don't have an account?
Need help in Bulk Trigger
Trigger :
public class ContactBulkTest {
public static void ContactBulkMethod(Contact[] conts){
List<Country__c> CountryName = [SELECT Id, Phone_Prefix__c FROM Country__c WHERE Name = :MailingCountry LIMIT 1];
map<String, ID> map_cntry = new map<String, ID>
for(Contact c: conts){
map_cntry.put(c.Id,c.Phone_Prefix__c);
}
}
}
Error recieved : Error: Compile Error: unexpected token: 'for' at line 9 column 6
I have some other issues with bulk . But suddenly I am stucked in this issue .
Thanks.
I am doing the same thing ,but slightly diffrently .I will also do this way as well map<id, list<contact> > .
public class ContactBulkTest {
public static void ContactBulkMethod(Contact[] conts){
String PhonePrfix ;
List<Country__c> CountryName = [SELECT name,Phone_Prefix__c FROM Country__c ];
map<String, String> map_cntry = new map<String, String> () ;
for (Country__c c : CountryName ) {
map_cntry.put(c.name,c.Phone_Prefix__c);
system.debug('++++++++'+map_cntry );
}
for(Contact c: conts){
PhonePrfix = map_cntry.get(c.MailingCountry);
system.debug('**********'+PhonePrfix );
}
}
}
This class is same as I posted in my query ,but only thing I missed was these two statements to get values :
for(Contact c: conts){
PhonePrfix = map_cntry.get(c.MailingCountry);
Also,earlier my class was giving Soql limit exception 101 through Trigger .
Anyways thanks a lot dude for discussion :) my issues is now resolved .
All Answers
Clearly visible
for loop isn't regonized, this mean you got to look at the line above and there has to be some issue there
Now if you notice , () <- paranthesis are missing - meaning the map isn't instantiated
Possible Fix
True .its a syntax error .
Thank you .
Please tag the reply as 'solution' - will help others to resolve the issue quickly. You action would highly be appreciated.
Furthermore , I have this class : I tried to bulky it as above but currently I am stuck on how to include (if, else) statement outside my for loop. I am able to make query out of it as above .
public class ContactBulkTest {
public static void ContactBulkMethod(Contact[] conts){
for (Contact c :conts){
if (c.Email <> null)
{
c.Email = c.Email.toLowerCase();
}
if (c.Phone <> null)
{
Country__c[] cntry = [SELECT Id, Phone_Prefix__c FROM Country__c WHERE Name = :c.MailingCountry LIMIT 1];
if (cntry.size() > 0)
{
if (cntry[0].Phone_Prefix__c <> null)
{
c.Mailing_Country_Phone_Prefix_EDITABLE__c = cntry[0].Phone_Prefix__c;
String newphone = c.Phone;
newphone = newphone.replacefirst('\\' + c.Mailing_Country_Phone_Prefix_EDITABLE__c,'');
newphone = newphone.replace('-','');
newphone = newphone.replace('(','');
newphone = newphone.replace(')','');
newphone = newphone.replace('+','');
newphone = newphone.replace(' ','');
newphone = newphone.replace('.','');
newphone = newphone.trim();
while (newphone.startswith('0'))
{
newphone = newphone.replacefirst('0','');
}
String cntryprefix = cntry[0].Phone_Prefix__c;
while (cntryprefix.startswith('+'))
{
cntryprefix = cntryprefix.replacefirst('\\' + '+','');
}
cntryprefix = cntryprefix.trim();
if (newphone.startswith(cntryprefix))
{
newphone = newphone.replacefirst(cntryprefix,'');
}
while (newphone.startswith('0'))
{
newphone = newphone.replacefirst('0','');
}
c.Cleaned_Phone_EDITABLE__c = cntry[0].Phone_Prefix__c + ' ' + newphone;
}
else
{
c.Cleaned_Phone_EDITABLE__c = c.Phone;
}
}
}
else
{
c.Cleaned_Phone_EDITABLE__c = null;
}
}
}
}
Can you please be more clear with the problem and provide the error code you are dealing in
If I were you, i would have followed little of standard practices
1. Make a map of id and list of contacts Map<id, List<Contact>> there populate the map iterating through make a check for validataion and then once done
2. Move out to trigger and ad this pieace handler in the trigger and reference to the size of map
Follow my post - little different but would give idea on how to make trigger handle bulk data
http://www.forcelabs.net/2012/01/salesforce-trigger-to-count-contact.html
I am doing the same thing ,but slightly diffrently .I will also do this way as well map<id, list<contact> > .
public class ContactBulkTest {
public static void ContactBulkMethod(Contact[] conts){
String PhonePrfix ;
List<Country__c> CountryName = [SELECT name,Phone_Prefix__c FROM Country__c ];
map<String, String> map_cntry = new map<String, String> () ;
for (Country__c c : CountryName ) {
map_cntry.put(c.name,c.Phone_Prefix__c);
system.debug('++++++++'+map_cntry );
}
for(Contact c: conts){
PhonePrfix = map_cntry.get(c.MailingCountry);
system.debug('**********'+PhonePrfix );
}
}
}
This class is same as I posted in my query ,but only thing I missed was these two statements to get values :
for(Contact c: conts){
PhonePrfix = map_cntry.get(c.MailingCountry);
Also,earlier my class was giving Soql limit exception 101 through Trigger .
Anyways thanks a lot dude for discussion :) my issues is now resolved .
Great to know this worked for you