• D-Coder
  • NEWBIE
  • 139 Points
  • Member since 2017

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 47
    Replies
Hello Everyone,

I have created 1 trigger on Account which opens a case as soon as we create the account.
So, as soon as I have written both the codes and now testing with testClass, it is not creating a new Account record in my salesforce org. and hence also not opening any case.

Is there anything I am missing here. Support is really appreciated.

1. Trigger on Account to open a case 
trigger CreateTShirtCaseonAccount on Account (after insert) {
    for(Account ListofAllAccount: Trigger.New)
    {
        Case newTshirtCase = new Case();
        newTshirtCase.Subject = 'Congratulations, your account is opened, with free T-Shirt from us';
        newTshirtCase.Priority = 'High';
        newTshirtCase.AccountId = ListofAllAccount.id;
        insert newTshirtCase;
    }
}


2. Test Class to test the trigger

@isTest
public class TestAccountTrigger {
    static testMethod void accountCreator()
    {
        Account newAccount = new Account();
        newAccount.Name = 'Account Created with TestClass : TestAccountTrigger';
        insert newAccount;
    }
}



Regards,
Sombir Sheoran
Hi,

I am trying to create a new opportunity (Enquiry) when a checkbox (Enquiry_Creator__c) is enabled . anyone please give me a advise why it's not created.  Kindly Check the below code please.

************** Trigger ***********
Trigger VisualInsCreateEnquiry on Visual_Inspection__c (After Insert) {
    
    Set<Id> VisInsId = new Set<Id>();
    List<Opportunity> oppList = New List<Opportunity>();
    
    for(Visual_Inspection__c  vi : Trigger.New){
        If(vi.Enquiry_Creator__c == True){
            VisInsId.add(vi.Id);
            system.debug('++++++Visual Inspection Id : ' + VisInsId);
        }
    }
    
    If(VisInsId.size() > 0){
        System.debug('+++++++Visual Inspection Size is : ' + VisInsId.size() );
        
            oppList = [Select id,name, Customer_Name__c, Type, Sales_Office__c, Sales_Org1__c, Plant_Type__c, Sites__c, CloseDate, StageName
                       from Opportunity 
                       where Id IN :VisInsId AND RecordType.Name IN ('Service Centre')];
        
        for(Visual_Inspection__c vis : Trigger.new){
            If(VisInsId.size() > 0 && vis.Enquiry_Creator__c == True){
                for(Opportunity op : oppList){
            Opportunity oppty = New Opportunity();
            //oppty.RecordTypeId = oppList.Id;
            oppty.Name = 'Test Oppty';
            oppty.StageName =  'Enquiry';
            oppty.Sales_Office__c = 'Chennai';
            oppty.Sales_Org1__c = 'Chennai';
            oppty.CloseDate = System.today();
            oppty.Plant_Type__c = 'New Plant';
            oppty.Sites__c = 'Test Site';
            oppList.add(oppty);
        }
                
                IF(oppList.size() > 0){
            insert oppList;
        }
                
                
            }
        }
        
        
    }
}

 Thanks in advance !!!

Regards,
Soundar.
Hello, 

I want to make dicount filed 0 if it left blank. How is it possible?

trigger QuotelineItemApproval on QuoteLineItem (after insert, after update) {

    List<Quote> parentObjList = new List<Quote>();
    List<ID> listIds = new List<ID>();
    List<Quote> listIds1 = new List<Quote>();
    
    //List <QuotelineItem> m3 = [select ID, Discount_Flag1__c from QuotelineItem where Discount_Flag1__c = : '1'];
    Boolean inRange ;
    
    String status  ='Not Required';
    String QuoteID ;
    Boolean isAwaiting = false;
    
    
    for (QuoteLineItem childObj : Trigger.new) {
        if(QuoteID == null) {
             QuoteID  = childObj.QuoteID;
        }    
    }
    
    Boolean changed = false;
    
    if(QuoteID  != null) {
        for(List<QuoteLineItem> items : [select ID, Discount_Flag1__c,Quantity ,Discount  from QuotelineItem where QuoteId= : QuoteID  ]) {
            for(QuoteLineItem item : items ) {
                inRange = false;
                changed  = true;
                if(item.Quantity >= 0 && item.Quantity <= 9 &&  item.Discount <= 0) {
                       inRange = true;
                } else {
                   if(item.Quantity >= 10 && item.Quantity <= 25 &&  item.Discount <= 5) {
                     inRange = true;
                   } else {
                      if(item.Quantity >= 26 && item.Quantity <= 49 &&  item.Discount <= 7) {
                         inRange = true;
                      } else {
                         if(item.Quantity >= 50  &&  item.Discount <= 10) {
                             inRange = true;
                         }
                      }
                   }
                }
                
                if(!inRange) {
                   isAwaiting  = true;              
                }  
                
                system.debug('***********+Quantity +*************'+item.Quantity);
                system.debug('***********+Discount +*************'+item.Discount);
                 
                system.debug('***********+inRange +*************'+inRange );
        
            } 
        } 
        
        
        system.debug('***********+isAwaiting  +*************'+isAwaiting  );
         
        if(changed ) {
           
           Id retVal = null;
           for(ProcessInstanceWorkitem workItem  : [Select p.Id from ProcessInstanceWorkitem p   where p.ProcessInstance.TargetObjectId =: QuoteID]) {
                retVal  =  workItem.Id;
           } 
           
           if(isAwaiting  ) {  
               status = 'Awaiting Approval'; 
           } else {
               status = 'Not Required';           
           }
           
           List<Quote> quotes = [select Id,Approval_Status__c  from Quote where Id =:QuoteID  ]; 
           
           if(quotes.size() > 0) {
               Quote QuoteDetails = quotes[0];
               if(retVal != null && status == 'Not Required') {
                       Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
                       req.setComments('Automatically approved as Approval is no longer required.'); 
                       req.setAction('Approve');
                       req.setNextApproverIds(new Id[] {UserInfo.getUserId()});  
                       req.setWorkitemId(retVal );    
                       Approval.ProcessResult result =  Approval.process(req);
               } 
                
               
               
           
               //QuoteDetails.IsSynching = false;
               QuoteDetails.Approval_Status__c  = status;
               update QuoteDetails;
           } 
        } 
    }
    
    
    
}

Thanks & Regards,
Utkarsha
Hi All,

I have array of string : one,two,three,four,"five1,five2", six ,seven,"eight1,eight2","nine",,eleven

I need output as :
one
two
three
four
five1,five2
six
seven
eight1,eight2
nine

eleven

Thanks in advance
Hi,
I am using SOQL query to retrive all the class methods,
SOQL query ========= "select id,name,Body from apexclass''

Can someone help me to retrive all the class methods and variables using SOQL
Thanks
 
Hi,

I want to updateto date field based on another object value.If my Case object having a picklist field value ABCD then in policy object i wnat to update two date fields.I will match Policy no from my case object so that it will update that exact policy start date and end date. Please help
Hello Everyone,

I have created 1 trigger on Account which opens a case as soon as we create the account.
So, as soon as I have written both the codes and now testing with testClass, it is not creating a new Account record in my salesforce org. and hence also not opening any case.

Is there anything I am missing here. Support is really appreciated.

1. Trigger on Account to open a case 
trigger CreateTShirtCaseonAccount on Account (after insert) {
    for(Account ListofAllAccount: Trigger.New)
    {
        Case newTshirtCase = new Case();
        newTshirtCase.Subject = 'Congratulations, your account is opened, with free T-Shirt from us';
        newTshirtCase.Priority = 'High';
        newTshirtCase.AccountId = ListofAllAccount.id;
        insert newTshirtCase;
    }
}


2. Test Class to test the trigger

@isTest
public class TestAccountTrigger {
    static testMethod void accountCreator()
    {
        Account newAccount = new Account();
        newAccount.Name = 'Account Created with TestClass : TestAccountTrigger';
        insert newAccount;
    }
}



Regards,
Sombir Sheoran
Hi,

I am trying to create a new opportunity (Enquiry) when a checkbox (Enquiry_Creator__c) is enabled . anyone please give me a advise why it's not created.  Kindly Check the below code please.

************** Trigger ***********
Trigger VisualInsCreateEnquiry on Visual_Inspection__c (After Insert) {
    
    Set<Id> VisInsId = new Set<Id>();
    List<Opportunity> oppList = New List<Opportunity>();
    
    for(Visual_Inspection__c  vi : Trigger.New){
        If(vi.Enquiry_Creator__c == True){
            VisInsId.add(vi.Id);
            system.debug('++++++Visual Inspection Id : ' + VisInsId);
        }
    }
    
    If(VisInsId.size() > 0){
        System.debug('+++++++Visual Inspection Size is : ' + VisInsId.size() );
        
            oppList = [Select id,name, Customer_Name__c, Type, Sales_Office__c, Sales_Org1__c, Plant_Type__c, Sites__c, CloseDate, StageName
                       from Opportunity 
                       where Id IN :VisInsId AND RecordType.Name IN ('Service Centre')];
        
        for(Visual_Inspection__c vis : Trigger.new){
            If(VisInsId.size() > 0 && vis.Enquiry_Creator__c == True){
                for(Opportunity op : oppList){
            Opportunity oppty = New Opportunity();
            //oppty.RecordTypeId = oppList.Id;
            oppty.Name = 'Test Oppty';
            oppty.StageName =  'Enquiry';
            oppty.Sales_Office__c = 'Chennai';
            oppty.Sales_Org1__c = 'Chennai';
            oppty.CloseDate = System.today();
            oppty.Plant_Type__c = 'New Plant';
            oppty.Sites__c = 'Test Site';
            oppList.add(oppty);
        }
                
                IF(oppList.size() > 0){
            insert oppList;
        }
                
                
            }
        }
        
        
    }
}

 Thanks in advance !!!

Regards,
Soundar.
I work on a managed package which has a scheduled Apex job that runs daily. This job includes some code that gets our managed package namespace prefix and prepends it to our custom objects. For some reason when an organization has our managed package installed the scheduled job fails with the following error.

Failed to process batch for class 'kimbia_sync.DeleteKimbiaLogs' for job id '7071a00002zBrzq'
caused by: System.QueryException: sObject type 'ApexClass' is not supported.

I can run the same code in that org through the developer console and it works just fine. 

I found this issue on StackExchange (https://salesforce.stackexchange.com/questions/27113/invalid-type-sobject-type-apexclass-is-not-supported) but it's a few years old and the API Access feature is now deprecated. I opened a Salesforce support ticket asking if they could help out and they checked one of the affected orgs and it had the correct setting so I'm at a loss. 
Hi,
Belew is the VF page and controller using the metadata methods.And there are two errors:
-->Method does not exist or incorrect signature: void createService() from the type MetadataController
--->Variable does not exist: customField

<apex:page controller="MetadataController">
    <apex:form id="form">
        <apex:sectionHeader title="Metadata Demo">
            <apex:pageMessages/>
                <apex:actionPoller action="{!checkStatus}" interval="5" rerender="form" rendered="{!NOT(ISNULL(Result))}">
                    <apex:outputPanel rendered="{!ISNULL(Result)}">
                        <apex:commandButton value="Create Field" action="{!createField}"/>
                        <!--apex:commandButton value="Delete Field" action="{!deleteField}"/-->
                    </apex:outputPanel>
                </apex:actionPoller>
        </apex:sectionHeader>
    </apex:form>
</apex:page>
--------------------------------------------------------------
public with sharing class MetadataController {
    
    public MetadataService.AsyncResult result {get;set;}
    public Book__c b{get;set;}
    
    public MetadataController(){
    
        result = new MetadataService.AsyncResult();        
    }
    
    
    public PageReference createField()
    {
        // .. as per above ...
        result = createService().create(new List<MetadataService.Metadata>{customField})[0];
        displayStatus();
        return null;
    }
    
    public PageReference checkStatus()
    {
        // Check status of the request
        //result = createService().checkStatus(new List<String> { result.Id })[0];
        displayStatus();
        return null;
    }
    
    private void displayStatus()
    {
        // Inspect the AsyncResult and display the result
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,
                                                   result.done ? 'Request completed' : 'Request in progress...'));
        if(result.state == 'Error')
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, result.message));
        if(result.done)
            result = null;
    }
}
Can someone help me

Thanks in Advance
Is it possible to create custom object data automatically  using liveagent prechat API

I have requirment to  create custom object data and Case automatically when a prechat form is completed using liveagent prechat API
What is Synchronous and Asynchronous Apex ?
Hello all,

i have a problem i'd like to fix, perhaps somebody can help me.

Our company has Live Agent deployed. Works just fine, except for one thing: A customer on our external website can currently open a chat multiple times, creating multiple sessions. This way our service professionals are blocked for other customers. Is there any known way to prevent this from happening?
Hello,

I have picklist A, Piclkist B with below values
picklist_A__C
  1
  2

Picklis_ B__C
 A
 B

When the value is 1 then A is selected automatically and when the value is 2 then the value B is selected by default

thanks for suggestion !
  • July 11, 2017
  • Like
  • 0
Public Class CommonHelper1 {
     public static Void getpostionbylocation (string CityName)
     {
          list<Position__C> lstpos =[Select id ,name from Position__C where location__C =:CityName];
          system.debug('Postion Record collection size' +lstpos.size());
         
        if (!lstpos.isempty())
         {
             
             for(Position__C pos :lstpos)
             {
                 
                 system.debug('Position Record is '+pos);
                 
             }
             
         }
             
             
             
    }
   }



calling method anonymous window :CommonHelper1.getpostionbylocation('Delhi');

When someone takes the time/effort to repspond to your question, you should take the time/effort to either mark the question as "Solved", or post a Follow-Up with addtional information.  

 

That way people with a similar question can find the Solution without having to re-post the same question again and again. And the people who reply to your post know that the issue has been resolved and they can stop working on it.