0

I have a button called Sync on Order object. I want to sync only those orderlineitems whose IsSynced field has value as 'No'. If there are no such orderlineitems then i want to display a message on Order detail page say 'No more orderlineitems to Sync'.

1
  • Sync is a button on Order object which executes a javascript & calls the controller via trigger on after update event. Now suppose my list has no rows to return(i.e no records with Sync='Yes'), so i put a condition like this: if(list.size()>0){ call controller } else { addError}. Now the problem is whenever i make an update on Order object it is not allowing me to save(giving the add error message- No more records to sync) – Ashish Mar 27 '15 at 11:11
2

Have you tried addError function? It helps to add error messages. You can add it in your trigger so that when there are no more records to sync it'll give the message.

Example:

public class MyException extends Exception {} 


Trigger.new[0].addError(new myException('no more items to sync'));
0

If you want to send an error message from your controller, you need something like this:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'my error msg'));

Plus, you need to include <apex:pageMessages id="messages"/> on your Visualforce page and make sure you rerender it after your action runs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.