Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for more Apex language file extensions (apxc, apxt) #4640

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ ApacheConf:
Apex:
type: programming
extensions:
- ".apxc"
pchaigno marked this conversation as resolved.
Show resolved Hide resolved
- ".apxt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I downloaded the 221 files associated with that extension using Harvester and counted 106 repositories by 96 users. This is not enough to mandate addition to Linguist by our standards (i.e., hundreds of repositories). I think we should remove it from this pull request and reconsider it in the future if usage grows.

Copy link
Author

@Arv18 Arv18 Oct 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is a low number of repositories, but it is the official extension of that language. Users who are using the java extension .cls, is because they want them indexed with linguist, but I'm sure they want to send a pull like this or they don't know how. I really think this would help a lot. Thanks for considering this.

https://trailhead.salesforce.com/en/content/learn/modules/developer_console/developer_console_source_code
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro.htm

- ".cls"
tm_scope: source.java
ace_mode: java
Expand Down
23 changes: 23 additions & 0 deletions samples/Apex/AccountAddressTrigger.apxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
trigger AccountAddressTrigger on Account(before insert, before update) {
// EXAMPLE APEX TRIGGER ON Account
// https://trailhead.salesforce.com/es-MX/content/learn/modules/apex_triggers/apex_triggers_intro?trail_id=force_com_dev_beginner

Account a = new Account();
for(Account a : Trigger.New) {
if (a.Match_Billing_Address__c){
a.ShippingPostalCode = a.BillingPostalCode;
}
}

for(Account a2 : Trigger.New) {
if (a2.Match_Billing_Address__c == true && a2.Match_Billing_Address__c != null){
a2.ShippingPostalCode = a2.BillingPostalCode;
}
}

for(Account a3 : Trigger.New) {
if (a3.Match_Billing_Address__c == true){
a3.ShippingPostalCode = a3.BillingPostalCode;
}
}
}
14 changes: 14 additions & 0 deletions samples/Apex/ClosedOpportunityTrigger.apxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
// EXAMPLE APEX TRIGGER ON Opportunity
// https://trailhead.salesforce.com/es-MX/content/learn/modules/apex_triggers/apex_triggers_bulk?trail_id=force_com_dev_beginner

List<Task> t = new List<Task>();
for(Opportunity o : Trigger.New) {
if (o.StageName == 'Closed Won'){
t.add(new Task(Subject = 'Follow Up Test Task' + WhatId = o.Id));
}
}
if (t.size() > 0) {
insert t;
}
}
40 changes: 40 additions & 0 deletions samples/Apex/EmailManager.apxc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
public class EmailManager {
// EXAMPLE APEX CLASS with methods

// Public method
public static void sendMail(String address, String subject, String body) {
// Create an email message object
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {address};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);

// Pass this email message to the built-in sendEmail method
// of the Messaging class
Messaging.SendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

// Call a helper method to inspect the returned results
inspectResults(results);
}

// Helper method
private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
Boolean sendResult = true;

// sendEmail returns an array of result objects.
// Iterate through the list to inspect results.
// In this class, the methods send only one email,
// so we should have only one result.
for (Messaging.SendEmailResult res : results) {
if (res.isSuccess()) {
System.debug('Email sent successfully');
}else {
sendResult = false;
System.debug('The following errors occurred: ' + res.getErrors());
}
}

return sendResult;
}
}
90 changes: 90 additions & 0 deletions samples/Apex/NetSuiteContactBatch.apxc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
global class NetSuiteContactBatch implements Database.Batchable<Integer>, Database.Stateful, Database.AllowsCallouts{
// EXAMPLE APEX BATCH

public Boolean isAll;
public Integer pageSize;
public String searchId;

global NetSuiteContactBatch(Boolean isAll, Integer pageSize){
this.pageSize = pageSize;
this.isAll = isAll;
}

global List<Integer> start(Database.BatchableContext BC){
Integer totalPages = 0;
for(Dom.XmlNode childElement1:NetSuiteConnection.getNetSuiteSearchObject(isAll, 'ContactSearch', pageSize))
for(Dom.XmlNode childElement2:childElement1.getChildElements())

for(Dom.XmlNode childElement3:childElement2.getChildElements()){
if(childElement3.getName() == 'totalPages'){
totalPages = String.isNotBlank(childElement3.getText()) ? Integer.valueOf(childElement3.getText()) : 0;
}
if(childElement3.getName() == 'searchId'){
searchId = childElement3.getText();
break;
}
}

List<Integer> pages = new List<Integer>();
for(Integer i = 1; i <= totalPages; i++) pages.add(i);
return pages;
}

global void execute(Database.BatchableContext BC, List<Integer> scope) {
Map<String, Contact> contactsMap = new Map<String, Contact>();
Map<String, Id> accountsMap = new Map<String, Id>();
Contact cont;
for(Dom.XmlNode childElement1:NetSuiteConnection.getNetSuiteSearchMore(searchId, scope[0])){
for(Dom.XmlNode childElement2:childElement1.getChildElements()){
for(Dom.XmlNode childElement3:childElement2.getChildElements()){
if(childElement3.getName() == 'recordList'){
for(Dom.XmlNode childElement4:childElement3.getChildElements()){
cont = new Contact();
cont.NetSuite_ID__c = childElement4.getAttributeValue('internalId', '');
for(Dom.XmlNode childElement5:childElement4.getChildElements()){
if(childElement5.getName() == 'entityId') cont.LastName = childElement5.getText();
if(childElement5.getName() == 'firstName') cont.FirstName = childElement5.getText();
if(childElement5.getName() == 'lastName') cont.LastName = childElement5.getText();
if(childElement5.getName() == 'company') cont.NetSuite_Customer_ID__c = childElement5.getAttributeValue('internalId', '');
if(childElement5.getName() == 'dateCreated') cont.Date_Created__c = childElement5.getText().countMatches('-') == 3 ? DateTime.valueOf(childElement5.getText().substringBeforeLast('-').replace('T', ' ')) : DateTime.valueOf(childElement5.getText().replace('T', ' '));
if(childElement5.getName() == 'email') cont.Email = childElement5.getText();
if(childElement5.getName() == 'addressbookList'){
for(Dom.XmlNode childElement6:childElement5.getChildElements()){
for(Dom.XmlNode childElement7:childElement6.getChildElements()){
if(childElement7.getName() == 'defaultBilling') cont.Default_Billing__c = childElement7.getText() == 'true' ? true : false;
if(childElement7.getName() == 'addressbookAddress'){
if(cont.Default_Billing__c != null && cont.Default_Billing__c){
for(Dom.XmlNode childElement8:childElement7.getChildElements()){
if(childElement8.getName() == 'city') cont.MailingCity = childElement8.getText();
if(childElement8.getName() == 'country') cont.MailingCountry = childElement8.getText();
if(childElement8.getName() == 'dropdownstate') cont.MailingState = childElement8.getText();
if(childElement8.getName() == 'zip') cont.MailingPostalCode = childElement8.getText();
if(childElement8.getName() == 'addrText') cont.MailingStreet = childElement8.getText();
}
}
}
}
}
}
}
if(String.isNotEmpty(cont.NetSuite_Customer_ID__c)) accountsMap.put(cont.NetSuite_Customer_ID__c, null);
contactsMap.put(cont.NetSuite_ID__c, cont);
}
}
}
}
}
List<Database.UpsertResult> upsertResults;
for(Account account: [Select id, NetSuite_ID__c from Account where NetSuite_ID__c in:accountsMap.keySet()]) accountsMap.put(account.NetSuite_ID__c, account.id);
for(Contact con: contactsMap.values()) if(accountsMap.get(con.NetSuite_Customer_ID__c) != null) con.AccountId = accountsMap.get(con.NetSuite_Customer_ID__c);

if(!contactsMap.values().isEmpty()){
upsertResults = Database.upsert(contactsMap.values(), Contact.NetSuite_ID__c, false);
for(Database.UpsertResult upsertResult:upsertResults) if(!upsertResult.isSuccess()) for(Database.Error upsertError : upsertResult.getErrors()) System.debug('NetSuiteContactBatch Contact Upsert Error: ' + upsertError.getMessage());
}
}

global void finish(Database.BatchableContext BC) {
if(!Test.isRunningTest()) Database.executeBatch(new NetSuiteItemBatch(isAll, pageSize), 1);
}
}
15 changes: 15 additions & 0 deletions samples/Apex/TestVerifyDate.apxc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@isTest
public class TestVerifyDate {
// EXAMPLE APEX TEST
// https://trailhead.salesforce.com/es-MX/content/learn/modules/apex_testing/apex_testing_triggers?trail_id=force_com_dev_beginner

@isTest static void testCheckDates() {
Date pri = VerifyDate.CheckDates(date.newinstance(2019, 5, 14), date.newinstance(2019, 5, 31));
System.assertEquals(date.newinstance(2019, 5, 31), pri);
}

@isTest static void testCheckDates2() {
Date pri = VerifyDate.CheckDates(date.newinstance(2019, 5, 14), date.newinstance(2019, 6, 30));
System.assertEquals(date.newinstance(2019, 6, 30), pri);
}
}