You need to sign in to do that
Don't have an account?
Edward Scott 17
opportunity contact count
Hi,
I am working on a DML statement that will first collect every opportunity where the close date equals 11/26/2018. Those opps will then be added to a second list and if they have a name of test then the opportunity will be updated. Most of it is working now. The problem I am having is updating the opportunity after it is found. I want to update the Primary Source Campaign (Campaign.name) which is a standard field on the opportunity with the value of the Primary Contact's (Primary_Contact__c a custom field on the opportunity that looks up to the Contact) Source Campaign (Source_Campaign__c another custom field on the contact page).
Long story short I am not sure how to write the apex code to look up the value of a custom field. I am pasting the code below.
Thanks in advance for your help,
Ed
I am working on a DML statement that will first collect every opportunity where the close date equals 11/26/2018. Those opps will then be added to a second list and if they have a name of test then the opportunity will be updated. Most of it is working now. The problem I am having is updating the opportunity after it is found. I want to update the Primary Source Campaign (Campaign.name) which is a standard field on the opportunity with the value of the Primary Contact's (Primary_Contact__c a custom field on the opportunity that looks up to the Contact) Source Campaign (Source_Campaign__c another custom field on the contact page).
Long story short I am not sure how to write the apex code to look up the value of a custom field. I am pasting the code below.
Thanks in advance for your help,
Ed
//collect all opportunities Date closeDate = Date.newInstance(2018, 11, 26); List<Opportunity> oppList = [Select Id, Name, Description, Type, StageName, Primary_Contact__c, Campaign.name from Opportunity Where Closedate =:closeDate]; //Create a list to store the records that we need to update List<Opportunity> updatedOppList = new List <Opportunity>(); for (Opportunity obj:oppList) { if(obj.name =='test'){ obj.campaign.name = Primary_Contact__c.Source_Campaign__c; updatedOppList.add(obj); } } //DML Statement to update the invoice status update updatedOppList; //Prints the value of updated invoices System.debug('List has been updated and updated value of records are'+updatedOppList);
Change the query like below:
List<Opportunity> oppList = [Select Id, Name, Description, Type, StageName, Campaign, Primary_Contact__c, Primary_Contact__r.Source_Campaign__c, Campaign.name from Opportunity Where Closedate =:closeDate];
and inside the for loop change the below line as like below:
obj.campaign = obj.Primary_Contact__r.Source_Campaign__c;
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C