• Apex code.ax1542
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

I am getting an error while saving a note as i want to change the Title of the Note with Body content upto 77 alphabhets.

 

Error-   INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call

 

Here is my code:-

trigger NotesTitleBeforeInsert on Note (after insert,after update){

List<Note> allTitles = new List<Note>();
if(trigger.isInsert || trigger.isUpdate){
for(Note nT: Trigger.new){
List<Note> ntList = [select ID,Title,Body,ParentId,Parent.Id from Note where Id =:nT.Id];
String titleValue;
for(Note n1 : ntList){
titleValue = n1.Title.substring(0, 6);
system.debug(titleValue);
Boolean TitleTest = Pattern.matches('[0-9]', titleValue);
//Pattern titlePattern = Pattern.Compile('[0-9]{10}');
//Matcher NoteTitle = titlePattern.matcher(n1.Title);
system.debug(TitleTest);

if(TitleTest == true){
n1.Title = n1.Body.substring(0, 76);
}
//update n1;
allTitles.add(n1);
}


}
}
if(allTitles.size() > 0 ){
insert allTitles ;
}
}

I am getting an error while saving a note as i want to change the Title of the Note with Body content upto 77 alphabhets.

 

Error-   INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call

 

Here is my code:-

trigger NotesTitleBeforeInsert on Note (after insert,after update){

List<Note> allTitles = new List<Note>();
if(trigger.isInsert || trigger.isUpdate){
for(Note nT: Trigger.new){
List<Note> ntList = [select ID,Title,Body,ParentId,Parent.Id from Note where Id =:nT.Id];
String titleValue;
for(Note n1 : ntList){
titleValue = n1.Title.substring(0, 6);
system.debug(titleValue);
Boolean TitleTest = Pattern.matches('[0-9]', titleValue);
//Pattern titlePattern = Pattern.Compile('[0-9]{10}');
//Matcher NoteTitle = titlePattern.matcher(n1.Title);
system.debug(TitleTest);

if(TitleTest == true){
n1.Title = n1.Body.substring(0, 76);
}
//update n1;
allTitles.add(n1);
}


}
}
if(allTitles.size() > 0 ){
insert allTitles ;
}
}

Hello,

I see a strange behavior with a Visualforce in my managed package:
1. There is a button on Opportunity that links to a VF page
2. When button is pressed the URL changes to:
https://myprefix.na6.visual.force.com/apex/mypage?scontrolCaching=1&id=0068000000O7yGb
3. VF page has a 'Save' button that has the following code:
PageReference myPage = new PageReference('/' + opportunityId);
myPage.setRedirect(true);                               
return myPage;

basically all it does is redirects a user to an Opportunity screen with the opportunityId.

BUT, when user is redirected to the Opportunity page the URL remains the same (and never changes no matter where you go):
https://myprefix.na6.visual.force.com/apex/mypage?scontrolCaching=1&id=0068000000O7yGb


Thanks,
Shamil