You need to sign in to do that
Don't have an account?
Invalid initial type LIST<Student_Lookup__c> for MAP<String,id>
What I'm attempting to do here is replicate data from the Contact, Account and Contract objects into a custom object called Student_Lookup__c. The application is for a franchise that has multiple schools and they have security on the accounts that prevent one franchise from seeing another frachises students however, a student can attend class at another franchises location when traveling. This requires the franchises to be able to see limited information about the student to know if they have an active contract.
I thought what I'd do is run a nightly job that updates the Student_Lookup__c with the relevant information from the Contact, Account, and Contract objects. Basically duplicating the data. I'm not convinced I'm doing this the easiest way so I'm open to ideas. However this is what I have so far but I'm receiving the above error on my Map statement.
public with sharing class clsRefreshStudentLookup { public void Refresh() { // Create Variable to update all the updates List<Student_Lookup__c> SL = New List<Student_Lookup__c>(); // Set Today's Date Date dExpDate = date.today(); // Gather Student_Lookup__c ID's to add to the data set below Map<String, ID> SList = new Map<String, ID>([Select ContractId__c, ID from Student_Lookup__c where ContractId__c <> '']); // Query for Student with active Contracts for (Contract[] Stud : [Select c.AccountId, c.Id, c.OwnerId, c.Program__r.Name, c.Program__r.School__c, c.StartDate, c.EndDate, c.Student__c, c.Student__r.Student_ID__c, c.Student__r.FirstName, c.Student__r.LastName, c.Student__r.Birthdate, c.Student__r.EC_Name__c, c.Student__r.EC_Other_Phone__c, c.Student__r.EC_Phone__c, c.Student__r.EC_Relationship__c from Contract c where c.EndDate >= :dExpDate]) { for (Contract c : Stud ) { ID SLid = SList.get(c.id); // Update Student_Lookup__c Student_Lookup__c SLUpdate = New Student_Lookup__c ( ID = SLid, ContractId__c=c.Id, OwnerId=c.OwnerId, Program_Name__c=c.Program__r.Name, Contract_StartDate__c=c.StartDate, Contract_EndDate__c=c.EndDate, Student_ContactID__c=c.Student__c, Student_ID__c=c.Student__r.Student_ID__c, First_Name__c=c.Student__r.FirstName, Last_Name__c=c.Student__r.LastName, Birthdate__c=c.Student__r.Birthdate, EC_Name__c=c.Student__r.EC_Name__c, EC_Other_Phone__c=c.Student__r.EC_Other_Phone__c, EC_Phone__c=c.Student__r.EC_Phone__c, EC_Relationship__c=c.Student__r.EC_Relationship__c, School_AccountID__c=c.AccountID); SL.add(SLUpdate); } } upsert SL; } }
You can't use the Map<T,U> constructor that takes a List<U>, unless T is the data type of ID, and U is an SObject. That means that you can do this:
In this context, you can find a ContractId__c by using the key of a Student_Lookup__c.Id.
To make the map in the manner you are attempting to do, you would have to use the usual for-each loop:
I assume that this is your use case based on your code example. Note that Id, Id is the most appropriate here, since ContractId__c is obviously an ID value.
All Answers
You can't use the Map<T,U> constructor that takes a List<U>, unless T is the data type of ID, and U is an SObject. That means that you can do this:
In this context, you can find a ContractId__c by using the key of a Student_Lookup__c.Id.
To make the map in the manner you are attempting to do, you would have to use the usual for-each loop:
I assume that this is your use case based on your code example. Note that Id, Id is the most appropriate here, since ContractId__c is obviously an ID value.
That makes sense and it works perfectly. Thank you!