I am trying to create an easy way to mark attendance. I have a custom object "students" as well as a custom object "attendance." The attendance object is related to the student object by a lookup field (student ID).

I would like to use the list view of my student object to select each student present. Then use a button to create an attendance object record for each student selected and have it related to each student by the lookup field.

I am able to get the button to create an attendance object record for each student selected, but it will not populate the Student Id look up field.


Not tested, but something like this should work

    var url = parent.location.href;       
    var records = {!GETRECORDIDS($ObjectType.Student__c)}; 
    var newRecords = [];  

    if (records[0] == null) { 
        alert("Please select at least one record to update.");     
    } else { 
        for (var a=0; a<records.length; a++) {              
            var newAttendance = new sforce.SObject("Attendance__c");
            newAttendance.Student__c = records[a]; 
        result = sforce.connection.insert(newRecords); 
        parent.location.href = url; //refresh the page 

result = sforce.connection.insert(newRecords);

here it should be like this

result = sforce.connection.create(newRecords);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.