You need to sign in to do that
Don't have an account?
Omkar11
Load data from CSV file. Trigger error appears on VF page - want to hide error
Hi,
I have a requirement in that I want to save 100+ records at a time.
I am using Database.Insert(recordlist, false). If any of the record is failing during the insert (because of obj.AddError('enter name') in trigger) then i am caputuring the error from Database.SaveResult[].
Problem : If error (AddError() method ) is occured in trigger then it is displaying on the VF page as well. For validation rule it is not showing error on VF page. I don't want to show this error message, as i am generating result (success/fail) CSV file.
NOTE : I want <apex:pageMessages ></apex:pageMessages> on VF Page for other functionality on same page.
Thanks in advance.
VF page
<apex:page standardController="Account" extensions="DatabaseInsertPOCExt">
<apex:pageMessages ></apex:pageMessages>
<apex:form >
<apex:pageBlock title="Account Insert">
<apex:pageBlockButtons >
<apex:commandButton value="Insert Account" action="{!insertAccount}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller
public with sharing class DatabaseInsertPOCExt
{
public DatabaseInsertPOCExt(ApexPages.StandardController controller)
{
}
public void insertAccount()
{
try
{
list<Account> accList = new list<Account>();
for(integer i = 0; i < 3; i++)
{
Account a = new Account();
a.name = 'omkar - ' + string.valueof(i);
a.City__c = 'Pune-'+ string.valueof(i);
accList.add(a);
}
Database.SaveResult[] sr = Database.insert(accList, False);
for(Database.SaveResult s : sr)
{
system.debug('error--------->'+s.getErrors());
}
}
catch(exception ex)
{
system.debug('ex---------->'+ex);
}
}
}
Trigger
trigger testTriggerAccount on Account (before insert, before update)
{
for(Account a : Trigger.new)
{
if(a.City__c =='Pune-1')
{
a.addError('Other city plz');
}
}
}
I have a requirement in that I want to save 100+ records at a time.
I am using Database.Insert(recordlist, false). If any of the record is failing during the insert (because of obj.AddError('enter name') in trigger) then i am caputuring the error from Database.SaveResult[].
Problem : If error (AddError() method ) is occured in trigger then it is displaying on the VF page as well. For validation rule it is not showing error on VF page. I don't want to show this error message, as i am generating result (success/fail) CSV file.
NOTE : I want <apex:pageMessages ></apex:pageMessages> on VF Page for other functionality on same page.
Thanks in advance.
VF page
<apex:page standardController="Account" extensions="DatabaseInsertPOCExt">
<apex:pageMessages ></apex:pageMessages>
<apex:form >
<apex:pageBlock title="Account Insert">
<apex:pageBlockButtons >
<apex:commandButton value="Insert Account" action="{!insertAccount}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller
public with sharing class DatabaseInsertPOCExt
{
public DatabaseInsertPOCExt(ApexPages.StandardController controller)
{
}
public void insertAccount()
{
try
{
list<Account> accList = new list<Account>();
for(integer i = 0; i < 3; i++)
{
Account a = new Account();
a.name = 'omkar - ' + string.valueof(i);
a.City__c = 'Pune-'+ string.valueof(i);
accList.add(a);
}
Database.SaveResult[] sr = Database.insert(accList, False);
for(Database.SaveResult s : sr)
{
system.debug('error--------->'+s.getErrors());
}
}
catch(exception ex)
{
system.debug('ex---------->'+ex);
}
}
}
Trigger
trigger testTriggerAccount on Account (before insert, before update)
{
for(Account a : Trigger.new)
{
if(a.City__c =='Pune-1')
{
a.addError('Other city plz');
}
}
}
I don't think there is a way of adding the error to a csv field while inserting from a visualforce page. Errors that happen on vf page will be displayed on the page itself. Only changes made through the API like the data loader will create success/failure csv files.
Thanks,
Shashank
I have done the generating CSV after the operation. In my case the input is CSV file and im generating CSV as success/fail result. Error msg will be displayed along with row index.
But if error is from trigger the system is showing the error on VF page I just want to hide that from User. If error is by validation rule then it is not showing on page.
Anybody have any solution. Thanks in advance.
Did you try disabling the trigger and check if the validation rule error is not showing on the VF page? Because it usually should! And triggers fire before validation rules.
I'm not sure if there is a way of avoiding the trigger validation messages on the VF page.
Thanks,
Shashank
Thanks,
Omkar Jante
Can you please post your code how you are generating success and failure file,
I have requirement like am inserting bulk records more than 10k ,and if any field have error in my csv i need to show error message in visalforce page or if i generate succes and error file then its okey please share with me how you did.