• Frank Jordan 14
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I am pretty new to Salesforce development and wanted to know if there is an API for creating new accounts. We have a website where users fill in their info into a form and we would like for this data to push to Salesforce through an API. Is this possible?
I am pretty new to Salesforce development and I am having a hard time wiriting a test class for some code that I am writing for a Jira to Salesforce connector. Below is my class and trigger, but I am not sure how to write a test class for a web service callout. Any help would be appreciated.

Class: 
global class JIRAWebserviceCalloutSyncStatus {
    @future (callout=true)
    WebService static void syncstatus(String status, String jiraKey) {
        //Modify these variables:
        String username = 'salesforceconnector';
        String password = 'xxxxxx';
        String jiraURL = 'https://xxxxx.xxxxxx.com';
        String transitionId;
         
        //Map Salesforce Status to JIRA transition Id:
         if (status == 'Waiting on Risk') {                  // Salesforce.com Status
            transitionId = '181';                 // JIRA transition ID
        } else if (status == 'Waiting on Customer') {
            transitionId = '21';
        } else if (status == 'Active') {
            transitionId = '161'; 
        } 
        
         
        //Construct HTTP request and response
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
 
        //Construct Authorization and Content header
        Blob headerValue = Blob.valueOf(username+':'+password);
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-Type','application/json');
 
        //Construct Endpoint
        String endpoint = jiraURL+'/rest/api/2/issue/'+jiraKey+'/transitions';
         
        //Set Method and Endpoint and Body
        req.setMethod('POST');
        req.setEndpoint(endpoint);
        req.setBody('{ \"transition\": {\"id\": \"'+transitionId+'\"}}');
 
        try {
            //Send endpoint to JIRA
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug(res.toString());
        }
    }
}

Trigger:
trigger SyncStatus on Case (after update) {
    //Identify profile name to be blocked from executing this trigger
    String JIRAAgentProfileName = 'JIRA Agent';
    List<Profile> p = [SELECT Id FROM Profile WHERE Name=:JIRAAgentProfileName];
     
    //Check if specified Profile Name exist or not
    if(!p.isEmpty())
    {
        //Check if current user's profile is catergorized in the blocked profile
        if(UserInfo.getProfileId()!= String.valueOf(p[0].id))
        {
            for (Case c : Trigger.new) {
                //Define parameters to be used in calling Apex Class
                String status = c.Status;
                String jiraKey = c.JIRA_Key__c;
                 
                JIRAWebserviceCalloutSyncStatus.syncstatus(status, jiraKey);
            }
        }
    }
}

Test Class:
 
@isTest
public class TestJIRAWebserviceCalloutSyncStatus {

    static testMethod void TestJIRAWebserviceCalloutSyncStatus(){
        Test.startTest();
        JIRAWebserviceCalloutSyncStatus.SyncStatus();
        Test.stopTest();
         
        
        
    }
    
    
    
}

 
I have a trigger that updates a check box on a task when it is the most recent task created by  the account owner. I am getting the following error: System.QueryException: Non-selective query against large object type (more than 100000 rows). I even added a condition in my query where the created date must be after May of this year, and i know for a fact that there arent more than 100,000 rows. Any idea?
 
trigger LastActivityByAccountOwner on Task (after insert, after update) {

    
List<Task> TasksToUpdate = new List<Task>{};
 
boolean firstRecord = true; 
for(Task ttu : [Select Id, Last_activity_by_account_owner__c , Same_as_Account_Owner__c 
                from Task where Same_as_Account_Owner__c = true AND DAY_ONLY(createddate)>2016-05-01 
                ORDER BY createddate DESC ])
{
if(firstRecord)
{
ttu.Last_activity_by_account_owner__c = True;
firstRecord = false;
}
else
ttu.Last_activity_by_account_owner__c   = False;
 
TasksToUpdate.add(ttu);
 }
}

 
I am pretty new to Salesforce development and I am having a hard time wiriting a test class for some code that I am writing for a Jira to Salesforce connector. Below is my class and trigger, but I am not sure how to write a test class for a web service callout. Any help would be appreciated.

Class: 
global class JIRAWebserviceCalloutSyncStatus {
    @future (callout=true)
    WebService static void syncstatus(String status, String jiraKey) {
        //Modify these variables:
        String username = 'salesforceconnector';
        String password = 'xxxxxx';
        String jiraURL = 'https://xxxxx.xxxxxx.com';
        String transitionId;
         
        //Map Salesforce Status to JIRA transition Id:
         if (status == 'Waiting on Risk') {                  // Salesforce.com Status
            transitionId = '181';                 // JIRA transition ID
        } else if (status == 'Waiting on Customer') {
            transitionId = '21';
        } else if (status == 'Active') {
            transitionId = '161'; 
        } 
        
         
        //Construct HTTP request and response
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
 
        //Construct Authorization and Content header
        Blob headerValue = Blob.valueOf(username+':'+password);
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-Type','application/json');
 
        //Construct Endpoint
        String endpoint = jiraURL+'/rest/api/2/issue/'+jiraKey+'/transitions';
         
        //Set Method and Endpoint and Body
        req.setMethod('POST');
        req.setEndpoint(endpoint);
        req.setBody('{ \"transition\": {\"id\": \"'+transitionId+'\"}}');
 
        try {
            //Send endpoint to JIRA
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug(res.toString());
        }
    }
}

Trigger:
trigger SyncStatus on Case (after update) {
    //Identify profile name to be blocked from executing this trigger
    String JIRAAgentProfileName = 'JIRA Agent';
    List<Profile> p = [SELECT Id FROM Profile WHERE Name=:JIRAAgentProfileName];
     
    //Check if specified Profile Name exist or not
    if(!p.isEmpty())
    {
        //Check if current user's profile is catergorized in the blocked profile
        if(UserInfo.getProfileId()!= String.valueOf(p[0].id))
        {
            for (Case c : Trigger.new) {
                //Define parameters to be used in calling Apex Class
                String status = c.Status;
                String jiraKey = c.JIRA_Key__c;
                 
                JIRAWebserviceCalloutSyncStatus.syncstatus(status, jiraKey);
            }
        }
    }
}

Test Class:
 
@isTest
public class TestJIRAWebserviceCalloutSyncStatus {

    static testMethod void TestJIRAWebserviceCalloutSyncStatus(){
        Test.startTest();
        JIRAWebserviceCalloutSyncStatus.SyncStatus();
        Test.stopTest();
         
        
        
    }
    
    
    
}

 
I have a trigger that updates a check box on a task when it is the most recent task created by  the account owner. I am getting the following error: System.QueryException: Non-selective query against large object type (more than 100000 rows). I even added a condition in my query where the created date must be after May of this year, and i know for a fact that there arent more than 100,000 rows. Any idea?
 
trigger LastActivityByAccountOwner on Task (after insert, after update) {

    
List<Task> TasksToUpdate = new List<Task>{};
 
boolean firstRecord = true; 
for(Task ttu : [Select Id, Last_activity_by_account_owner__c , Same_as_Account_Owner__c 
                from Task where Same_as_Account_Owner__c = true AND DAY_ONLY(createddate)>2016-05-01 
                ORDER BY createddate DESC ])
{
if(firstRecord)
{
ttu.Last_activity_by_account_owner__c = True;
firstRecord = false;
}
else
ttu.Last_activity_by_account_owner__c   = False;
 
TasksToUpdate.add(ttu);
 }
}