You need to sign in to do that
Don't have an account?
WesCooper
New to Triggers
Hey guys, I am relatively new to writing triggers in SaleForce and so I am hitting a brick wall that I cannot seem to climb over. I've look on the net for the answer, but cannot seem to find it.
I need to create a case after and insert is done from another object. I have no issue here; it works. Thep roblem I am having is pulling a Lookup value from the object. I'm not sure how to do this and I'm having trouble figuring it out.
Here is my trigger:
trigger MyTrigger on MyObject (after insert) { private String Acc; private String Opp; private String pd; AssignmentRule aRule = new AssignmentRule(); aRule = [SELECT id FROM AssignmentRule WHERE SobjectType = 'Case' AND Active = true limit 1]; Database.DMLOptions dmlOpts = new Database.DMLOptions(); dmlOpts.assignmentRuleHeader.assignmentRuleId = aRule.id; Id rtID = [select Id, name from RecordType where name = 'Implementation' and SObjectType = 'Case' limit 1].Id; Case newpdCase = new Case( Subject = 'New Test Case Created', Priority = 'Medium', Status = 'New', Reason = 'Implementation', Description = 'Testing the trigger', RecordTypeId = rtID ); newpdCase.setOptions(dmlOpts); insert newpdcase; }
Any help would be greatly appreciated.
Thank you,
Wes
Hi,
the value in the lookup fields is a text field, just this text is ID to other record (and salesforce validate that).
if for example, in Object A you have field that is lookup to object B,
then this field must contain ID of existing object from type B.
By the way, it will be good idea to amend your code to support bulk records.
means, work on list instead of single object.
Hi, thank you for your assistance. As I am really new to the world of Apex, I am having some trouble with using IDs and Mappings. I've updated my code below, but it is still not working as intended. Not sure what I am doing wrong here.
I get no errors, but I also do not get the result I am looking for. The object with the trigger has a Lookup field called "Account Name" which is linked to Account. Under the Case object, there is a field called Account, which is also a lookup value. When the trigger executes, it doesn't seem to copy the value of Account from BLND_DFDT_Project__c to
the Case object.
Not sure what I am doing wrong here, but any help would be greatly appreciated.
I can't seem to figure out what the issue is here. When I run a debug on "newpdCase", it shows me that it contains the right ID and Account Name. Not sure why upon the insert It remains blank.
16:07:20:393 USER_DEBUG [39]|DEBUG|Account:{Name=Test, Id=001c0000004g6sxAAA}