• MGarg
  • NEWBIE
  • 0 Points
  • Member since 2009

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

I have created a custom clone button for cloning contacts.

 

When i click on the clone button it takes me to the edit page. Till this point everything is fine.

 

But even if i click on the cancel button, on the edit page, it creates the cloned contact.

 

It should only create the record on clicking the save button. Here is the code

 

public PageReference createContact(){

String errorMessage = '';

//if contact record type is Employee display error message

 if(sourceContact.RecordType.Name == EMPLOYEE){

errorMessage = ' Employee contacts cannot be cloned.'; ApexPages.addMessage(

new ApexPages.Message(ApexPages.Severity.ERROR, errorMessage));

}

//if contact record type is Contact create clone of the contact and return to the edit page of newly created contact

 else if(sourceContact.RecordType.Name == CONTACT){

Contact clonedContact = sourceContact.clone(false, true);

try{

insert clonedContact;}

catch(Exception ex){

errorMessage =' This contact can not be cloned. '+ex; ApexPages.addMessage(

new ApexPages.Message(ApexPages.Severity.ERROR, errorMessage));

}

PageReference pageRef = new PageReference('/' + clonedContact.Id+ '/e?retURL=%2F' + clonedContact.Id);

pageRef.setRedirect(true);

return pageRef;

}

//if page has error messages then display the messages

 if(ApexPages.hasMessages()){

showError=true;

showNoError=false;

return null;

}

return null;

}

  • January 14, 2010
  • Like
  • 0

Trish Perkins at FaithAction International House here, running the Nonprofit (Enterprise) Edition of SF.

 

I'd like to use the Excel Connector with my sandbox just to play with bulk data upload in the latest version of organizations (accounts) and contacts and converting leads to contacts. 

 

I put "test" before salesforce in the url. 

 

I logged in with my username and password. Nope. I added my security token. Nope. I tried backing out to start over and now I'm getting a whole rash of error messages. Could somebody just walk me through getting IN? 

 

Trish Perkins

pperkins@faihouse.org

336-379-0037