Loading
CRM Analytics
Definizione del comportamento delle azioni con la classe e i metodi del controller Apex

Definizione del comportamento delle azioni con la classe e i metodi del controller Apex

Definire una classe e i metodi del controller Apex che generano un elenco degli account visualizzati nel widget tabella, creano un'opportunità per ogni account e restituiscono lo stato di avanzamento di ogni operazione.

  1. Da Imposta, immettere Classi Apex nella casella Ricerca veloce.
  2. Selezionare Classi Apex.
  3. Fare clic su Nuovo.
    È possibile creare nuove classi dalla pagina Classi Apex.
  4. Aggiungere il seguente codice.
    public class CreateOpportunitiesController {
        public string query{get; set;}
     
    /* To determine the records to perform the bulk action on, extract the SAQL query */
        public PageReference init() {
            query = ApexPages.currentPage().getParameters().get('query');
            return null;
        }
    
    /* Takes the account records from the SAQL query, creates an opportunity for each account, and then returns a map between account ID and new opportunity name. Note: Account.Name and AccountId referenced below refer to the dataset field names. Update them to match your dataset fields. */
        @RemoteAction
        public static Map<String, String> create(List <Map<String, String>> accountRecords) {
            Map<String, String> result = new Map<String, String>();
    
    
            List<Opportunity> opps = new List<Opportunity>();
            for (Map<String, String> accountRecord : accountRecords) {
            
                String name = accountRecord.get('Account.Name') + ' - Sprint Review - 12/2';
                String accountId = accountRecord.get('AccountId');
                result.put(accountId, name);
                Opportunity opp = new Opportunity(
    /* You can set different fields from the Opportunity object than those listed below, like Amount. */
                    Name = name,
                    Type ='New Customer',
                    AccountId = Id.valueOf(accountId),
                    CloseDate=Date.valueOf('2016-12-31'),
                    StageName='Prospecting'); 
                opps.add(opp);
            }
            insert opps;
            return result;
        }
    }
  5. Fare clic su Salva.
 
Caricamento
Salesforce Help | Article