+ Start a Discussion
kevinjia1984kevinjia1984 

Record can not show proper value

 

Hi all,
I have met a problem. I'd appreciate it very much if anyone can offer help. The situation is when the Publication_Mentions__c object created with the Referral__c check box selected,  An opportunity object will be created in this Publication_Mentions__c object's related list. In the opportunity record's Name field, I need to put contact's firstname and lastname. Contact object is lookup related to Publication_Mention__c object and the lookup field in Publication_Mention__c named "Organisation_Contact_del__r". After I finished the code below and test it. I found the value in Opportunity.Name is null null, other fields' values are fine. Don't know what happened, I have selected a contact firstname and lastname when I created the Publication_Mention__c. Please give me some help, thanks.
public with sharing class NewPublicationMention {
 public static void createNewOpportunity(List<Publication_Mention__c> PublicationMentions)
 {
 for(Publication_Mention__c PM: PublicationMentions)
 {
 //when the Referral__c checkbox ticked
 if(PM.Referral__c==True)
 {
 
 //a new Opportunity object will be created
 Opportunity newOpportunity = new Opportunity();
 newOpportunity.Publication_Mention__c = PM.Id;
 
 
 //fields of the new Opportunity object
 newOpportunity.Name = PM.Organisation_Contact_del__r.FirstName + PM.Organisation_Contact_del__r.LastName;
newOpportunity.StageName = 'New';
newOpportunity.CloseDate = Date.today();
newOpportunity.Type = 'Free';
newOpportunity.Order_Source__c = 'Helpline';
newOpportunity.Order_Date__c = Date.today();
newOpportunity.Amount = 0;
insert newOpportunity;

}

}

}

}