• Arvind_Singh
  • NEWBIE
  • 144 Points
  • Member since 2016
  • Salesforce Technical Lead
  • Cognizant Technology Solutions U.S. Corp

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 22
    Replies
Please help with this test class, I cant get 100%, dont know how to improve it. Thanks,
@isTest
private class AutoPopDateTest {
  @isTest
  private static void AutoPopDate() {
    Billing__C bil = new Billing__C();
    bil.Name = 'NewBill';
    bil.Billing_Date__c = system.today();
    bil.Accounting_date__c = bil.Billing_Date__c.addDays(20);
    try {
      insert bil;
    } catch (NullPointerException n) {
    }
  }
}
and trigger:
trigger AutoPopAccPerDate on Billing__c(before insert, before update) {
   for (Billing__c billing : Trigger.new) {
    if (billing.Accounting_Date__c == null) {
      billing.Accounting_Date__c = billing.Billing_Date__c.adddays(30); // '30 Days' - Depends on the terms.
    }
  }
}

Appreciate any support!
 
I try to query the records using parent-child SOQL in test method  but i get the child reocrds for each parent in reverse order , if the query returns more than one parent records .
But if it return a single parent record than the child records are in proper order.

I attach the example code below , please go through it . 
@IsTest static void test(){
        List<Class__c> cList = new List<Class__c>();
        Class__c classRecord1 = new Class__c(Board__c = 'Bihar',Fee__c = 100, MaxSize__c = 4);
        Class__c classRecord2 = new Class__c(Board__c = 'Bihar',Fee__c = 1000, MaxSize__c = 5);
        cList.add(classRecord1);
        cList.add(classRecord2);
        insert cList;

        List<Student__c> studentList = new List<Student__c>();

        for(Integer i = 0; i < 4; i++){
            Student__c studentData1 = new Student__c(First_Name__c = 'Test Name '+ i + ' c0', LastName__c = 'LastName' + i, Sex__c = 'Female',Class__c = cList[0].Id);

            Student__c studentData2 = new Student__c(First_Name__c = 'Test Name '+ i + ' c1', LastName__c = 'LastName' + i, Sex__c = 'Female',Class__c = cList[1].Id);

            studentList.add(studentData1);
            studentList.add(studentData2);
        }

        insert studentList;

        Class__c output = [SELECT MaxSize__c, Fee__c, (SELECT First_Name__c FROM Students__r) FROM Class__c LIMIT 1];
        System.debug('Single record from output ' + output.Students__r);

        List<Class__c> outputList = [SELECT MaxSize__c, Fee__c, (SELECT First_Name__c FROM Students__r) FROM Class__c];
        System.debug('Single record from list of outputs '+ outputList[0].Students__r);
    }
The output for both debug are : 
      For 1st debug  :   Single record from output (Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTrAAK, First_Name__c=Test Name 0 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTtAAK, First_Name__c=Test Name 1 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTvAAK, First_Name__c=Test Name 2 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTxAAK, First_Name__c=Test Name 3 c0})

For 2nd Debug :     Single record from list of outputs (Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTxAAK, First_Name__c=Test Name 3 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTvAAK, First_Name__c=Test Name 2 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTtAAK, First_Name__c=Test Name 1 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTrAAK, First_Name__c=Test Name 0 c0})

You can see that the output of 1st debug gives student records in proper order as they are inserted , but output of 2nd debug givess student records in reverse order as they are inserted. 

I want to know why this happens . 

Thanks in advance
​​​​​​​
Is there any change in PD1 Syllabus recently? I see one with UI portion 10% covered and another Syllabus has 25% covered?  Anyone can tell me which one to follow? https://developer.salesforce.com/resources2/certification-site/files/SGCertifiedPlatformDeveloperI.pdf   https://trailhead.salesforce.com/en/help?article=Salesforce-Certified-Platform-Developer-I-Exam-Guide
  • June 07, 2020
  • Like
  • 0
Hi and thanks in advance for your help.  I wrote this test and can't figure out why I can't get any coverage.  Seems so simple.

public with sharing class AccountStatus
{

 @AuraEnabled

    public static Account getAccount(Id accountId)

    {

        //Query fields from Parent record to prepopulate New RTO

        return [SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :accountId];    

    }

}


Test class

@isTest
private class AccountStatusTest

{

   

    static testMethod void getAccount()

    {

        Account a = new Account();

        a.name='Test';

        a.phone='12345';        

        a.Account_Status__c = 'Active Account';

        a.Bill_To_DUNs_Number__c = '1234567890';

        a.BillingCountry = 'United States';

        a.BillingStreet = 'Main Street';

        a.BillingCity = 'Dallas';

        a.BillingState = 'Texas';

        a.BillingPostalCode = '76543';

        a.Billing_County__c = 'Blackland';

        a.BillingStateCode = 'TX';

        a.Legal_Entity_Name__c = 'TestParent';

        a.Type__c = 'Retail Outlet';

       // a.Account_Record_ID__c = '0120W000001USkRQAW';

        a.Current_Brand__c = 'Sunoco';

        insert a;

       

        Account a2=[SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :a.id];

        System.assert(a2!=null);        

    }    

}

Thank You,
Eric

 
Hello - I am facing issue when trying to get value from wrapper class when checkbox is selected from List. I am saving user Id in wrapper class. I need to post to chatter based on for Selected and unSelected user. 

Wrapper Class :
public class UserdetailsWrapper{
    @AuraEnabled public string userName  {get;set;}
    @AuraEnabled public Id userId        {get;set;}
    @AuraEnabled public string userrole  {get;set;}
    @AuraEnabled public Boolean userchk  {get;set;}
    
    public UserdetailsWrapper(string userName,Id userId,string userrole){
        this.userName = userName;
        this.userId   = userId;
        this.userrole = userrole;
        this.userchk   = false;
    }
    
}

On Button Press I need to post to used for sleetced and unselected user from chatter post 
I am not getting user ID in log here is my JS Helper 
I googled and changed multiple times but nothing worked Any help or sample code ?
for (var m = 0; m < rowsSelected.length; m++){
                                AskedTo.push(rowsSelected[m].get("v.userId"));
                                alert("Loop-Selected Row");
                                console.log(rowsSelected[m].get("v.userId"));
                            }
 for (var n = 0; n < rowsUnSelected.length; n++) {
                                FyiTo.push(rowsUnSelected[n].get("v.userId"));
                                console.log(rowsUnSelected[n].get("v.userId"));
                                alert("Loop-UnSelected Row");
                            }

 
Hello,
I have created method in trigger handler class but method is taking more CPU time and sometime give error. Anyone Please suggested better approch of doing this. Thanks in Advance!!
Boolean QueryrunOnce = true;
Public void updatecheckandtoggle(List<AMM_ODR__REL__C> triggerNew)
{
Try{
Set<Id> OppIds = new set<id> ();
List<AMM_Opportunity__c> ListAMMOpptoUpdate;
If (Trigger.isInsert ||Trigger.isUpdate )
{
for (AMM_ODR__REL__C Odr : triggerNew )
{
OppIds.add(Odr.AMM_Opportunity__c);
}

}
if(OppIds.size() > 0 && QueryrunOnce )
{
QueryrunOnce = false;
ListAMMOpptoUpdate = New List<AMM_Opportunity__c> ([Select Id,AMM_OPP_Check__c,(Select TTPI__C from Summury_Flex__Jo__r) from AMM_Opportunity__c where id:=OppIds];
}
If(!ListAMMOpptoUpdate.isEmpty())
{
for (AMM_Opportunity__c Opps: ListAMMOpptoUpdate )
{
If (Opps.Summury_Flex__Jo__r.size()>0)
{
for (AMM_ODR__REL__C Odrr : Opps.Summury_Flex__Jo__r)
{
if(Odrr!null && odrr.TTPI__C!=null && Odrr.TTPI__C.startwith('14') )
{
Opps.AMM_OPP_Check__c = true;
opps.AMM_OPP_toggle__c=true;
} else
{
Opps.AMM_OPP_Check__c = true;
opps.AMM_OPP_toggle__c=true;
}
}
}
} Update ListAMMOpptoUpdate;
}
} Catch (Exception ex) {system.debug('The Exception Occur - ')}

 
Hello,
chartHelper run as system but still getting error. I have tried all possible ways but no luck. Can someone please help. 

Challenge Not yet complete... here's what's wrong: 
Ensure that the methods in the chartHelper class run as the system.

ChartHelper.apxc
public class ChartHelper {
    
    @AuraEnabled// Make sure annotation should be pplied for this method 
    public static List<chartData> GetInventory()
    {
        
        List<chartData> cht = new List<chartData>();
        
        for(AggregateResult ar : [SELECT Family family, Sum(Quantity_Remaining__c) total 
                                  FROM Product2
                                  WHERE Quantity_Remaining__c > 0 GROUP BY Family]){
                                      cht.add(new chartData((String)ar.get('family'), Integer.valueOf(ar.get('total'))));
                                  }
        return cht;
    }
    
    public class ChartData {
        public String name {get;set;}
        public Decimal val {get;set;}
        
        public ChartData(String name, Decimal val){
            this.name = name;
            this.val = val;
        }
    }
    
}
Product2Extension​.apxc
public class Product2Extension {

    public List<ProductWrapper> productsToInsert {get;set;}

    public Product2Extension(ApexPages.StandardController controller){
        productsToInsert = new List<ProductWrapper>();
        addRows();
    }
	
    public List<SelectOption> GetFamilyOptions() {
		List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption(Constants.SELECT_ONE, Constants.SELECT_ONE));
        for(PickListEntry eachPicklistValue : Constants.PRODUCT_FAMILY) {
			options.add(new SelectOption(eachPicklistValue.getValue(), eachPicklistValue.getLabel()));
        }
            return options;
    }
    
    public void AddRows(){
        for (Integer i=0; i<Constants.DEFAULT_ROWS; i++ ){
            productsToInsert.add(new ProductWrapper());
        }
    }

    public List<ChartHelper.ChartData> GetInventory(){
        return ChartHelper.GetInventory();
    }

    public PageReference Save(){
        SavePoint sp = Database.setSavepoint();
        Integer insertedCount = 0;
        try {
            List<Product2> newProducts = new List<Product2>();
            List<PriceBookEntry> pbeList = new List<PriceBookEntry>();
            List<ProductWrapper> filteredProductWrappers = new List<ProductWrapper>();
            for(ProductWrapper eachPW : productsToInsert) {
            	if(!String.isBlank(eachPW.productRecord.Name) && !String.isBlank(eachPW.productRecord.Family) && 
                   eachPW.productRecord.Family!=Constants.SELECT_ONE && eachPW.productRecord.isActive &&
                   eachPW.pricebookEntryRecord.UnitPrice!=null && eachPW.productRecord.Initial_Inventory__c!=null && 
                   eachPW.productRecord.Initial_Inventory__c!=0 && eachPW.pricebookEntryRecord.UnitPrice!=0) {
                       filteredProductWrappers.add(eachPW);
                   }                
            }
            for(ProductWrapper eachPW : filteredProductWrappers) {
                newProducts.add(eachPW.productRecord);
            }
            Database.SaveResult[] productSaveResults = Database.insert(newProducts, false);
            for(Integer i=0; i<productSaveResults.size(); i++) {
                if(productSaveResults[i].isSuccess()) {
                    PriceBookEntry pbe = filteredProductWrappers[i].pricebookEntryRecord;
                    pbe.Product2Id = productSaveResults[i].getId();
                    pbe.IsActive = true;
                    pbe.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
                    pbeList.add(pbe);
                    insertedCount++;
                }
            }
            Database.SaveResult[] pbeSaveResults = Database.insert(pbeList, false);
            
            //If successful clear the list and display an informational message
            apexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,insertedCount + ' Inserted'));
            productsToInsert.clear();   //Do not remove
            addRows();  //Do not remove
        } 
        catch (Exception e){
			System.debug('Exception occured:'+e.getMessage());
            Database.rollback(sp);
            apexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, Constants.ERROR_MESSAGE));            
        }
        return null;
    }
    
    public class ProductWrapper {
        public Product2 productRecord {get;set;}
        public PriceBookEntry pricebookEntryRecord {get;set;}
        
        public ProductWrapper() {
            productRecord = new Product2();
            pricebookEntryRecord = new PricebookEntry();
        }
	}
}
Product2New.vfp
<apex:page standardcontroller="Product2" extensions="Product2Extension">
    <apex:sectionHeader title="New Product" subtitle="Add Inventory" />
    <apex:pageMessages id="pageMessages" />
    <apex:form id="form" >
        <apex:actionRegion >
            <apex:pageBlock title="Existing Inventory" id="existingInv">
                <apex:chart data="{!Inventory}" width="600" height="400">
                    <apex:axis type="Category" fields="name" position="left" title="Product Family"/>
                    <apex:axis type="Numeric" fields="val" position="bottom" title="Quantity Remaining"/>
                    <apex:barSeries axis="bottom" orientation="horizontal" xField="val" yField="name"/>
                 </apex:chart>                
            </apex:pageBlock>
            <apex:pageBlock title="New Products" >
                <apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!save}" value="Save" reRender="existingInv, orderItemTable, pageMessages"/>
                </apex:pageBlockButtons>
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton action="{!addRows}" value="Add" reRender="orderItemTable, pageMessages" />
                </apex:pageBlockButtons>

                <apex:pageBlockTable value="{!productsToInsert}" var="p" id="orderItemTable" >
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}" >
                        <apex:inputText value="{!p.productRecord.Name}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}" >
                        <apex:selectList value="{!p.productRecord.Family}" size="1" multiselect="false">
                            <apex:selectOptions value="{!FamilyOptions}"></apex:selectOptions>
                        </apex:selectList>
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.IsActive.Label}" >
                        <apex:inputField value="{!p.productRecord.isActive}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.PricebookEntry.Fields.UnitPrice.Label}" >
                        <apex:inputText value="{!p.pricebookEntryRecord.UnitPrice}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Initial_Inventory__c.Label}" >
                        <apex:inputField value="{!p.productRecord.Initial_Inventory__c}" />
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:actionRegion>
    </apex:form>
</apex:page>

 
Hello everybody!
I have a custom object (Signoff) connected to Opportunity through a Master-Detail relationship.
On Signoff, there is a field called Currency. I would like to make sure that if the Currency field on Opportunity is 'US Dollar' for example, the Currency field on Signoff must be automatically updated to 'US Dollar'.

I tried to make it through a Workflow but I can't update the Currency field on Signoff with a Workflow.

How to do it with code, please?

Thanks a lot
Benji
Please help with this test class, I cant get 100%, dont know how to improve it. Thanks,
@isTest
private class AutoPopDateTest {
  @isTest
  private static void AutoPopDate() {
    Billing__C bil = new Billing__C();
    bil.Name = 'NewBill';
    bil.Billing_Date__c = system.today();
    bil.Accounting_date__c = bil.Billing_Date__c.addDays(20);
    try {
      insert bil;
    } catch (NullPointerException n) {
    }
  }
}
and trigger:
trigger AutoPopAccPerDate on Billing__c(before insert, before update) {
   for (Billing__c billing : Trigger.new) {
    if (billing.Accounting_Date__c == null) {
      billing.Accounting_Date__c = billing.Billing_Date__c.adddays(30); // '30 Days' - Depends on the terms.
    }
  }
}

Appreciate any support!
 
I try to query the records using parent-child SOQL in test method  but i get the child reocrds for each parent in reverse order , if the query returns more than one parent records .
But if it return a single parent record than the child records are in proper order.

I attach the example code below , please go through it . 
@IsTest static void test(){
        List<Class__c> cList = new List<Class__c>();
        Class__c classRecord1 = new Class__c(Board__c = 'Bihar',Fee__c = 100, MaxSize__c = 4);
        Class__c classRecord2 = new Class__c(Board__c = 'Bihar',Fee__c = 1000, MaxSize__c = 5);
        cList.add(classRecord1);
        cList.add(classRecord2);
        insert cList;

        List<Student__c> studentList = new List<Student__c>();

        for(Integer i = 0; i < 4; i++){
            Student__c studentData1 = new Student__c(First_Name__c = 'Test Name '+ i + ' c0', LastName__c = 'LastName' + i, Sex__c = 'Female',Class__c = cList[0].Id);

            Student__c studentData2 = new Student__c(First_Name__c = 'Test Name '+ i + ' c1', LastName__c = 'LastName' + i, Sex__c = 'Female',Class__c = cList[1].Id);

            studentList.add(studentData1);
            studentList.add(studentData2);
        }

        insert studentList;

        Class__c output = [SELECT MaxSize__c, Fee__c, (SELECT First_Name__c FROM Students__r) FROM Class__c LIMIT 1];
        System.debug('Single record from output ' + output.Students__r);

        List<Class__c> outputList = [SELECT MaxSize__c, Fee__c, (SELECT First_Name__c FROM Students__r) FROM Class__c];
        System.debug('Single record from list of outputs '+ outputList[0].Students__r);
    }
The output for both debug are : 
      For 1st debug  :   Single record from output (Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTrAAK, First_Name__c=Test Name 0 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTtAAK, First_Name__c=Test Name 1 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTvAAK, First_Name__c=Test Name 2 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTxAAK, First_Name__c=Test Name 3 c0})

For 2nd Debug :     Single record from list of outputs (Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTxAAK, First_Name__c=Test Name 3 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTvAAK, First_Name__c=Test Name 2 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTtAAK, First_Name__c=Test Name 1 c0}, Student__c:{Class__c=a062x0000023FrkAAE, Id=a052x000003JrTrAAK, First_Name__c=Test Name 0 c0})

You can see that the output of 1st debug gives student records in proper order as they are inserted , but output of 2nd debug givess student records in reverse order as they are inserted. 

I want to know why this happens . 

Thanks in advance
​​​​​​​

Hello All,

I inherited an Apex Class that's purpose is to check if Child Cases are still "Open" (not "Resolved" or "Closed") before allowing the Parent Case to be "Resolved" or "Closed".

The Apex Class has been working well until recently when a Case with 222 Child Cases and 59 Related Cases was trying to be "Closed".

The query of the Child Cases uses a FOR loop, but returned error:

 "Aggregate query has too many rows for direct assignment, use FOR loop."

I tried utilizing my companies Premier Support, but go nowhere. Lot's of links, but little help.

So I am asking if anyone has suggestions to make this Apex Class work.

Thanks friends.

Robert

 

Error:

System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop
External entry point

Problem Statement

//query all child cases

for(Case c:[SELECT Id, status,(select Id,status from cases) FROM  Case

 

Apex Class:

public class UpdateClosedCaseHelper {
    public static boolean skipSuperUserFilter = false;
    public static void updateCase(List<Case>  newcaselist,Map<Id,Case> oldMap,Map<Id,Case> newMap){
        if(!skipSuperUserFilter){
            //get current user info
            User u=[SELECT Id,Support_Super_User__c From User WHERE Id=:UserInfo.getUserId()];
            Set<Id> caseIdset=new Set<Id>();
            Map<Id,case> junctionMap=new Map<Id,case>();
            //get all case id's
            for(Case cd:newcaselist){
                caseIdset.add(cd.Id);
                junctionMap.put(cd.Id,cd);
            }
            //query all child cases                     
            for(Case c:[SELECT Id, status,(select Id,status from cases) FROM Case WHERE Id IN:caseIdset]){
                //check for value change
                if(oldMap.get(c.Id)!=newMap.get(c.Id)){
                    //case is not going to close
                    if(!newMap.get(c.Id).status.equals('Closed') 
                       &&
                       !newMap.get(c.Id).status.equals('Resolved')){
                           if(u.Support_Super_User__c){
                               //update case 
                           }
                           else{
                               if(oldMap.get(c.Id).status.equals('Closed'))
                                   newMap.get(c.Id).addError('Please contact your Almac Super User to re-open closed cases');
                               else{
                                   //update case 
                               }
                           }                        
                       }else{ 
                           //closing or resolving case
                           if((newMap.get(c.Id).status.equals('Closed') || newMap.get(c.Id).status.equals('Resolved')) && 
                              !isAllchildsClosed(c.cases)){                        
                                  if(u.Support_Super_User__c){
                                      //update case 
                                  }
                                  else{
                                      if(oldMap.get(c.Id).status.equals('Closed'))
                                          newMap.get(c.Id).addError('Please contact your Almac Super User to re-open closed cases');
                                      else{
                                          //update case 
                                      }
                                  }
                              }
                           else{
                               junctionMap.get(c.Id).addError('Child Case(s) need to be resolved before resolving a Parent Case');
                           }
                       }
                }
            }    
        }
    }
    public static boolean isAllchildsClosed(List<Case> childs){
        boolean flag=false;
        for(Case c:childs){
            if(!'Closed'.equals(c.Status) && !'Resolved'.equals(c.Status)){
                flag=true;
                break;
            }
        }
        return flag;
    }
}

 

hi everyone, how to reduce the batch run time ?? when I ran the batch it took 2 days to complete it which is a lot time for business to check the changes, is there any way we can reduce it ??
 
Is there any change in PD1 Syllabus recently? I see one with UI portion 10% covered and another Syllabus has 25% covered?  Anyone can tell me which one to follow? https://developer.salesforce.com/resources2/certification-site/files/SGCertifiedPlatformDeveloperI.pdf   https://trailhead.salesforce.com/en/help?article=Salesforce-Certified-Platform-Developer-I-Exam-Guide
  • June 07, 2020
  • Like
  • 0
I've been told by Salesforce that I need to use Apex coding to do this (permission sets, sharing rules/sets, and validation won't work), but I'm am looking for some direction on how to do it.

I have a Custom Object called Properties that is a child to Accounts. My properties are shopping centers in South Florida in Palm Beach, Broward, and Miami-Dade Counties. The counties are values in a picklist field.

I'd like the community users to have visibility access to all the Properties located in each county that is selected in a Picklist (Multi-Select) field that is in the Contacts Object. Currently, without this structure, community users can see all Properties in all 3 counties.

Thanks in advance for any help you can offer. 
I want to write a trigger to convert lead after updating the status field to "working-contacted".
Review the errors on this page.
VishalYadav.LeadTrigger: execution of AfterUpdate caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, convertedStatus is required.: [Status] Trigger.VishalYadav.LeadTrigger: line 8, column 1

TRIGGER:
----------
Trigger LeadTrigger on Lead (after update) {
    For(Lead l: Trigger.new)
    {
        if(l.IsConverted == false)
        {
            Database.LeadConvert lc = new database.LeadConvert();
            lc.setLeadId(l.id);
            Database.LeadConvertResult lcr = Database.convertLead(lc);
            System.assert(lcr.isSuccess());
        } }
}
Create a field on Account called “Only_Default_Contact”, checkbox, default off
Assignment:
When a new Account is created, create a new Contact that has the following data points:
First Name = “Info”
Last Name = “Default”
Email = “info@websitedomain.tld”
Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.

my question is on which object the trigger need to be created(Account,contact) if so Y
Hi and thanks in advance for your help.  I wrote this test and can't figure out why I can't get any coverage.  Seems so simple.

public with sharing class AccountStatus
{

 @AuraEnabled

    public static Account getAccount(Id accountId)

    {

        //Query fields from Parent record to prepopulate New RTO

        return [SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :accountId];    

    }

}


Test class

@isTest
private class AccountStatusTest

{

   

    static testMethod void getAccount()

    {

        Account a = new Account();

        a.name='Test';

        a.phone='12345';        

        a.Account_Status__c = 'Active Account';

        a.Bill_To_DUNs_Number__c = '1234567890';

        a.BillingCountry = 'United States';

        a.BillingStreet = 'Main Street';

        a.BillingCity = 'Dallas';

        a.BillingState = 'Texas';

        a.BillingPostalCode = '76543';

        a.Billing_County__c = 'Blackland';

        a.BillingStateCode = 'TX';

        a.Legal_Entity_Name__c = 'TestParent';

        a.Type__c = 'Retail Outlet';

       // a.Account_Record_ID__c = '0120W000001USkRQAW';

        a.Current_Brand__c = 'Sunoco';

        insert a;

       

        Account a2=[SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :a.id];

        System.assert(a2!=null);        

    }    

}

Thank You,
Eric

 

Hii Friends
I want to convert JSON into APEX and access fields in it
here I am attaching my JSON before I was using serialization but I was getting heap exception 
from bellow sting, I want to access "Position" field
can you help me with this 
Thank you

{
    "summary": {
        "query": "new york united states",
        "queryType": "NON_NEAR",
        "queryTime": 100,
        "numResults": 10,
        "offset": 0,
        "totalResults": 40,
        "fuzzyLevel": 1,
        "geoBias": {
            "lat": 37.337,
            "lon": -121.89
        }
    },
    "results": [{
        "type": "Geography",
        "id": "US/GEO/p0/2602",
        "score": 10.390219688415527,
        "dist": 4102107.7960908953,
        "entityType": "Municipality",
        "address": {
            "municipality": "New York",
            "countrySubdivision": "NY",
            "countrySubdivisionName": "New York",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "New York, NY"
        },
        "position": {
            "lat": 40.71305,
            "lon": -74.00723
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 40.9175,
                "lon": -74.25564
            },
            "btmRightPoint": {
                "lat": 40.49587,
                "lon": -73.70027
            }
        },
        "boundingBox": {
            "topLeftPoint": {
                "lat": 40.9175,
                "lon": -74.25564
            },
            "btmRightPoint": {
                "lat": 40.49587,
                "lon": -73.70027
            }
        },
        "dataSources": {
            "geometry": {
                "id": "d49d86a4-0f4b-45f2-b607-31a84d02af00"
            }
        }
    }, {
        "type": "Geography",
        "id": "US/GEO/p0/1651",
        "score": 9.32979965209961,
        "dist": 3955708.622326391,
        "entityType": "Municipality",
        "address": {
            "municipality": "New York Mills",
            "countrySecondarySubdivision": "Oneida",
            "countrySubdivision": "NY",
            "countrySubdivisionName": "New York",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "New York Mills, NY"
        },
        "position": {
            "lat": 43.09643,
            "lon": -75.30036
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 43.11543,
                "lon": -75.30826
            },
            "btmRightPoint": {
                "lat": 43.08484,
                "lon": -75.28021
            }
        },
        "boundingBox": {
            "topLeftPoint": {
                "lat": 43.11543,
                "lon": -75.30826
            },
            "btmRightPoint": {
                "lat": 43.08484,
                "lon": -75.28021
            }
        },
        "dataSources": {
            "geometry": {
                "id": "0000554e-3100-3c00-0000-0000596b08c2"
            }
        }
    }, {
        "type": "Geography",
        "id": "US/GEO/p0/29888",
        "score": 9.32979965209961,
        "dist": 2404251.2708335696,
        "entityType": "Municipality",
        "address": {
            "municipality": "New York Mills",
            "countrySecondarySubdivision": "Otter Tail",
            "countrySubdivision": "MN",
            "countrySubdivisionName": "Minnesota",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "New York Mills, MN"
        },
        "position": {
            "lat": 46.52074,
            "lon": -95.37458
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 46.71649,
                "lon": -95.52331
            },
            "btmRightPoint": {
                "lat": 46.4122,
                "lon": -95.23825
            }
        },
        "boundingBox": {
            "topLeftPoint": {
                "lat": 46.71649,
                "lon": -95.52331
            },
            "btmRightPoint": {
                "lat": 46.4122,
                "lon": -95.23825
            }
        },
        "dataSources": {
            "geometry": {
                "id": "00004d4e-3200-3c00-0000-0000596a3d5c"
            }
        }
    }, {
        "type": "Geography",
        "id": "US/GEO/p0/47216",
        "score": 9.32979965209961,
        "dist": 4100442.6075305184,
        "entityType": "Municipality",
        "address": {
            "municipality": "West New York",
            "countrySecondarySubdivision": "Hudson",
            "countrySubdivision": "NJ",
            "countrySubdivisionName": "New Jersey",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "West New York, NJ"
        },
        "position": {
            "lat": 40.78555,
            "lon": -74.00927
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 40.7966,
                "lon": -74.02369
            },
            "btmRightPoint": {
                "lat": 40.77438,
                "lon": -73.99288
            }
        },
        "boundingBox": {
            "topLeftPoint": {
                "lat": 40.7966,
                "lon": -74.02369
            },
            "btmRightPoint": {
                "lat": 40.77438,
                "lon": -73.99288
            }
        },
        "dataSources": {
            "geometry": {
                "id": "0000554e-4a00-3c00-0000-000059693dac"
            }
        }
    }, {
        "type": "Street",
        "id": "US/STR/p0/10292205",
        "score": 9.056180000305176,
        "dist": 14705.030048383549,
        "address": {
            "streetName": "New York Avenue",
            "municipality": "Los Gatos",
            "countrySecondarySubdivision": "Santa Clara",
            "countrySubdivision": "CA",
            "countrySubdivisionName": "California",
            "postalCode": "95030",
            "extendedPostalCode": "950306110, 950306111, 950306112",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "New York Avenue, Los Gatos, CA 95030",
            "localName": "Los Gatos"
        },
        "position": {
            "lat": 37.22315,
            "lon": -121.97456
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 37.22378,
                "lon": -121.97598
            },
            "btmRightPoint": {
                "lat": 37.22284,
                "lon": -121.97304
            }
        }
    }, {
        "type": "Geography",
        "id": "US/GEO/p0/1",
        "score": 8.88148021697998,
        "dist": 3924591.578208102,
        "entityType": "CountrySubdivision",
        "address": {
            "countrySubdivision": "NY",
            "countrySubdivisionName": "New York",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "NY"
        },
        "position": {
            "lat": 42.99724,
            "lon": -75.70226
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 45.01585,
                "lon": -79.76259
            },
            "btmRightPoint": {
                "lat": 40.49587,
                "lon": -71.85615
            }
        },
        "boundingBox": {
            "topLeftPoint": {
                "lat": 45.01585,
                "lon": -79.76259
            },
            "btmRightPoint": {
                "lat": 40.49587,
                "lon": -71.85615
            }
        },
        "dataSources": {
            "geometry": {
                "id": "00005858-5800-1200-0000-000077360db3"
            }
        }
    }, {
        "type": "Street",
        "id": "US/STR/p0/10530766",
        "score": 8.844799995422363,
        "dist": 14325.764991750375,
        "address": {
            "streetName": "Bella Vista Avenue",
            "municipality": "Los Gatos",
            "countrySecondarySubdivision": "Santa Clara",
            "countrySubdivision": "CA",
            "countrySubdivisionName": "California",
            "postalCode": "95030, 95032",
            "extendedPostalCode": "950306101, 950306104, 950306131, 950325400, 950325415, 950325416, 950325421, 950325477",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "Bella Vista Avenue, Los Gatos, CA",
            "localName": "Los Gatos"
        },
        "position": {
            "lat": 37.22544,
            "lon": -121.97099
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 37.22907,
                "lon": -121.97304
            },
            "btmRightPoint": {
                "lat": 37.22284,
                "lon": -121.97028
            }
        }
    }, {
        "type": "Street",
        "id": "US/STR/p0/632163",
        "score": 8.735420227050781,
        "dist": 4089764.478969137,
        "address": {
            "streetName": "New York Road",
            "municipality": "Port Republic",
            "countrySecondarySubdivision": "Atlantic",
            "countrySubdivision": "NJ",
            "countrySubdivisionName": "New Jersey",
            "postalCode": "08241",
            "extendedPostalCode": "082419723, 082419724, 082419727, 082419730",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "New York Road, Port Republic, NJ 08241",
            "localName": "Port Republic"
        },
        "position": {
            "lat": 39.54058,
            "lon": -74.46479
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 39.54902,
                "lon": -74.47561
            },
            "btmRightPoint": {
                "lat": 39.53104,
                "lon": -74.45229
            }
        }
    }, {
        "type": "Street",
        "id": "US/STR/p0/648519",
        "score": 8.735420227050781,
        "dist": 4089982.9640824813,
        "address": {
            "streetName": "New York Road",
            "municipality": "Absecon",
            "countrySecondarySubdivision": "Atlantic",
            "countryTertiarySubdivision": "Galloway",
            "countrySubdivision": "NJ",
            "countrySubdivisionName": "New Jersey",
            "postalCode": "08205, 08241",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "New York Road, Absecon, NJ",
            "localName": "Absecon"
        },
        "position": {
            "lat": 39.53321,
            "lon": -74.46423
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 39.53348,
                "lon": -74.46441
            },
            "btmRightPoint": {
                "lat": 39.53304,
                "lon": -74.46405
            }
        }
    }, {
        "type": "Street",
        "id": "US/STR/p0/10748985",
        "score": 8.735420227050781,
        "dist": 2396324.9954685825,
        "address": {
            "streetName": "New York Avenue",
            "municipality": "Creston",
            "countrySecondarySubdivision": "Union",
            "countrySubdivision": "IA",
            "countrySubdivisionName": "Iowa",
            "postalCode": "50801",
            "extendedPostalCode": "508013301, 508013302, 508013303, 508013304, 508013308, 508013309, 508013310, 508013311, 508013316, 508013317, 508013320, 508013325",
            "countryCode": "US",
            "country": "United States",
            "countryCodeISO3": "USA",
            "freeformAddress": "New York Avenue, Creston, IA 50801",
            "localName": "Creston"
        },
        "position": {
            "lat": 41.04701,
            "lon": -94.37767
        },
        "viewport": {
            "topLeftPoint": {
                "lat": 41.05591,
                "lon": -94.38977
            },
            "btmRightPoint": {
                "lat": 41.03793,
                "lon": -94.36592
            }
        }
    }]
}
Hi all. I am new to this stuff so please forgive my question if it seems basic. I use a web-to-lead form on multiple pages as a way to gate content (fill out the form... get the download). In SF I have a custom field called Lead Origin which records the title of the web-to-lead form. The trouble I am having is when a user returns and completes a different form in order to access a different download, the field cannot be updated. I asked SF support for insight on how to complete this and they suggested that I would need to use a trigger, but it is not something i am familiar with. Does anyone have any example of this?
Hello,
I have created method in trigger handler class but method is taking more CPU time and sometime give error. Anyone Please suggested better approch of doing this. Thanks in Advance!!
Boolean QueryrunOnce = true;
Public void updatecheckandtoggle(List<AMM_ODR__REL__C> triggerNew)
{
Try{
Set<Id> OppIds = new set<id> ();
List<AMM_Opportunity__c> ListAMMOpptoUpdate;
If (Trigger.isInsert ||Trigger.isUpdate )
{
for (AMM_ODR__REL__C Odr : triggerNew )
{
OppIds.add(Odr.AMM_Opportunity__c);
}

}
if(OppIds.size() > 0 && QueryrunOnce )
{
QueryrunOnce = false;
ListAMMOpptoUpdate = New List<AMM_Opportunity__c> ([Select Id,AMM_OPP_Check__c,(Select TTPI__C from Summury_Flex__Jo__r) from AMM_Opportunity__c where id:=OppIds];
}
If(!ListAMMOpptoUpdate.isEmpty())
{
for (AMM_Opportunity__c Opps: ListAMMOpptoUpdate )
{
If (Opps.Summury_Flex__Jo__r.size()>0)
{
for (AMM_ODR__REL__C Odrr : Opps.Summury_Flex__Jo__r)
{
if(Odrr!null && odrr.TTPI__C!=null && Odrr.TTPI__C.startwith('14') )
{
Opps.AMM_OPP_Check__c = true;
opps.AMM_OPP_toggle__c=true;
} else
{
Opps.AMM_OPP_Check__c = true;
opps.AMM_OPP_toggle__c=true;
}
}
}
} Update ListAMMOpptoUpdate;
}
} Catch (Exception ex) {system.debug('The Exception Occur - ')}

 

Hi,

I'm an admin and I'd like to create something to prevent non-SysAdmin users from deleting opportunity products.  The only option I'm seeing for this is creating a trigger...which I've never done.  I copied and pasted the below from something and am trying to swap things out, but I'm not sure what to plug in.  What should "Account acc" be for opportunity product?  How do I prevent this from being applied to admins?  Do I only need the trigger to get this to work?



trigger <PreventOpportunityProductDeletion> on OpportunityLineItem (<events>) {
     for(Account acc : trigger.old){
         acc.adderror('Account Cannot be deleted');
}
}



Thanks in advance for your help!

In which screen, I will be able to find all the required fields for a given object in salesforce pls ?
  • August 27, 2018
  • Like
  • 0
Hi,
Below is my code for the trigger for  duplicate prevention on the account . It works well, but if I have 50k records this impacts scalability and not feasible.
So please any one can help to code in better way.
thanks in advance.
trigger AccountDuplicate on Account (before insert) {
 List<Account> dup = new List<Account>();
 dup = [Select id, Name from Account];
 for(Account a:Trigger.New){
 for(Account a1:dup){
 if(a.Name==a1.Name){
 a.Name.addError('Name already Exist ');
 }
 }
 }   
 }
Hi,

I have report - PDF page - that run sometimes on large amount of data.
with too much data, it failed when loading the page to the screen, so I try different approach- generating the page in background, and attach it to the chatter.
It does incrase the capacity of the report, but still in some amount of data it fails, and I can see in log Internal Salesforce.com Error.
I'm not hitting any other SF limitation (CPU close to limit, but not beyond).

The PDF (that failed) expected to be ~1.5MB, with ~800-1000 pages.
I able to generate it with ~1MB, ~600 pages.

Anyone have idea possible reason for this error?




global class AddPdfToRecord{
    webservice static void addPDF(){ 
     
       PageReference pdf = Page.TestLiron;
      
       pdf.getParameters().put('parm1','111');
       pdf.getParameters().put('parm2','222');
 
       pdf.setRedirect(true);
      
      //system.debug('URL: ' + pdf.getURL());

       Attachment attach = new Attachment();
       Blob body;
       try
       {
           body = pdf.getContentasPDF();        //here the failure

            // post to chatter
            FeedItem post = new FeedItem();
            post.ParentId = '0F9c00000008efE'; // nickforce chatter group id
            post.Body = 'Report for..';
            post.Type = 'ContentPost';
            post.ContentData = body;
            post.ContentFileName = 'FMR_TEST' + '.pdf';

            insert post;
       }
       catch(Exception e)
       {system.debug('EEEEEEEEEEEEEEEE'  + e) ;}
   }
}