In reference to a previous question located here, I have a new problem.
Our marketing department had an issue with assets being tied to a particular contact record as it was causing issues with opportunities and leads. While I am unsure of the exact nature of the problem, I was asked to remove all contact names from our Customer Assets.
As a result, my code no longer functions properly. It still runs, but the customer signed by field is no longer being filled in.
I wanted to attempt creating a custom field named "Primary Contact" as a checkbox, then when that was checked off the account would automatically show the contact as being the primary.
I could then have the CreateContract and FirmwareUpgrade classes I created reference that field from the account section. After being foiled several times in trying to get that to work, I found that there already is a contact role I could use out of the box. Problem is that I can not find that as a reference anywhere in Salesforce.
Has anyone else run into this and can point me in the right direction? I just need to populate my code with a contact from the account that has ownership of the customer asset so we can send out notices to customers that a new product update is out, or that their maintenance contract is about to expire.
Contract Code:
public with sharing class CreateContract{
public void CreateContract(List<Customer_Asset__c> assets){
List<Contract> ContractsToCreate = new List<Contract>();
Map<String, String> signedcontact = new Map<String, String>();
signedcontact = [Select Id, contactid from AccountContactRole where isprimary=true];
for(Customer_Asset__c acc:assets){
if (acc.Support_Contract__c == true){
Contract ContractToAdd = new Contract();
ContractToAdd.Accountid = acc.Account__c;
ContractToAdd.StartDate = acc.DateShipped__c;
ContractToAdd.ContractTerm = 15;
ContractToAdd.Customer_Asset__c = acc.id;
ContractToAdd.CompanySignedId = acc.OwnerId;
ContractToAdd.CustomerSignedId = signedcontact;
ContractsToCreate.add(ContractToAdd);
}
}
if (ContractsToCreate.size() > 0)
insert ContractsToCreate;
}
}