0
public void updateattendeecb() {
    System.debug(enteredText1);
    Id myId = Id.valueOf(enteredText1);
    list_attendees1=[Select id,Send_Email_for_Certificate__c from EM_Attendee_vod__c where id= :myId];
    //  list_attendees1=Database.query('Select Id, Send_Email_for_Certificate__c from EM_Attendee_vod__c where Id='+attendee_id);
    if(!list_attendees1[0].Send_Email_for_Certificate__c) {
        list_attendees1[0].Send_Email_for_Certificate__c=true;
        update list_attendees1;    
    }
}

So the line Id myId = Id.valueOf(enteredText1); is causing the above error.

I used system.debug(enteredText1) and it's showing correct id value in string. Now I am trying to convert to Id return type but getting the error. The variable enteredText1 is returning the correct value

07:40:24:023 USER_DEBUG [20]|DEBUG|a610V0000015C5DQAU. 

This id is fine but don't know the error here. Please help.

  • May be you can try by using first 15 characters. – Ysr Shk Aug 5 at 2:55
  • Is there whitespace, or other non-printing unicode characters at the end (or start?) of the string? – ca_peterson Aug 5 at 4:04
  • 1
    Agreed with @ca_peterson. Looks like there is a period at the end of the Id. I ran a system debug for an Id and there was no period at the end. – Zach Aug 6 at 19:56
0

This seems to work when attempted independnetly, using execute anonymous via the sfdx CLI for example:

>> Start typing Apex code. Press the Enter key after each line, 
>> then press CTRL+D when finished.
> String enteredText1 = 'a610V0000015C5DQAU';
Id myId = Id.valueOf(enteredText1);
> System.debug(myId);
Compiled successfully.
Executed successfully.

49.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO
Execute Anonymous: String enteredText1 = 'a610V0000015C5DQAU';
Execute Anonymous: Id myId = Id.valueOf(enteredText1);
Execute Anonymous: System.debug(myId);
21:05:55.41 (41527237)|USER_INFO|[EXTERNAL]|0059A000002vILv|test-brmv1q3myzqi@example.com|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00
21:05:55.41 (41562129)|EXECUTION_STARTED
21:05:55.41 (41570907)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
21:05:55.41 (42463391)|USER_DEBUG|[3]|DEBUG|a610V0000015C5DQAU
21:05:55.42 (42595094)|CUMULATIVE_LIMIT_USAGE
21:05:55.42 (42595094)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

21:05:55.42 (42595094)|CUMULATIVE_LIMIT_USAGE_END

21:05:55.41 (42676157)|CODE_UNIT_FINISHED|execute_anonymous_apex
21:05:55.41 (42688967)|EXECUTION_FINISHED

From that, I have to assume there is whitespace, or other non-printing characters in your enteredText variable. Can you check its length? use .trim() before you assign it to an ID?

| improve this answer | |

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.