You need to sign in to do that
Don't have an account?
Rajat Bhatt 4
My Trigger is not working properly , please help
Hi,
I am new to salesforce and i am facing an issue my Trigger is not working properly.
I want the trigger to check whether the all Shipping Address field is filled or not , and if not the display the error message.
Any help will be appreciated.
Thanks.
I am new to salesforce and i am facing an issue my Trigger is not working properly.
I want the trigger to check whether the all Shipping Address field is filled or not , and if not the display the error message.
Any help will be appreciated.
Thanks.
trigger shippingAddress on Account (before insert,before update) { List<Account> accList=new List<Account>(); for(account accObject:trigger.new) { if(accObject.ShippingStreet !=null && accObject.ShippingCity!=null && accObject.ShippingState!=null && accObject.ShippingPostalCode!=null && accObject.ShippingCountry!=null) { accList.add(accObject); } else { accObject.addError('All Shipping Fields are required'); } } insert accList; }
Hi have done some small changes to your trigger. Hope this will work for you.
trigger shippingAddress on Account (after insert,after update)
{
try{
List<Account> accList=new List<Account>();
for(account accObject:trigger.new)
{
if(accObject.ShippingStreet ==null || accObject.ShippingCity ==null ||
accObject.ShippingState ==null || accObject.ShippingPostalCode==null ||
accObject.ShippingCountry==null)
{
accObject.addError('All Shipping Fields are required');
}
else
{
accList.add(accObject);
}
}
insert accList;
}catch(Exception exp){
system.debug('The following exception has occurred ' + exp.getMessage() + ' at line no ' + exp.getLineNumber());
}
}
Thank you
Ajay Dubedi
All Answers
Hi have done some small changes to your trigger. Hope this will work for you.
trigger shippingAddress on Account (after insert,after update)
{
try{
List<Account> accList=new List<Account>();
for(account accObject:trigger.new)
{
if(accObject.ShippingStreet ==null || accObject.ShippingCity ==null ||
accObject.ShippingState ==null || accObject.ShippingPostalCode==null ||
accObject.ShippingCountry==null)
{
accObject.addError('All Shipping Fields are required');
}
else
{
accList.add(accObject);
}
}
insert accList;
}catch(Exception exp){
system.debug('The following exception has occurred ' + exp.getMessage() + ' at line no ' + exp.getLineNumber());
}
}
Thank you
Ajay Dubedi
Could you tell me what was wrong with my code as i could not understand the difference.
Thanks a lot again.