February, 2017
Salesforce: onClick JavaScript
Sample 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")} var name = "{!Contact.FirstName}"; var conid = "{!Contact.Id}"; //window.confirm('are you sure you want to execute ' + conid ); //SELECT ContactId FROM User //where contactId = '003E000000crCfb' //var userReg = sforce.connection.query("SELECT ContactId from User where contactId //='{!Contact.Id}' limit 1"); //alert(userReg ); var recordExists = false; var result = sforce.connection.query("SELECT Name,ContactId from User where contactId ='{!Contact.Id}' limit 1"); records = result.getArray("records"); for (var i=0; i< records.length; i++) { var record = records[i]; //alert(record.Name + " -- " + record.ContactId ); recordExists = true; alert('This user is already registered. ' + record.Name); } if(!recordExists) { if(confirm('You are about to generate a new Activation Email for this user. Would you like to proceed?')) { var result = sforce.apex.execute('RequestActivationCodeController','requestActivationCodeFromJS',{ contId: '{!Contact.Id}' }); if(result == 'Success') { window.top.location.reload(); alert('Send Activation Email Success!'); } else if (result == 'There is no email exists') { alert('There is no email exists'); recordExists = false; } } } |
Sample 2: using Labels
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")} var recordId = "{!Event__c.Id}"; if("{!Event__c.OwnerId}" != "{!$User.Id}" && "{!Event__c.Status__c}" =="New"){ alert("Event must send for approval or approved before attendees send for Subumission."); }else{ var resCode = sforce.apex.execute('GlobalUtilCls', 'validateEventRequiredFields', {eventId:recordId}); if( resCode == '{!$Label.Result_Code_All_OK}'){ var cqChecked = false; if("{!Event__c.Is_Control_Questions_Check_Performed__c}"==true){ cqChecked = true; }else{ var cqList = sforce.apex.execute('ControlQuestionHelper','getControlQuestionIdListWS',{objectId:recordId}); if(cqList.length == 0){ cqChecked = true; } } if(cqChecked==false){ alert('Error- '+ '{!$Label.Event_ControlQuestion_RequiredMsg}'); } else{ var checkDocsResCode = sforce.apex.execute('RequiredDocumentHelper', 'validateRequiredDocumentsWS', {objectId:recordId}); if(checkDocsResCode == '{!$Label.Result_Code_All_OK}'){ window.location.href ='/apex/EventSubmitForm?Id='+recordId; }else{ alert('Error- '+checkDocsResCode); } } }else{ //display error message alert('Error- '+resCode); } } |
Sample 3: reLoad the same page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")} //var conid = "{!Contact.Id}"; if(confirm('You are about to generate a Username Retrieval Email for this user. Would you like to proceed?')) { //alert('{!Contact.Email}'); var result = sforce.apex.execute('RequestUsernameController','requestUsernameFromJS',{ emailAddress: '{!Contact.Email}'}); if(result == 'Success') { window.top.location.reload(); alert('Send Username Retrieval Email Success!'); } else if (result == 'There is no email exists') { alert('There is no email exists'); } } |
Favorite
Future Method
1 2 3 4 5 6 7 |
global class SomeClass { @future public static void someFutureMethod(List<Id> recordIds) { List<Account> accounts = [Select Id, Name from Account Where Id IN :recordIds]; // process account records to do awesome stuff } } |
Note The reason why objects can’t be passed as arguments to future methods is because the object can change between the time you call the method and the time that it actually executes. Remember, future methods are executed when system resources become available. In this case, the future method may have an old object […]
USING SOAPUI TO TEST SALESFORCE SOAP WEBSERVICES
USING SOAPUI TO TEST SALESFORCE SOAP WEBSERVICES (https://play.vidyard.com/s8gYmLgVhztuPTgPxRYGcQ) Favorite
Get to Know the Salesforce APIs
Trailhead link The Salesforce API landscape is as vast as the ocean blue. That’s because Salesforce takes an API-first approach to building features on the Salesforce App Cloud. API first means building a robust API for a feature before focusing on designing its UI. This approach gives you, the Salesforce developer, flexibility to manipulate your […]