Whenever case is created I have to create a incident record as well, as per my requirement I have done the field mapping as shown in class.

Problem here is one of the incident object filed BMCServiceDesk__FKCategory__c This field has a lookup to category object, but the actual field I am trying to map from case object is Applications__c; this is a Picklist field.

The class saved successfully, but while running the class in debug log i am getting an error like:

System.StringException: Invalid id.

Case data coming from lightning controller.

Please find my controller code below and suggest me how to achieve this:

public class ctssupportform {

    public static List<Attachment> attachments;
    public static final Integer DEFAULT_ATTACHMENT_NO=1;
    public String sobjId {get; set;}

    public static id Savesupportform(Case casedata, String fileName, String base64Data, String contentType){

        insert Casedata; 

        base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
        System.debug('@@@@@@@@@@@@@@@@'+base64Data );
        //base64Data = 'Test';
        Attachment oAttachment = new Attachment();
        oAttachment.parentId = casedata.id;
        oAttachment.Body = EncodingUtil.base64Decode(base64Data);        
        oAttachment.Name = fileName;
        oAttachment.ContentType = contentType;
        insert oAttachment; 

        Attachment oAttachment1 = new Attachment();
        oAttachment1.parentId = casedata.id;
        oAttachment1.Body = EncodingUtil.base64Decode(base64Data);        
        oAttachment1.Name = fileName;
        oAttachment1.ContentType = contentType;
        oAttachment1.parentId = casedata.id;
        insert oAttachment1; 

        BMCServiceDesk__Incident__c inc = new BMCServiceDesk__Incident__c();
        inc.Cases__c = casedata.id;
        inc.BMCServiceDesk__incidentDescription__c = casedata.Type_Of_Ticket__c;
        inc.BMCServiceDesk__FKCategory__c = casedata.Applications__c; // Problem with this filed
        inc.BMCServiceDesk__Service_Request_Title__c = casedata.Subject;
        inc.BMCServiceDesk__FKImpact__c = casedata.Impact__c;
        inc.BMCServiceDesk__FKUrgency__c= casedata.Urgency__c;
        inc.BMCServiceDesk__incidentDescription__c= casedata.Description ;
        inc.BMCServiceDesk__incidentDescription__c= casedata.Justification__c ;
        insert inc;

        return casedata.id;


1 Answer 1


This field mapping does not make sense in the way you've executed it. As the error indicates, you cannot populate an arbitrary string in an Id field (which is what a lookup field really is).

If the Picklist field values actually correspond to records of your Category object, you would need to perform a query for the Category record first, and use its Id to populate the lookup field.

It's not clear from your description whether or not the above is the case, however. You may need to go back to whomever provided you with this assignment and have it clarified.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .