• Omkar11
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
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 am looking for DEV-401 latest dumps. is anybody have it plz send me.

 

Thanks in advance.

  • September 28, 2012
  • Like
  • 0

Hi,

 

I want to access mobile camera from salesforce VF page to capture photo and save it in salesforce object.

 

Please help me. Thanks in advance.

 

OM

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');
        }
    }
}

Hi,

 

I want to access mobile camera from salesforce VF page to capture photo and save it in salesforce object.

 

Please help me. Thanks in advance.

 

OM