function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ALEX YAN 7ALEX YAN 7 

add new values to picklist when use metadata api

Hello,I want to add new values to picklist ,I import all class  which from https://github.com/financialforcedev/apex-mdapi  into my org.
I write a class named AddSegment.cls and  a test class  ,when I run test class to create Field ,it show error:Attempt to de-reference a null object, can someone tell me what wrong and what should I do.Thank you very much.
User-added image
User-added image

 
Best Answer chosen by ALEX YAN 7
Sukanya BanekarSukanya Banekar
Hi,
I don't know what is your code returning? Need to check your whole code then only I can tell you why is it returning null.

Thanks,
Sukanya Banekar

All Answers

ALEX YAN 7ALEX YAN 7
I think results ==null, but I don't know why.
List<MetadataService.SaveResult> results = service.createMetadata( new MetadataService.Metadata[] { customField });
Sukanya BanekarSukanya Banekar
Hi,
Write below statement before line no.102
if()
If(results <> NULL && !results.isEmpty()){
   handleSaveResults(results[0]);
}
Let me know if this works

Thanks,
Sukanya Banekar
 
ALEX YAN 7ALEX YAN 7
Thank you for your reply. If I add "If(results <> NULL && !results.isEmpty())" ,there is no error.  
But when use metadata api to create customField , results  should return something ? But I get results null. Is there anything wrong.
Sukanya BanekarSukanya Banekar
Hi,
I don't know what is your code returning? Need to check your whole code then only I can tell you why is it returning null.

Thanks,
Sukanya Banekar
This was selected as the best answer