You need to sign in to do that
Don't have an account?
Synthia B.
Apex Trigger: Showing Rec Id's and not Rec Name
The trigger below works great when a new opportunity is created however, if I need to make a change to the record types I would have to update the trigger in the sanidbox and send it back to the live enviornment.
********************************************************************************************************************
The trigger below works as well but it only shows the record Id's when a new opportunity is created and not the name of the recodes. I am not sure what I am missing.
Thanks in advance.
trigger IMPBI on Plan_Year__c (after insert) { List <Implementation__c> impToInsert = new List <Implementation__c>(); Map<Integer, String> impMap = new Map<Integer, String>(); impMap.put(1, 'Account/Billing Structure'); impMap.put(2, 'Benefit Effective Date'); impMap.put(3, 'Communications'); impMap.put(4, 'Contracts/Required Documents'); impMap.put(5, 'Data Requirements'); impMap.put(6, 'Open Enrollment'); impMap.put(7, 'Planning/Implementation'); impMap.put(8, 'Post Enrollment'); impMap.put(9, 'Post Implementation'); impMap.put(10, 'Pre-Implementation'); impMap.put(11, 'Required Documents'); impMap.put(12, 'Technical/Reporting'); impMap.put(13, 'Vendor Service Agreement'); for (Plan_Year__c currPlanYear : Trigger.New) { for(Integer i=1; i<=13; i++) { Implementation__c rec = new implementation__c (Name = impMap.get(i), Plan_Year_1__c = currPlanYear.Id); ImpToInsert.add(rec); } } Database.saveResult[] sr = database.insert(impToInsert,false); for(integer x=0;x<sr.size();x++) { if(sr[x].isSuccess() == false) system.debug(logginglevel.error,sr[x].getErrors()[0].getMessage()); } }
********************************************************************************************************************
The trigger below works as well but it only shows the record Id's when a new opportunity is created and not the name of the recodes. I am not sure what I am missing.
trigger planTrigger_AT on Plan_Year__c (after insert) { list<RecordType> RT=new list<RecordType>(); RT=[select id from RecordType where SObjectType = 'Implementation__c' and isActive=true]; list<Implementation__c> List_imp = new list<Implementation__c>(); if(trigger.isInsert){ if(trigger.isAfter){ for(Plan_Year__c PY: Trigger.new){ for(RecordType RC : RT){ Implementation__c imp = new Implementation__c(); imp.RecordTypeid = RC.id; imp.Plan_Year_1__c = PY.id; List_imp.add(imp); } } if(RT.size()>0){ insert List_imp; } } } }
Thanks in advance.
If don't do then it will display record id instead of name. It does happen when we insert the record using apex or api.
Thanks
Abdul Vahid
I created the following filed on the Opportunity object as well as on the Implementation object. I am still getting the Id's and not the names of the records.
Plan_Year_1__c Lookup(Plan Year)
I am not following what you advised "check that on the object is it text or autonumber field, if its text then we have to put text while inserting record."Can you provide steps for this?
Thanks!
The records are only on the Implementation Object as they belong to Implementation. The Plan Year Object is the Opportunity Object. There are no records on the Plan Year Object.
Thank you!
For
trigger planTrigger_AT on Plan_Year__c (after insert) ..............
{ Implementation__c imp = new Implementation__c();
imp.RecordTypeid = RC.id;
imp.Plan_Year_1__c = PY.id;
Need to add: imp.Name = ....(what ever name you like to see)
List_imp.add(imp); } }
if(RT.size()>0){ insert List_imp; } } } }
you are not getting the name because you are not adding the name
You need to add: imp.Name = .... (what ever name you like to see)
thx.