You need to sign in to do that
Don't have an account?

Please help with the trigger
trigger case1 on Case (after insert)
{
List<message__c> l=new list<message__c>();
if(trigger.isinsert)
{
for(case c:trigger.new)
{
system.debug('The value in the case variable c is'+c);if(c.fine__c)
{
Message__c a=new Message__c();
//a.accountid__c=c.accountid;
a.name__c=c.casenumber;
System.debug('The value in the variable a.name__c is'+a.name__c);
//a.name__c=c.contact;
a.Name='Sweet and Sour';
System.debug('The value in the variable a.name explixitly has been assigned is'+a.name);
l.add(a);
}
System.debug('The value in the List l is explicitly has been assigned is'+L);
}
}
insert(l);
}
Guys, I am new to salesforce and to this community.I am working on the problem.I have a trigger on the case object and a check boxfield on the case .If somebody checks that box then another object by the name of message should be created and some value from the case object should be passed on to the fields on the message object. For example,this value a.Name='Sweet and Sour'; has been harcoded becasue I was getting some error.a.name__c=c.casenumber;
Above I have assigned values from casenumber field on the case to the field name__c on the message field.
Firstly,Can I do this without having any relationship between the case and the message object.?Secondly,It is adding all the values to the message list as I can see in the debug log.However,it is not not inserting record with the values in the message custome object.Thirdly,Help me in correcting it so that it can insert record in the message object.
Please help
Thanks,
Trick
Correct.
All Answers
First off, you shouldn't have to test if the trigger isInsert, since you have it sent to only fire "after insert".
I'm confused by your second bit. Do you have a second/custom field called "Name" in addition to the standard Name field present on all objects? If so, what value are you putting in each field, Name and Name__c?
When you say it isn't inserting the objects, are you getting any sort of error? If there are no errors, you should be seeing the new objects. One way you can check this is to use the Database.insert method which returns a List of SaveResults. You can then iterate through this list and system.debug the Ids of the new Message__c objects.
Thanks David,
I know my code looks nonsensical to you at the moment.Yes,I have two fields one is Name and other is Name__c which is the custom field.In the name field I have hard coded the value Name='Sweet and sour' and in the other custom name field I am putting the case number from the case object to the Name__c in the message object.
I am not seeing any error.I have simply not been able to see the saved record.I tried system debug and I could see case number value and sweet and sour value but I don't see them in the database.
I have tried database statement also but it did not make any difference.
Has it got anything to do with relationship between the two objects.One is custom object and the other is standard object.
Your suggestions are most welcome.
Thanks,
Trick
It shouldn't have anything to do with the custom vs. standard objects. Is there actually a relationship between the objects? It doesn't sound like there is.
To verify if you inserts are happening, you can do something like this:
Thanks a lot, David, for helping,
I will try to see what result I get.Otherwise I will come back to you to get some more advice.David,does the rest of the code looks good to you?
I am trying to do it without any relationship.
Thanks,
Trick
The basics are there, but you'll need to query the Contact table if you want the Contact name on your new object. You'll have to go through your cases and get the Contact Ids, then query the contact table for a list of contacts so that you can get the Names.
If you need some help with that bit, let me know, but I'm curious to see what you get from the other debugging.
Hi David,
Thanks its working.
I could see information in the message ojbect. I tried to debug with the database statement and I have this id
01C000000OYYMU
From
Trick
There are two versions of every object Id. One 15 character case sensitive Id and another 18 character non-case sensitive. They can typically be used interchangably unless you are doing comparisons.
I'm not aware of a way to convert between the two, particularly 15 to 18, but it may exist.
So Both the ID's would represent the same record.Is that correct?
Correct.