• LaKeisha Jordan
  • NEWBIE
  • -1 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 5
    Replies
Error Received:

Apex script unhandled trigger exception by user/organization: 00570000004LeTu/00D300000006E35
 
Region_cLeadTrigger: execution of BeforeInsert
 
caused by: System.QueryException: List has no rows for assignment to SObject
 
Trigger.Region_cLeadTrigger: line 3, column 1




Below is the full Trigger:

trigger Region_cLeadTrigger on Lead (before insert) {

    staticResource sr = [
        select Body
        from StaticResource
        where Name = 'regionjson'
    ];
    String country = '';
    JSONParser parser = JSON.createParser(sr.Body.toString());
   
    try {
        if(Trigger.isBefore) {
            for (Lead l : trigger.New) { 
                System.debug('Inbound country is: ' + l.Country__c + ' Inbound Region is: ' + l.Region__c);
                if (l.Region__c == null) {
                    String region = findRegion(l.Country__c);
                    System.debug('Value of new region is: ' + region);
                    if (region != null) {
                        l.Region__c = region;
                    }
                }
            }
        }
    } catch (Exception ex) {
        System.debug('Unable to save region due to incorrect mapping error is: ' + ex);
    }
    private String findRegion(String uiCountry) {
        boolean rootFlag = false;
        String country;
        while (parser.nextToken() != null) {
            // root found
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Workbook')) {
                System.debug('Found root!');
                rootFlag = true;
                parser.nextToken();
            }         
            if (rootFlag)  {
                if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
                    country = parser.getText();
                    while (parser.nextToken() != null) {
                        if (parser.getCurrentToken() == JSONToken.VALUE_STRING) {
                            if (uiCountry.equalsIgnoreCase(country)) {
                                return parser.getText();   
                            }
                            break;
                        }                      
                    }
                }
            }
        }
        return null;
    }
}
 
The error message states there is an error in column 3 line 1



trigger Region_cLeadTrigger on Lead (before insert) {

    staticResource sr = [
        select Body
        from StaticResource
        where Name = 'regionjson'

 
Here is the Trigger:

trigger Region_cLeadTrigger on Lead (before insert) {

    staticResource sr = [
        select Body
        from StaticResource
        where Name = 'CountryRegionJSONII'
    ];
    String country = '';
    JSONParser parser = JSON.createParser(sr.Body.toString());
   
    try {
        if(Trigger.isBefore) {
            for (Lead l : trigger.New) { 
                System.debug('Inbound country is: ' + l.Country__c + ' Inbound Region is: ' + l.Region__c);
                if (l.Region__c == null) {
                    String region = findRegion(l.Country__c);
                    System.debug('Value of new region is: ' + region);
                    if (region != null) {
                        l.Region__c = region;
                    }
                }
            }
        }
    } catch (Exception ex) {
        System.debug('Unable to save region due to incorrect mapping error is: ' + ex);
    }
    private String findRegion(String uiCountry) {
        boolean rootFlag = false;
        String country;
        while (parser.nextToken() != null) {
            // root found
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Workbook')) {
                System.debug('Found root!');
                rootFlag = true;
                parser.nextToken();
            }         
            if (rootFlag)  {
                if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
                    country = parser.getText();
                    while (parser.nextToken() != null) {
                        if (parser.getCurrentToken() == JSONToken.VALUE_STRING) {
                            if (uiCountry.equalsIgnoreCase(country)) {
                                return parser.getText();   
                            }
                            break;
                        }                      
                    }
                }
            }
        }
        return null;
    }
}


Error Message:

Reason: Apex trigger Region_cLeadTrigger caused an unexpected exception, contact your administrator: Region_cLeadTrigger: execution of BeforeInsert
 
caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.Region_cLeadTrigger: line 3, column 1



 
Unable to configure an Apex Trigger/Code to update a field after insert. When the data of one field is integrated from the Website into the Salesforce Lead record, I neeed a trigger that will update the Region field from the data entered in the Country field.
Here is the Trigger:

trigger Region_cLeadTrigger on Lead (before insert) {

    staticResource sr = [
        select Body
        from StaticResource
        where Name = 'CountryRegionJSONII'
    ];
    String country = '';
    JSONParser parser = JSON.createParser(sr.Body.toString());
   
    try {
        if(Trigger.isBefore) {
            for (Lead l : trigger.New) { 
                System.debug('Inbound country is: ' + l.Country__c + ' Inbound Region is: ' + l.Region__c);
                if (l.Region__c == null) {
                    String region = findRegion(l.Country__c);
                    System.debug('Value of new region is: ' + region);
                    if (region != null) {
                        l.Region__c = region;
                    }
                }
            }
        }
    } catch (Exception ex) {
        System.debug('Unable to save region due to incorrect mapping error is: ' + ex);
    }
    private String findRegion(String uiCountry) {
        boolean rootFlag = false;
        String country;
        while (parser.nextToken() != null) {
            // root found
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Workbook')) {
                System.debug('Found root!');
                rootFlag = true;
                parser.nextToken();
            }         
            if (rootFlag)  {
                if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
                    country = parser.getText();
                    while (parser.nextToken() != null) {
                        if (parser.getCurrentToken() == JSONToken.VALUE_STRING) {
                            if (uiCountry.equalsIgnoreCase(country)) {
                                return parser.getText();   
                            }
                            break;
                        }                      
                    }
                }
            }
        }
        return null;
    }
}


Error Message:

Reason: Apex trigger Region_cLeadTrigger caused an unexpected exception, contact your administrator: Region_cLeadTrigger: execution of BeforeInsert
 
caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.Region_cLeadTrigger: line 3, column 1