Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Community - Apex Triggers - Apex Code Development - Force.com Discussion Boards

Started 1 month, 1 week ago by Laytro80
Hi, Very new to salesforce APEX development. I have created a custom object called file note (file_note__c). The object contains a checkbox field called new opportunity ( new_opportunity__c). When I save a new or updated file note record I want a trigger to run. Trigger If the 'new opportunity checkbox' is ticked (set...
Site: Salesforce.com Community  Salesforce.com Community - site profile
Forum: Apex Code Development  Apex Code Development - forum profile
Total authors: 3 authors
Total thread posts: 14 posts
Thread activity: no new posts during last week
Domain info for: salesforce.com

Other posts in this thread:

Anand@SAAS replied 1 month, 1 week ago
You can certainly create the opportunity using a trigger but you cannot navigate the user to another record from a trigger. Here are a few options: 1. Use "visual force" and "retURL" or "saveURL" in order to take you to the opportunity record 2. Override "edit" of "File_Note__c" with a visual force page and manage the logic that you mention in the controller extension. More info ...

Laytro80 replied 1 month, 1 week ago
Thanks for the quick reply. I can certainly recreate my filenote to look how it does currently. Not sure how to write the apex code to evaluate if the new opportunity checkbox is true and if creating a new opportunity do you have an example of sample code. Thanks again Much appreciated.

ColinKenworthy1 replied 1 month, 1 week ago
trigger myFirstTrigger on file_note__c (after insert, after update) { System.Debug('## >>> Trigger executing run by ' + UserInfo.getName()); file_note__c[] myNotesToProcess = new file_note__c[]{}; for(Integer i=0 ; i<Trigger.new.size() ; i++) { if ( Trigger.new[i].new_opportunity__c == true ) { myNotesToProcess.add(Trigger.new[i]); // ...

Laytro80 replied 1 month, 1 week ago
Thanks Colin, This method worked really well, I really appreciate you taking the time to reply, couple of quick questions. First, at the moment a new opportunity requires mandatory fields to be completed before I can save. To get the trigger to work I have just added manual strings to test. If I wanted to map the opportunity fields required to fields that exist on ...

Laytro80 replied 1 month, 1 week ago
Have figured out an answer to question 1. I just need to know now if it is possible to link the newly create opportunity to the filenote. Cheers R

ColinKenworthy1 replied 1 month, 1 week ago
In this for loop the the instance of the file_note__c has been named myNote (make up any naming system you like). So to use the fields you should use e.g. oppy.Name = myNote.Subject__c; The Id field in the opportunities is not known until after the INSERT. It would be rather easier in this case if the Opportunity had a lookup field to the file_note__c e.g. oppy.file_note_lookup...

Laytro80 replied 1 month, 1 week ago
Thanks again Colin, I have amended my code see below and it looked like it worked and saved okay. Problem is which I try the process I get this error message Error: Invalid Data. Review all error messages below to correct your data. Apex trigger myFirstTrigger caused an unexpected exception, contact your administrator: myFirstTrigger: execution of AfterUpdate caused by...

Laytro80 replied 1 month, 1 week ago
Have also tried upsert same error message

ColinKenworthy1 replied 1 month ago
Hi, I think you should change these to "before insert" and "before update" triggers then you won't need the "update myNotesToProcess;" line at all. Personally I think this is nicer as a before trigger (since you are also updating the file_note__c in the trigger) BUT maybe in future with workflow field updates in place you may need to make this an after trigger to pickup some of the ...

Laytro80 replied 1 month ago
Hi Colin, Thanks again for all your help will read through the help files mentioned. Requirements changed slightly which I thought would make this a lot easier. Have added two fields to the opportunity record one checkbox which indicates if the source was a filenote and the other a link to the filenote. Amended code is below, only problem I have is the opportunity filenote...

 

Top contributing authors

Name
Posts
Laytro80
8
user's latest post:
Community - Apex Triggers - Apex...
Published (2009-11-09 13:50:00)
Thanks for all your help Colin, works like a charm. &nbsp; &nbsp;
ColinKenworthy1
5
user's latest post:
Community - Apex Triggers - Apex...
Published (2009-11-10 02:16:00)
Please read this post - it explains things quite simply about before and after triggers. http://community.salesforce.com/sforce/board/message?board.id=apex&amp;message.id=22429#M22429 &nbsp; &nbsp;
Anand@SAAS
1
user's latest post:
Community - Apex Triggers - Apex...
Published (2009-11-05 16:35:00)
You can certainly create the opportunity using a trigger but you cannot navigate the user to another record from a trigger. &nbsp; Here are a few options: 1. Use &quot;visual force&quot; and &quot;retURL&quot; or &quot;saveURL&quot; in order to take you to the opportunity record 2. Override &quot;edit&quot; of &quot;File_Note__c&quot; with a visual force page and manage the logic that you mention in...

Related threads on "Salesforce.com Community":

Related threads on other sites:

Thread profile page for "Community - Apex Triggers - Apex Code Development - Force.com Discussion Boards" on http://www.salesforce.com. This report page is a snippet summary view from a single thread "Community - Apex Triggers - Apex Code Development - Force.com Discussion Boards", located on the Message Board at http://www.salesforce.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity