You need to sign in to do that
Don't have an account?
moritz.dev1.3947933254307776E12
Cant get my remote to work
Hey guys,
I am fairly new to Remoting. I tried it on a small class to test it out and it works.
Now I am programming a Contact Creator (Just for the fun of it and learning).
But I can not get my Remoting zu work.
The called method worked fine whenever I used apex:action elements.
What I noticed is, that the page reloads everytime I hit the "create Dummie" button.
Any idea what I am doing wrong?
<script type="text/javascript">
function createDummiesRemote() {
var integer = document.getElementById('input').value;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MoesController.createDummies}',
integer,
function(result, event){
if (event.status) {
alert("Dummies created");
} else if (event.type === 'exception') {
alert("exception: "+event.message);
} else {
alert(event.message);
}
},
{escape: true}
);
alert(integer);
}
</script>
It does reach the alert part and gives me the correct integer, so it is triggered correctly. Just the function does not seem to work.
I am fairly new to Remoting. I tried it on a small class to test it out and it works.
Now I am programming a Contact Creator (Just for the fun of it and learning).
But I can not get my Remoting zu work.
The called method worked fine whenever I used apex:action elements.
What I noticed is, that the page reloads everytime I hit the "create Dummie" button.
Any idea what I am doing wrong?
<script type="text/javascript">
function createDummiesRemote() {
var integer = document.getElementById('input').value;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MoesController.createDummies}',
integer,
function(result, event){
if (event.status) {
alert("Dummies created");
} else if (event.type === 'exception') {
alert("exception: "+event.message);
} else {
alert(event.message);
}
},
{escape: true}
);
alert(integer);
}
</script>
It does reach the alert part and gives me the correct integer, so it is triggered correctly. Just the function does not seem to work.
@RemoteAction
public static Boolean createDummies(Integer amount) {
System.debug('Start');
List<Contact> toInsert = new List<Contact>();
for(Integer i = 1; i<=amount; i++){
contact.title = 'dummy';
contact.lastName = lnames.get(randomizer(10));
if(fnameCheck) contact.firstName = fnames.get(randomizer(10));
if(nationCheck) contact.Nationality__c = nation.get(randomizer(10));
if(salutCheck) contact.Salutation = salut.get(randomizer(5));
if(birthCheck) contact.birthdate = date.newInstance(randomizer(1900, 2000), randomizer(1, 12), randomizer(1, 28));
if(emailCheck) contact.Email = contact.FirstName + '.' + contact.LastName + '@' + 'gmail.com';
if(adresCheck) {
contact.MailingStreet = street.get(randomizer(10)) + ' ' + randomizer(1, 200);
contact.MailingPostalCode = '' + randomizer(10000, 99999);
contact.MailingCity = city.get(randomizer(10));
contact.MailingCountry = contact.Nationality__c;
}
if(identCheck){
contact.ID_document_type__c = ident.get(randomizer(3));
contact.Passport_ID_Number__c = '' + randomizer(99999999);
}
if(creditCardCheck) {
contact.Credit_Card_Holder_Name__c = contact.FirstName + ' ' + contact.LastName;
contact.Credit_Card_Type__c = ccType.get(randomizer(5));
contact.Credit_Card_Number_Encrypt__c = '' + randomizer(1000, 9999) + '-' + randomizer(1000, 9999) + '-' + randomizer(1000, 9999) + '-' + randomizer(1000, 9999);
contact.Credit_Card_Security_Code_Text__c = '' + randomizer(100, 999);
contact.Credit_Card_Expiry_Month_Pick__c = month.get(randomizer(1, 12));
contact.Credit_Card_Expiry_Year_Pick__c = '' + randomizer(2014, 2025);
}
if(phoneCheck) contact.Phone = '(+' + randomizer(1, 49) + ')' + ' ' + randomizer(100, 999) + ' ' + randomizer(100, 999) + ' ' + randomizer(100, 999);
toInsert.add(contact);
contact = null;
}
insert toInsert;
toInsert.clear();
return True;
}