Saving custom object programmatically in salesforce - object

I defined a custom object (called Transaction). I populated it within a trigger. The trigger is defined after insert of Task object. After populating Transaction object i want to save it such that it shows up as a object of type Transaction in data management->storage usage.
How do i do this?
The only way I have saved custom objects is by using dataloader to import them. Not sure how to save them directly from within Sdfc apex code.
Any pointers would be appreciated.
regards
Sameer

Not sure if understand correctly, but in trigger You probably got something like this:
Transaction__c trans = new Transaction__c();
trans.Some_Field__c = 'some value';
And after that You should have add:
insert trans;
Hope that helps

Related

How to insert into custom table

I have a customization to the Invoice and Memo screen, where I have a completely custom table to which I want to write an error log entry. Since this doesn't really fit with how the training addresses the issue - is there a way to do this directly? I noticed that there's a PXInsert<> command - but there's no documentation that I could find, either in the Framework help, or here on Stack Overflow.
I know I can create a Cache object for my custom table's DAC and use the Insert command of that Cache - but I don't know the exact syntax for doing that (and I couldn't find a good fit for what I'm trying to do in the training manuals). Maybe I missed it.
The syntax to create a Cache object (or I think you might be thinking of a graph) is to use PXGraph object. Here is an example:
private void Function()
{
//TargetGraph is the name of the custom page
TargetGraph graph = PXGraph.CreateInstance<TargetGraph>();
//TargetDAC is the name of the custom DAC in your customizations
TargetDAC dac = new TargetDAC();
//Set all data to dac
dac.Log = log;
//Finally insert and perform the save action for the graph
graph.LogView.Insert(dac);
graph.Actions.PressSave();
}
Perhaps someone could add to this answer on how to grab the errors from the page if that is also what you need.

How can I update the status of a Test

We are automating tests using selenium, and I would like to be able to update the test to their latest status based on the result of the automated test.
I'm able to identify the test, but it appears the Status property does not have a setter.
It sounds like you're using the Object Model library.
The Object Model library does not, in fact, have a setter for that property. It may expect you to use an Operation on that asset to adjust status, such as .Close()
The SDK API library has more fine-grained access and allows more arbitrary asset editing. You may also hit the rest-1.v1 API endpoint directly with an XML body describing your attribute change. You'd need to know the ID of the TestStatus list item you want to set it to, and do a single-valued relation update
Do you have code you can share?
Once I have a VersionOne.SDK.ObjectModel.Test object I was able to do the following:
Test test = null;
test = FindTest(regressionTest); // This finds the Test object.
test.Status.CurrentValue = status;
test.Save();

is there a way to see which objects in a managedobjectcontext have not yet been added to the persistent store?

is there a simple and efficient/fast way to query a managedobjectcontext to get an array of all the managedobjects in the context that have not yet been added to the persistent store?
i ask this because i would like to be able to save nsmanagedobjects that have been added to the MOC only if they conform to certain criteria. basically i want to be able to do this so that if some unexpected event happened before my managed object attributes were properly populated, i can catch this fact and purge the object(s) before saving the context. given the complexity of the navigation possible in the app, i'd like to have a look at the data to be sure they are good before i save.
i suppose i could also do this with some kind of validation rule and a flag field that doesn't get set until i am sure the user has added all the data to the record, but i don't yet know how to implement this...
any help much appreciated.
The insertedObjects method of NSManagedObjectContext
returns the set of objects that have been inserted into the context but not yet saved in a persistent store.

How do you pass a NotesDocument / NotesViewEntry Collection into a Custom Control via custom property?

I want to have a custom control that works on whatever documents I decide to pass to it. What's the best way of doing that?
Assuming that you can't pass the collection directly... should a function be created to convert the collection to a hashMap or vector of UNID's?
Is there another way?
Thanks
If you instead pass a data source, you'll get recycle-safe objects transferred to the Custom Control.
For example, if the XPage defines a document data source, and you pass a reference to that data source to the CC, the Java object being transferred is a DominoDocument, which is a recycle-safe wrapper around the "back end" document. Passing the document directly risks that the linked C object will get orphaned between requests.
Similarly, passing a reference to a view data source provides the CC a DominoView, which is essentially a recycle-safe wrapper around a back end ViewEntryCollection.
For most use cases, you can get away with just passing the back end object directly, but passing the data source is far safer.
Passing NotesDocument and/or NotesDocumentCollection objects to the Custom Control works fine. Just set the Custom Control's property type as java.lang.Object. By this you can transfer what ever objects to the Custom Control.

Core Data: Design questions. Object wrappers or not?

I'm designing my first project using Core Data (for iPhone) and Im having some issues that might be related with my design approach.
I'm doing an application that allows the user to create an Order (let's say for a restaurant).
I'm using the graphic designer to model my persistence object (i.e. OrdeMO). I add MO to the ead of each name to indicate its a Managed Object.
I use XCode to create the Managed Object Class automatically.
I have created some "DAO" classes that allows you to search or create a new object in the Managed Context.
Now to my problem.
I want to create an OrderMO object to store the order the user is creating, BUT I don't want it to be part of the context until the user actually places it.
I tried creating the object with [OrderMO alloc] but the object I get is "incomplete" and when I try to set any of its attribute I get an error.
I'm assuming the problem is that I need to create the order IN the context in order to use it. Is that so?
I have considered various options:
Create the object in the context and the user rollback if the user discards the order. The problem is that the user might save other context object during the process (like his prefs) so this doesn't work. Is there a way to create the object "inside a separate transaction" of sorts?
Create a wrapper object that will hold the same data as the MO, and then only create the MO when the user place the order. The downside of this is that I have to maintain a new class.
Create an attribute in the MO, such as "placed", and use to filter my searches in the context. The problem with this one is that I will end up with "trash" objects in the domain (i.e. unplaced orders) and I will have to do some cleanup from time to time...
Do I have any other choice?
Any suggestion is appreciated.
Thanks (for reading this long post!)
Gonso
You should create the OrderMO object in the managed object context and then delete it if the user decides not to place the order.
If the context is saved before the object is deleted, the "trash" object will be deleted from the persistent store on the next save (if the context wasn't saved, the "trash" object will never be saved to the persistent store).
The flag to determine if the order was placed or not does not have to live in the OrderMO object as you suggest in option 3. It could be in the view controller that is tracking the order(s) that are being edited. And, again, you won't have "trash" objects because they will have been deleted.

Resources