• Gaby Frydman
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies
Hi, 

Out of the blue, all our forms that collect contact's data stopped working - we checked field level permissions, account role and hierchy sharing, sharing rules, profile permissions and it all seems to give access.

We get one of two errors - either "We are down for maintenance. Sorry for the inconvenience. We'll be back shortly." when submitting this form: https://js-staffing-1480f8a2526-14ab9e6033e.secure.force.com/careers/ContactDetails?id=0032400000DcQAo 

Or just a cpu timeout on this one: http://js-staffing-1480f8a2526-14ab9e6033e.force.com/candidates/jsforms__forminclude?formId=a1R240000003l4eEAA&ContactId=00324000008KOq4&idDetails=00324000008KOq4

Forms on any other object work fine. Debug log does not help at all - when the Save function is called it crashes (for the first error type) and debug does not show anything unusual for the second form.

Both of these forms worked fine a week a go, and apart from instaling Conga and maybe creating a few custom objects, nothing much has changed.

Whats more bizzare is that we also get the error "Error: Request Entity Too Large: head" 

Any idea where to start looking?
 
Ok, so in sandbox, I have a trigger on an object called Exam - so if an exam is updated to "Fail" then I want to create a new examination record that replicates the original one but also marks it as a resit. 

My trigger works fine in Sandbox  but in Production I get 2 extra records instead of 1 extra record. 

I dont have any other triggers on the same objects and the Debug console isnt very helpful either. 

Any idea how to troubleshoot?
Hi All, 

I am trying to obtain all attachments from a Contact that has a record on  Application__c which belongs to an object called Job__c.

The Application__c is in many-to-many (lookup) with Contact and master-detail with Job__c

The idea is that If I have the Id of the Job__c, to loop over it's applicaitons and obtain the attachemnts from the contact 

I have currently the following code which does the job if i have the contact id :
 
Id jobId = 'a0K24000000QneY';

list<Attachment> attachments = 
    [SELECT Id, Name, Body, ContentType FROM Attachment 
     WHERE ParentId IN
		(SELECT Id from Contact WHERE id =: jobId)];

				
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'secret@secret.com'};
email.setToAddresses(toAddresses);
email.setSubject('Foo');
email.setPlainTextBody('Bar');

List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
for(Attachment att : attachments) {

    Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
    efa.setFileName(att.Name);
    efa.setBody(att.Body);
    efa.setContentType(att.ContentType);
    emailAttachments.add(efa);
}

email.setFileAttachments(emailAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

Since I cannot have more than one level query in child-parent relationship, what can do the job?
Hi All, 

I currently have a controller that logs people in  via their NIN and DOB. It works great, however I am expanding the functionality by adding multiple states with different forms.

My current code looks like that:
public without sharing class LearnerDetails_Controller {
    public Contact contact {get;set;}
    public Contact editContact {get;set;}
    public Integer state {get;set;}

    public LearnerDetails_Controller() {
        contact = new Contact(Id = null);
        editContact = null;
        state = 0;
    }
    
    public void loadContact() {
        try {
            //Verify NI number and birthday are available
            if (contact.National_Insurance__c == null
             || contact.BirthDate == null)
                 throw new PageException('Please enter your national insurance number and birth date.');
                 
            //Load contact
            List<Contact> contacts = [SELECT id, firstName, lastName, Nationality__c, ID_Issue_Date__c, Document_of_Identification__c, ts2__Mobile_Telephone_Number__c, Email, MailingAddress, MailingStreet, MailingCountry, MailingCity, MailingPostalCode, MobilePhone, Sex__c, ID_Expires__c, ID_Number__c, ID_Visa_Comments__c, Visa_Type__c, Visa_Expires__c, Marital_Status_use__c, Programme__c, Adviser__c, Adviser_s_Location_Portal__c, Adviser_s_Name_Portal__c, Benefit_Type__c, Disability__c, Ethnicity__c, CRB_conflict__c, Qualify_for_free_training__c, Name, General_Comments__c, ILP_Signed__c, F2L_Agreement__c, Years_in_UK__c, Start_Being_Learner__c
                                      FROM Contact 
                                      WHERE National_Insurance__c like :contact.National_Insurance__c
                                        AND BirthDate = :contact.BirthDate
                                      ORDER BY CreatedDate DESC
                                      LIMIT 1];
                                        
            if (contacts.size() == 0) {
                throw new PageException('We\'re sorry, but we could not find any applicant with the details you have entered.');
            }
            
            this.contact = contacts.get(0);
            this.editContact = contacts.get(0).clone();
            this.editContact.Id = null;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    
    public void doSave() {
        try {
            if (editContact == null) {
                throw new PageException('Please log in first.');
            }
            editContact.Id = contact.Id;
            
            update editContact;
            editContact.Id = null;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Your details have been successfully saved.'));
            nextState();
        } catch (DMLException e) {
            editContact.Id = null;
            ApexPages.Message msg = new ApexPages.Message(Apexpages.Severity.ERROR, e.getdmlMessage(0) );
            ApexPages.addMessage(msg);
        }
    }

  public void nextState() {
    state++;
  }
    
    public class PageException extends Exception {}
}

And I want to add ILP__c, Agreement__c and VAK_ Questinnaire__c to the controller.
public without sharing class LearnerDetails_Controller {
    public Contact contact {get;set;}
    public Contact editContact {get;set;}
    public Integer state {get;set;}
    public LearnerDetails_Controller() {
    contact = new Contact(Id = null);
    editContact = null;
    state = 0;
}
public class loadForms{
    public List<ILP__c> editILP {get;set;}
    public List<F2L_Agreement__c> editAgreement {get;set;}
    public List<VAK_Questionnaire__c> editVAK {get;set;}


    
    public void loadContact() {
        try {
            //Verify NI number and birthday are available
            if (contact.National_Insurance__c == null
             || contact.BirthDate == null)
                 throw new PageException('Please enter your national insurance number and birth date.');
                 
            //Load contact
            List<Contact> contacts = [SELECT id, firstName, lastName, Nationality__c, ID_Issue_Date__c, Document_of_Identification__c, ts2__Mobile_Telephone_Number__c, Email, MailingAddress, MailingStreet, MailingCountry, MailingCity, MailingPostalCode, MobilePhone, Sex__c, ID_Expires__c, ID_Number__c, ID_Visa_Comments__c, Visa_Type__c, Visa_Expires__c, Marital_Status_use__c, Programme__c, Adviser__c, Adviser_s_Location_Portal__c, Adviser_s_Name_Portal__c, Benefit_Type__c, Disability__c, Ethnicity__c, CRB_conflict__c, Qualify_for_free_training__c, Name, General_Comments__c, ILP_Signed__c, F2L_Agreement__c, Years_in_UK__c, Start_Being_Learner__c
                                      FROM Contact 
                                      WHERE National_Insurance__c like :contact.National_Insurance__c
                                        AND BirthDate = :contact.BirthDate
                                      ORDER BY CreatedDate DESC
                                      LIMIT 1];
                                        
            if (contacts.size() == 0) {
                throw new PageException('We\'re sorry, but we could not find any applicant with the details you have entered.');
            }
            
            this.contact = contacts.get(0);
            this.editContact = contacts.get(0).clone();
            this.editContact.Id = null;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    
    private void loadForms() {
        // Load ILP
        Id contactId = this.contact.Id;
        List<ILP__c> frmILP = [SELECT Id, Additional_Learning_Support__c, Additional_Learning_Support_Comment__c, Agree_to_ILP__c, Any_planned_actions__c, Attended_an_Induction__c, Completed_enrolment_PW__c, Contact__c, Customer_Service_Skills__c, Date_Signed__c, Employ_ability_Skills__c, Employment_Goals_Comment__c, Experience_and_Knowledge__c, Formal_Training__c, Formal_Training_Comment__c, Further_information_and_advice__c, Improve_confidence__c, Information_and_Advice__c, Need_Relevant_Knowledge__c, Practical_Exp__c, Practical_Exp_Comment__c, Received_Copies__c, Where_Programme_Delivery__c, Who_my_advisor_is__c,Why_this_course__c FROM ILP__c WHERE Contact__c = :contactId ORDER BY CreatedDate DESC LIMIT 1];
        if (frmILP.size() > 0)
            editILP = frmILP.get(0);
        else
            editILP = new ILP__c(Contact__c = ContactId);
        // Load Agreement (if any)
       
        List<F2L_Agreement__c> frmAgreement = [SELECT Id, Name FROM ILP__c WHERE Contact__c = :contactId ORDER BY CreatedDate DESC LIMIT 1];
        if (frmAgreement.size() > 0)
            editAgreement = frmAgreement.get(0);
        else
            editAgreement = new F2L_Agreement__c(Contact__c = ContactId);
        // Load VAK
        
        List<VAK_Questionnaire__c> frmVAK = [SELECT Id, q9__c, q8__c, q7__c, q6__c, q5__c, q4__c, q30__c, q3__c, q29__c, q28__c, q27__c, q26__c, q25__c, q24__c, q23__c, q22__c, q21__c, q20__c, q2__c, q19__c, q18__c, q17__c, q16__c, q15__c, q14__c, q13__c, q12__c, q11__c, q10__c, q1__c  FROM VAK_Questionnaire__c WHERE Contact__c = :contactId ORDER BY CreatedDate DESC LIMIT 1];
        if (frmVAK.size() > 0)
            editVAK = frmVAK.get(0);
        else
            editVAK = new VAK_Questionnaire__c(Contact__c = ContactId);
        
    }
}
    
    
    public void doSave() {
        try {
            if (editContact == null) {
                throw new PageException('Please log in first.');
            }
            editContact.Id = contact.Id;
            
            update editContact;
            editContact.Id = null;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Your details have been successfully saved.'));
            nextState();
        } catch (DMLException e) {
            editContact.Id = null;
            ApexPages.Message msg = new ApexPages.Message(Apexpages.Severity.ERROR, e.getdmlMessage(0) );
            ApexPages.addMessage(msg);
        }
    }

  public void nextState() {
    state++;
  }
    
    public class PageException extends Exception {}
}

But I get the following error:" Invalid bind expression type of Schema.SObjectField for column of type String at line 27 column 73 "

Have I not defined the variables correctly? Am I missing something? Cant get my head around it..
 
Hi All, 

I have a rather neat controller with a visual force page that is called on button press to collect a signature. The end result is a file called "Signature.png" and is attached to the Notes and Attachments section on the contact object.

My question is: How can I have a visualforce page within the contact layout which would display the signature picture?

Reason is : to create a pdf of the contact page with their signature at the bottom

Currently my Controlelr for creating the signature attachment:
public with sharing class ehsSignatureExtensionController {

private final Contact ehs;

public ehsSignatureExtensionController(ApexPages.StandardController controller) {
    ehs = (Contact)controller.getRecord();
}

@RemoteAction public static RemoteSaveResult saveSignature(Id ehsId, String signatureBody) {
    Attachment a = new Attachment(ParentId=ehsId, name='Signature.png', ContentType='image/png', Body=EncodingUtil.base64Decode(signatureBody));
    Database.saveResult result = Database.insert(a,false);
    RemoteSaveResult newResult = new RemoteSaveResult();
    newResult.success = result.isSuccess();
    newResult.attachmentId = a.Id;
    newResult.errorMessage = result.isSuccess()?'':result.getErrors()[0].getMessage();
    return newResult;
}

public class RemoteSaveResult {
    public Boolean success;
    public Id attachmentId;
    public String errorMessage;
}

public pageReference cancel(){
    pageReference page = new PageReference('/'+ehs.id);
    page.setRedirect(true);
    return page;
}
}

My VF Page:
<apex:page docType="html-5.0" standardController="Contact" extensions="ehsSignatureExtensionController" sidebar="false" showHeader="false">

<script>var $j = jQuery.noConflict();</script>
<apex:stylesheet value="{!URLFOR($Resource.jquerymobile,'/jquerymobile/jquery.mobile-1.3.2.min.css')}"/>

<apex:includeScript value="{!URLFOR($Resource.jquerymobile,'/jquerymobile/jquery.mobile-1.3.2.min.js')}"/>

<canvas id="signatureCanvas" width="400" height="250" style="border: 1px solid black;"/>  
<apex:includeScript value="/soap/ajax/28.0/connection.js"/>

<script>

sforce.connection.sessionId = "{!$Api.Session_Id}";
var canvas = document.getElementById("signatureCanvas");
var context = canvas.getContext("2d");
var mouseButton = 0;
var lastX = lastY = null;
var ehsId = '{!Contact.Id}';

function saveSignature() {

    var image = canvas.toDataURL().split(',')[1];
    ehsSignatureExtensionController.saveSignature(ehsId,image,handleResult);
}

function handleResult(result,event) {
    if(result.success) {
        window.top.location.href='/'+ehsId;
    } else {
        alert('Error: '+result.errorMessage);
    }
}

function handleEvent(event) {
    if(event.type==="mousedown"||event.type==="touchstart") {
        mouseButton = event.which || 1;
        lastX = lastY = null;
    }
    if(event.type==="touchcancel" || event.type==="touchcancel" || event.type==="mouseup") {
        mouseButton = 0;
        lastX = lastY = null;
    }
    if((event.type==="touchmove" || event.type==="mousemove") && mouseButton) {
        var newX, newY;
        var canvasX = 0, canvasY = 0, obj = event.srcElement || event.target;
        do {
            canvasX += obj.offsetLeft;
            canvasY += obj.offsetTop;
        } while(obj = obj.offsetParent);
        if(event.targetTouches && event.targetTouches.length) {
            newX = event.targetTouches[0].clientX - (canvasX/2);
            newY = event.targetTouches[0].clientY - (canvasY/2);
        } else {
            newX = event.offsetX;
            newY = event.offsetY;
        }
        if(!lastX && !lastY) {
            lastX = newX;
            lastY = newY;
            context.beginPath();
            context.moveTo(lastX,lastY);
            context.lineTo(lastX,lastY,lastX,lastY);
            context.stroke();
        } else {
            context.beginPath();
            context.moveTo(lastX,lastY);
            context.lineTo(newX,newY);
            context.stroke();
            lastX = newX;
            lastY = newY;
        }
    }
    if(event.type=="touchmove" || event.type==="mousedrag" || (event.type==="selectstart" && (event.srcElement||event.target)===canvas)) {
        event.returnValue=false;
        event.stopPropagation();
        event.preventDefault();
        return false;
    }
}

canvas.addEventListener("mousedrag",handleEvent,true);
canvas.addEventListener("mousemove",handleEvent,true);
canvas.addEventListener("mousedown",handleEvent,true);
window.addEventListener("mouseup",handleEvent,true);
canvas.addEventListener("touchstart",handleEvent,true);
canvas.addEventListener("touchmove",handleEvent,true);
window.addEventListener("touchend",handleEvent,true);
window.addEventListener("selectstart",handleEvent,true);

</script>

<apex:form >
    <apex:commandButton value="Save Signature" onclick="saveSignature();return false;" styleClass="button"/>
    <apex:commandButton action="{!cancel}" value="Exit"/>
</apex:form>

</apex:page>

My button on the contact page:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

var id = '{!Contact.Id}'; 
var url = "/apex/Signature?id=" + id + '&src=page'; 
var features = 'directories=no,menubar=no,titlebar=no,toolbar=no,width=450,height=460'; 
win = window.open(url,'', features); 
win.focus();

I am using JQuery Mobile standard library. 
Hi all, 

I am meeting some interesting challenges which I can't seem to figure out:

I have a site which is running a visualforce page that collects customer details. Customers can log in with their Customer Number and Date of Birth before being taken to completing a form of fields.

Problem is that when a conflict with validation rules occures, the page becomes read-only and the customer needs to refresh the page and no changes would be saved.

Any workarounds?
Ok, so in sandbox, I have a trigger on an object called Exam - so if an exam is updated to "Fail" then I want to create a new examination record that replicates the original one but also marks it as a resit. 

My trigger works fine in Sandbox  but in Production I get 2 extra records instead of 1 extra record. 

I dont have any other triggers on the same objects and the Debug console isnt very helpful either. 

Any idea how to troubleshoot?
Hi All, 

I am trying to obtain all attachments from a Contact that has a record on  Application__c which belongs to an object called Job__c.

The Application__c is in many-to-many (lookup) with Contact and master-detail with Job__c

The idea is that If I have the Id of the Job__c, to loop over it's applicaitons and obtain the attachemnts from the contact 

I have currently the following code which does the job if i have the contact id :
 
Id jobId = 'a0K24000000QneY';

list<Attachment> attachments = 
    [SELECT Id, Name, Body, ContentType FROM Attachment 
     WHERE ParentId IN
		(SELECT Id from Contact WHERE id =: jobId)];

				
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'secret@secret.com'};
email.setToAddresses(toAddresses);
email.setSubject('Foo');
email.setPlainTextBody('Bar');

List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
for(Attachment att : attachments) {

    Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
    efa.setFileName(att.Name);
    efa.setBody(att.Body);
    efa.setContentType(att.ContentType);
    emailAttachments.add(efa);
}

email.setFileAttachments(emailAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

Since I cannot have more than one level query in child-parent relationship, what can do the job?
Hi All, 

I currently have a controller that logs people in  via their NIN and DOB. It works great, however I am expanding the functionality by adding multiple states with different forms.

My current code looks like that:
public without sharing class LearnerDetails_Controller {
    public Contact contact {get;set;}
    public Contact editContact {get;set;}
    public Integer state {get;set;}

    public LearnerDetails_Controller() {
        contact = new Contact(Id = null);
        editContact = null;
        state = 0;
    }
    
    public void loadContact() {
        try {
            //Verify NI number and birthday are available
            if (contact.National_Insurance__c == null
             || contact.BirthDate == null)
                 throw new PageException('Please enter your national insurance number and birth date.');
                 
            //Load contact
            List<Contact> contacts = [SELECT id, firstName, lastName, Nationality__c, ID_Issue_Date__c, Document_of_Identification__c, ts2__Mobile_Telephone_Number__c, Email, MailingAddress, MailingStreet, MailingCountry, MailingCity, MailingPostalCode, MobilePhone, Sex__c, ID_Expires__c, ID_Number__c, ID_Visa_Comments__c, Visa_Type__c, Visa_Expires__c, Marital_Status_use__c, Programme__c, Adviser__c, Adviser_s_Location_Portal__c, Adviser_s_Name_Portal__c, Benefit_Type__c, Disability__c, Ethnicity__c, CRB_conflict__c, Qualify_for_free_training__c, Name, General_Comments__c, ILP_Signed__c, F2L_Agreement__c, Years_in_UK__c, Start_Being_Learner__c
                                      FROM Contact 
                                      WHERE National_Insurance__c like :contact.National_Insurance__c
                                        AND BirthDate = :contact.BirthDate
                                      ORDER BY CreatedDate DESC
                                      LIMIT 1];
                                        
            if (contacts.size() == 0) {
                throw new PageException('We\'re sorry, but we could not find any applicant with the details you have entered.');
            }
            
            this.contact = contacts.get(0);
            this.editContact = contacts.get(0).clone();
            this.editContact.Id = null;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    
    public void doSave() {
        try {
            if (editContact == null) {
                throw new PageException('Please log in first.');
            }
            editContact.Id = contact.Id;
            
            update editContact;
            editContact.Id = null;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Your details have been successfully saved.'));
            nextState();
        } catch (DMLException e) {
            editContact.Id = null;
            ApexPages.Message msg = new ApexPages.Message(Apexpages.Severity.ERROR, e.getdmlMessage(0) );
            ApexPages.addMessage(msg);
        }
    }

  public void nextState() {
    state++;
  }
    
    public class PageException extends Exception {}
}

And I want to add ILP__c, Agreement__c and VAK_ Questinnaire__c to the controller.
public without sharing class LearnerDetails_Controller {
    public Contact contact {get;set;}
    public Contact editContact {get;set;}
    public Integer state {get;set;}
    public LearnerDetails_Controller() {
    contact = new Contact(Id = null);
    editContact = null;
    state = 0;
}
public class loadForms{
    public List<ILP__c> editILP {get;set;}
    public List<F2L_Agreement__c> editAgreement {get;set;}
    public List<VAK_Questionnaire__c> editVAK {get;set;}


    
    public void loadContact() {
        try {
            //Verify NI number and birthday are available
            if (contact.National_Insurance__c == null
             || contact.BirthDate == null)
                 throw new PageException('Please enter your national insurance number and birth date.');
                 
            //Load contact
            List<Contact> contacts = [SELECT id, firstName, lastName, Nationality__c, ID_Issue_Date__c, Document_of_Identification__c, ts2__Mobile_Telephone_Number__c, Email, MailingAddress, MailingStreet, MailingCountry, MailingCity, MailingPostalCode, MobilePhone, Sex__c, ID_Expires__c, ID_Number__c, ID_Visa_Comments__c, Visa_Type__c, Visa_Expires__c, Marital_Status_use__c, Programme__c, Adviser__c, Adviser_s_Location_Portal__c, Adviser_s_Name_Portal__c, Benefit_Type__c, Disability__c, Ethnicity__c, CRB_conflict__c, Qualify_for_free_training__c, Name, General_Comments__c, ILP_Signed__c, F2L_Agreement__c, Years_in_UK__c, Start_Being_Learner__c
                                      FROM Contact 
                                      WHERE National_Insurance__c like :contact.National_Insurance__c
                                        AND BirthDate = :contact.BirthDate
                                      ORDER BY CreatedDate DESC
                                      LIMIT 1];
                                        
            if (contacts.size() == 0) {
                throw new PageException('We\'re sorry, but we could not find any applicant with the details you have entered.');
            }
            
            this.contact = contacts.get(0);
            this.editContact = contacts.get(0).clone();
            this.editContact.Id = null;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    
    private void loadForms() {
        // Load ILP
        Id contactId = this.contact.Id;
        List<ILP__c> frmILP = [SELECT Id, Additional_Learning_Support__c, Additional_Learning_Support_Comment__c, Agree_to_ILP__c, Any_planned_actions__c, Attended_an_Induction__c, Completed_enrolment_PW__c, Contact__c, Customer_Service_Skills__c, Date_Signed__c, Employ_ability_Skills__c, Employment_Goals_Comment__c, Experience_and_Knowledge__c, Formal_Training__c, Formal_Training_Comment__c, Further_information_and_advice__c, Improve_confidence__c, Information_and_Advice__c, Need_Relevant_Knowledge__c, Practical_Exp__c, Practical_Exp_Comment__c, Received_Copies__c, Where_Programme_Delivery__c, Who_my_advisor_is__c,Why_this_course__c FROM ILP__c WHERE Contact__c = :contactId ORDER BY CreatedDate DESC LIMIT 1];
        if (frmILP.size() > 0)
            editILP = frmILP.get(0);
        else
            editILP = new ILP__c(Contact__c = ContactId);
        // Load Agreement (if any)
       
        List<F2L_Agreement__c> frmAgreement = [SELECT Id, Name FROM ILP__c WHERE Contact__c = :contactId ORDER BY CreatedDate DESC LIMIT 1];
        if (frmAgreement.size() > 0)
            editAgreement = frmAgreement.get(0);
        else
            editAgreement = new F2L_Agreement__c(Contact__c = ContactId);
        // Load VAK
        
        List<VAK_Questionnaire__c> frmVAK = [SELECT Id, q9__c, q8__c, q7__c, q6__c, q5__c, q4__c, q30__c, q3__c, q29__c, q28__c, q27__c, q26__c, q25__c, q24__c, q23__c, q22__c, q21__c, q20__c, q2__c, q19__c, q18__c, q17__c, q16__c, q15__c, q14__c, q13__c, q12__c, q11__c, q10__c, q1__c  FROM VAK_Questionnaire__c WHERE Contact__c = :contactId ORDER BY CreatedDate DESC LIMIT 1];
        if (frmVAK.size() > 0)
            editVAK = frmVAK.get(0);
        else
            editVAK = new VAK_Questionnaire__c(Contact__c = ContactId);
        
    }
}
    
    
    public void doSave() {
        try {
            if (editContact == null) {
                throw new PageException('Please log in first.');
            }
            editContact.Id = contact.Id;
            
            update editContact;
            editContact.Id = null;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Your details have been successfully saved.'));
            nextState();
        } catch (DMLException e) {
            editContact.Id = null;
            ApexPages.Message msg = new ApexPages.Message(Apexpages.Severity.ERROR, e.getdmlMessage(0) );
            ApexPages.addMessage(msg);
        }
    }

  public void nextState() {
    state++;
  }
    
    public class PageException extends Exception {}
}

But I get the following error:" Invalid bind expression type of Schema.SObjectField for column of type String at line 27 column 73 "

Have I not defined the variables correctly? Am I missing something? Cant get my head around it..
 
Hi All, 

I have a rather neat controller with a visual force page that is called on button press to collect a signature. The end result is a file called "Signature.png" and is attached to the Notes and Attachments section on the contact object.

My question is: How can I have a visualforce page within the contact layout which would display the signature picture?

Reason is : to create a pdf of the contact page with their signature at the bottom

Currently my Controlelr for creating the signature attachment:
public with sharing class ehsSignatureExtensionController {

private final Contact ehs;

public ehsSignatureExtensionController(ApexPages.StandardController controller) {
    ehs = (Contact)controller.getRecord();
}

@RemoteAction public static RemoteSaveResult saveSignature(Id ehsId, String signatureBody) {
    Attachment a = new Attachment(ParentId=ehsId, name='Signature.png', ContentType='image/png', Body=EncodingUtil.base64Decode(signatureBody));
    Database.saveResult result = Database.insert(a,false);
    RemoteSaveResult newResult = new RemoteSaveResult();
    newResult.success = result.isSuccess();
    newResult.attachmentId = a.Id;
    newResult.errorMessage = result.isSuccess()?'':result.getErrors()[0].getMessage();
    return newResult;
}

public class RemoteSaveResult {
    public Boolean success;
    public Id attachmentId;
    public String errorMessage;
}

public pageReference cancel(){
    pageReference page = new PageReference('/'+ehs.id);
    page.setRedirect(true);
    return page;
}
}

My VF Page:
<apex:page docType="html-5.0" standardController="Contact" extensions="ehsSignatureExtensionController" sidebar="false" showHeader="false">

<script>var $j = jQuery.noConflict();</script>
<apex:stylesheet value="{!URLFOR($Resource.jquerymobile,'/jquerymobile/jquery.mobile-1.3.2.min.css')}"/>

<apex:includeScript value="{!URLFOR($Resource.jquerymobile,'/jquerymobile/jquery.mobile-1.3.2.min.js')}"/>

<canvas id="signatureCanvas" width="400" height="250" style="border: 1px solid black;"/>  
<apex:includeScript value="/soap/ajax/28.0/connection.js"/>

<script>

sforce.connection.sessionId = "{!$Api.Session_Id}";
var canvas = document.getElementById("signatureCanvas");
var context = canvas.getContext("2d");
var mouseButton = 0;
var lastX = lastY = null;
var ehsId = '{!Contact.Id}';

function saveSignature() {

    var image = canvas.toDataURL().split(',')[1];
    ehsSignatureExtensionController.saveSignature(ehsId,image,handleResult);
}

function handleResult(result,event) {
    if(result.success) {
        window.top.location.href='/'+ehsId;
    } else {
        alert('Error: '+result.errorMessage);
    }
}

function handleEvent(event) {
    if(event.type==="mousedown"||event.type==="touchstart") {
        mouseButton = event.which || 1;
        lastX = lastY = null;
    }
    if(event.type==="touchcancel" || event.type==="touchcancel" || event.type==="mouseup") {
        mouseButton = 0;
        lastX = lastY = null;
    }
    if((event.type==="touchmove" || event.type==="mousemove") && mouseButton) {
        var newX, newY;
        var canvasX = 0, canvasY = 0, obj = event.srcElement || event.target;
        do {
            canvasX += obj.offsetLeft;
            canvasY += obj.offsetTop;
        } while(obj = obj.offsetParent);
        if(event.targetTouches && event.targetTouches.length) {
            newX = event.targetTouches[0].clientX - (canvasX/2);
            newY = event.targetTouches[0].clientY - (canvasY/2);
        } else {
            newX = event.offsetX;
            newY = event.offsetY;
        }
        if(!lastX && !lastY) {
            lastX = newX;
            lastY = newY;
            context.beginPath();
            context.moveTo(lastX,lastY);
            context.lineTo(lastX,lastY,lastX,lastY);
            context.stroke();
        } else {
            context.beginPath();
            context.moveTo(lastX,lastY);
            context.lineTo(newX,newY);
            context.stroke();
            lastX = newX;
            lastY = newY;
        }
    }
    if(event.type=="touchmove" || event.type==="mousedrag" || (event.type==="selectstart" && (event.srcElement||event.target)===canvas)) {
        event.returnValue=false;
        event.stopPropagation();
        event.preventDefault();
        return false;
    }
}

canvas.addEventListener("mousedrag",handleEvent,true);
canvas.addEventListener("mousemove",handleEvent,true);
canvas.addEventListener("mousedown",handleEvent,true);
window.addEventListener("mouseup",handleEvent,true);
canvas.addEventListener("touchstart",handleEvent,true);
canvas.addEventListener("touchmove",handleEvent,true);
window.addEventListener("touchend",handleEvent,true);
window.addEventListener("selectstart",handleEvent,true);

</script>

<apex:form >
    <apex:commandButton value="Save Signature" onclick="saveSignature();return false;" styleClass="button"/>
    <apex:commandButton action="{!cancel}" value="Exit"/>
</apex:form>

</apex:page>

My button on the contact page:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

var id = '{!Contact.Id}'; 
var url = "/apex/Signature?id=" + id + '&src=page'; 
var features = 'directories=no,menubar=no,titlebar=no,toolbar=no,width=450,height=460'; 
win = window.open(url,'', features); 
win.focus();

I am using JQuery Mobile standard library. 
Hi all, 

I am meeting some interesting challenges which I can't seem to figure out:

I have a site which is running a visualforce page that collects customer details. Customers can log in with their Customer Number and Date of Birth before being taken to completing a form of fields.

Problem is that when a conflict with validation rules occures, the page becomes read-only and the customer needs to refresh the page and no changes would be saved.

Any workarounds?