You need to sign in to do that
Don't have an account?
Error in my code
Hi, anybody can help me why I have an error in my code at line 5
On the line: if(Profile.ID = '001i00000p80k') I have this error
public class ContactController { Profile PROFILE = [SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId()]; if(Profile.ID == '00e1i000000p80k') { u.addError('You are not allowed to create contact from this button'); } Else { public PageReference saveNew() { try { insert Contact; } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } return (new ApexPages.StandardController(new Contact())).edit(); } } }
On the line: if(Profile.ID = '001i00000p80k') I have this error
Expecting '}' but was: 'if'
Try the below
public class ContactController {
public PageReference saveNew() {
Profile PROFILE = [SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId()];
if(Profile.ID == '00e1i000000p80k') {
//u.addError('You are not allowed to create contact from this button');
return null;
}
Else {
try {
//insert Contact;
} catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
return (new ApexPages.StandardController(new Contact())).edit();
}
}
}
--
Magulan Duraipandian
www.infallibletechie.com
Thanks it works.
I have one more question... it is not related to the question before, maybe you can help me :)
Do you know how can I override the 'New' button from Contacts with a visualforce page? I don't want all the users to have access to this button only certains profiles. For example users with profile == 'ServiceMAX' are not allow to create contacts using this button, only users with profile == 'Sales'. So technically what I need is to maintain the standard functionality of the button but if the profile =='ServiceMax' then an error message should display: "You are not allow to create contacts using this button".
Also for the code added above you are using the method incorrectly , Requesy you to use developer manual/apex code before going through it
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.